提交 0873a8b0 编写于 作者: B Benjamin Pasero

web - switch to addEventListener for beforeunload

上级 cb932e42
...@@ -22,12 +22,10 @@ export class BrowserLifecycleService extends AbstractLifecycleService { ...@@ -22,12 +22,10 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
} }
private registerListeners(): void { private registerListeners(): void {
// Note: we cannot change this to window.addEventListener('beforeUnload') window.addEventListener('beforeunload', e => this.onBeforeUnload(e));
// because it seems that mechanism does not allow for preventing the unload
window.onbeforeunload = () => this.onBeforeUnload();
} }
private onBeforeUnload(): string | null { private onBeforeUnload(event: BeforeUnloadEvent): void {
const logService = this.logService; const logService = this.logService;
logService.info('[lifecycle] onBeforeUnload triggered'); logService.info('[lifecycle] onBeforeUnload triggered');
...@@ -48,7 +46,10 @@ export class BrowserLifecycleService extends AbstractLifecycleService { ...@@ -48,7 +46,10 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
// Veto: signal back to browser by returning a non-falsify return value // Veto: signal back to browser by returning a non-falsify return value
if (veto) { if (veto) {
return localize('lifecycleVeto', "Changes that you made may not be saved. Please check press 'Cancel' and try again."); event.preventDefault();
event.returnValue = localize('lifecycleVeto', "Changes that you made may not be saved. Please check press 'Cancel' and try again.");
return;
} }
// No Veto: continue with Will Shutdown // No Veto: continue with Will Shutdown
...@@ -61,8 +62,6 @@ export class BrowserLifecycleService extends AbstractLifecycleService { ...@@ -61,8 +62,6 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
// Finally end with Shutdown event // Finally end with Shutdown event
this._onShutdown.fire(); this._onShutdown.fire();
return null;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册