mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-15 05:09:29 +00:00
Can check if the current window is the first one.
Closes #1070 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
import { ContainerModule } from '@theia/core/shared/inversify';
|
||||
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
||||
import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
|
||||
import { ElectronMenuContribution as TheiaElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
|
||||
import { ElectronIpcConnectionProvider } from '@theia/core/lib/electron-browser/messaging/electron-ipc-connection-provider';
|
||||
import {
|
||||
SplashService,
|
||||
splashServicePath,
|
||||
} from '../../../electron-common/splash-service';
|
||||
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||
import { ElectronWindowService } from '../../electron-window-service';
|
||||
import { ElectronMainMenuFactory } from './electron-main-menu-factory';
|
||||
import { ElectronMenuContribution } from './electron-menu-contribution';
|
||||
import { nls } from '@theia/core/lib/common/nls';
|
||||
@@ -16,23 +9,25 @@ import { nls } from '@theia/core/lib/common/nls';
|
||||
import * as remote from '@theia/core/electron-shared/@electron/remote';
|
||||
import * as dialogs from '@theia/core/lib/browser/dialogs';
|
||||
|
||||
|
||||
Object.assign(dialogs, {
|
||||
confirmExit: async () => {
|
||||
const messageBoxResult = await remote.dialog.showMessageBox(
|
||||
remote.getCurrentWindow(),
|
||||
{
|
||||
message: nls.localize('theia/core/quitMessage', 'Any unsaved changes will not be saved.'),
|
||||
title: nls.localize('theia/core/quitTitle', 'Are you sure you want to quit?'),
|
||||
message: nls.localize(
|
||||
'theia/core/quitMessage',
|
||||
'Any unsaved changes will not be saved.'
|
||||
),
|
||||
title: nls.localize(
|
||||
'theia/core/quitTitle',
|
||||
'Are you sure you want to quit?'
|
||||
),
|
||||
type: 'question',
|
||||
buttons: [
|
||||
dialogs.Dialog.CANCEL,
|
||||
dialogs.Dialog.YES,
|
||||
],
|
||||
buttons: [dialogs.Dialog.CANCEL, dialogs.Dialog.YES],
|
||||
}
|
||||
)
|
||||
);
|
||||
return messageBoxResult.response === 1;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
@@ -41,14 +36,4 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
rebind(TheiaElectronMenuContribution).toService(ElectronMenuContribution);
|
||||
bind(ElectronMainMenuFactory).toSelf().inSingletonScope();
|
||||
rebind(TheiaElectronMainMenuFactory).toService(ElectronMainMenuFactory);
|
||||
bind(ElectronWindowService).toSelf().inSingletonScope();
|
||||
rebind(WindowService).toService(ElectronWindowService);
|
||||
bind(SplashService)
|
||||
.toDynamicValue((context) =>
|
||||
ElectronIpcConnectionProvider.createProxy(
|
||||
context.container,
|
||||
splashServicePath
|
||||
)
|
||||
)
|
||||
.inSingletonScope();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
||||
import { ElectronIpcConnectionProvider } from '@theia/core/lib/electron-browser/messaging/electron-ipc-connection-provider';
|
||||
import { ContainerModule } from '@theia/core/shared/inversify';
|
||||
import { WindowServiceExt } from '../../../browser/theia/core/window-service-ext';
|
||||
import {
|
||||
ElectronMainWindowServiceExt,
|
||||
electronMainWindowServiceExtPath,
|
||||
} from '../../../electron-common/electron-main-window-service-ext';
|
||||
import {
|
||||
SplashService,
|
||||
splashServicePath,
|
||||
} from '../../../electron-common/splash-service';
|
||||
import { ElectronWindowService } from './electron-window-service';
|
||||
|
||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
bind(ElectronWindowService).toSelf().inSingletonScope();
|
||||
rebind(WindowService).toService(ElectronWindowService);
|
||||
bind(WindowServiceExt).toService(ElectronWindowService);
|
||||
bind(ElectronMainWindowServiceExt)
|
||||
.toDynamicValue(({ container }) =>
|
||||
ElectronIpcConnectionProvider.createProxy(
|
||||
container,
|
||||
electronMainWindowServiceExtPath
|
||||
)
|
||||
)
|
||||
.inSingletonScope();
|
||||
bind(SplashService)
|
||||
.toDynamicValue(({ container }) =>
|
||||
ElectronIpcConnectionProvider.createProxy(container, splashServicePath)
|
||||
)
|
||||
.inSingletonScope();
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
inject,
|
||||
injectable,
|
||||
postConstruct,
|
||||
} from '@theia/core/shared/inversify';
|
||||
import * as remote from '@theia/core/electron-shared/@electron/remote';
|
||||
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';
|
||||
import { nls } from '@theia/core/lib/common';
|
||||
import { WindowServiceExt } from '../../../browser/theia/core/window-service-ext';
|
||||
import { ElectronMainWindowServiceExt } from '../../../electron-common/electron-main-window-service-ext';
|
||||
|
||||
@injectable()
|
||||
export class ElectronWindowService
|
||||
extends TheiaElectronWindowService
|
||||
implements WindowServiceExt
|
||||
{
|
||||
@inject(ConnectionStatusService)
|
||||
private readonly connectionStatusService: ConnectionStatusService;
|
||||
|
||||
@inject(SplashService)
|
||||
private readonly splashService: SplashService;
|
||||
|
||||
@inject(FrontendApplicationStateService)
|
||||
private readonly appStateService: FrontendApplicationStateService;
|
||||
|
||||
@inject(ElectronMainWindowServiceExt)
|
||||
private readonly mainWindowServiceExt: ElectronMainWindowServiceExt;
|
||||
|
||||
@postConstruct()
|
||||
protected override init(): void {
|
||||
this.appStateService
|
||||
.reachedAnyState('initialized_layout')
|
||||
.then(() => this.splashService.requestClose());
|
||||
}
|
||||
|
||||
protected shouldUnload(): boolean {
|
||||
const offline =
|
||||
this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE;
|
||||
const detail = offline
|
||||
? nls.localize(
|
||||
'arduino/electron/couldNotSave',
|
||||
'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
|
||||
)
|
||||
: nls.localize(
|
||||
'arduino/electron/unsavedChanges',
|
||||
'Any unsaved changes will not be saved.'
|
||||
);
|
||||
const electronWindow = remote.getCurrentWindow();
|
||||
const response = remote.dialog.showMessageBoxSync(electronWindow, {
|
||||
type: 'question',
|
||||
buttons: [
|
||||
nls.localize('vscode/extensionsUtils/yes', 'Yes'),
|
||||
nls.localize('vscode/extensionsUtils/no', 'No'),
|
||||
],
|
||||
title: nls.localize('vscode/Default/ConfirmTitle', 'Confirm'),
|
||||
message: nls.localize(
|
||||
'arduino/sketch/close',
|
||||
'Are you sure you want to close the sketch?'
|
||||
),
|
||||
detail,
|
||||
});
|
||||
return response === 0; // 'Yes', close the window.
|
||||
}
|
||||
|
||||
private _firstWindow: boolean | undefined;
|
||||
async isFirstWindow(): Promise<boolean> {
|
||||
if (this._firstWindow === undefined) {
|
||||
const windowId = remote.getCurrentWindow().id; // This is expensive and synchronous so we check it once per FE.
|
||||
this._firstWindow = await this.mainWindowServiceExt.isFirstWindow(
|
||||
windowId
|
||||
);
|
||||
}
|
||||
return this._firstWindow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user