-
-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathelectron-window-service.ts
41 lines (34 loc) · 1.79 KB
/
electron-window-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { inject, injectable, postConstruct } from 'inversify';
import { remote } from 'electron';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
import { ConnectionStatus, ConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';
import { ElectronWindowService as TheiaElectronWindowService } from '@theia/core/lib/electron-browser/window/electron-window-service';
import { SplashService } from '../electron-common/splash-service';
@injectable()
export class ElectronWindowService extends TheiaElectronWindowService {
@inject(ConnectionStatusService)
protected readonly connectionStatusService: ConnectionStatusService;
@inject(SplashService)
protected readonly splashService: SplashService;
@inject(FrontendApplicationStateService)
protected readonly appStateService: FrontendApplicationStateService;
@postConstruct()
protected init(): void {
this.appStateService.reachedAnyState('initialized_layout').then(() => this.splashService.requestClose());
}
protected shouldUnload(): boolean {
const offline = this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE;
const detail = offline
? 'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
: 'Any unsaved changes will not be saved.'
const electronWindow = remote.getCurrentWindow();
const response = remote.dialog.showMessageBoxSync(electronWindow, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Are you sure you want to close the sketch?',
detail
});
return response === 0; // 'Yes', close the window.
}
}