mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 20:06:32 +00:00
ATL-879: Avoid reopening the same sketch.
Instead of reopening it, focus the existing window. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
96f0722d56
commit
23877f162c
@ -1,15 +1,20 @@
|
||||
import { ContainerModule } from 'inversify';
|
||||
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
|
||||
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
|
||||
import { ElectronMainWindowService } from '@theia/core/lib/electron-common/electron-main-window-service';
|
||||
import { ElectronMainApplication as TheiaElectronMainApplication } from '@theia/core/lib/electron-main/electron-main-application';
|
||||
import { SplashService, splashServicePath } from '../electron-common/splash-service';
|
||||
import { SplashServiceImpl } from './splash/splash-service-impl';
|
||||
import { ElectronMainApplication } from './theia/electron-main-application';
|
||||
import { ElectronMainWindowServiceImpl } from './theia/electron-main-window-service';
|
||||
|
||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
bind(ElectronMainApplication).toSelf().inSingletonScope();
|
||||
rebind(TheiaElectronMainApplication).toService(ElectronMainApplication);
|
||||
|
||||
bind(ElectronMainWindowServiceImpl).toSelf().inSingletonScope();
|
||||
rebind(ElectronMainWindowService).toService(ElectronMainWindowServiceImpl);
|
||||
|
||||
bind(SplashServiceImpl).toSelf().inSingletonScope();
|
||||
bind(SplashService).toService(SplashServiceImpl);
|
||||
bind(ElectronConnectionHandler).toDynamicValue(context =>
|
||||
|
@ -13,7 +13,7 @@ import { SplashServiceImpl } from '../splash/splash-service-impl';
|
||||
@injectable()
|
||||
export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
|
||||
protected windows: BrowserWindow[] = [];
|
||||
protected _windows: BrowserWindow[] = [];
|
||||
|
||||
@inject(SplashServiceImpl)
|
||||
protected readonly splashService: SplashServiceImpl;
|
||||
@ -34,7 +34,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
async createWindow(asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultBrowserWindowOptions()): Promise<BrowserWindow> {
|
||||
const options = await asyncOptions;
|
||||
let electronWindow: BrowserWindow | undefined;
|
||||
if (this.windows.length) {
|
||||
if (this._windows.length) {
|
||||
electronWindow = new BrowserWindow(options);
|
||||
} else {
|
||||
const { bounds } = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
|
||||
@ -63,14 +63,14 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
splashScreenOpts
|
||||
}, this.splashService.onCloseRequested);
|
||||
}
|
||||
this.windows.push(electronWindow);
|
||||
this._windows.push(electronWindow);
|
||||
electronWindow.on('closed', () => {
|
||||
if (electronWindow) {
|
||||
const index = this.windows.indexOf(electronWindow);
|
||||
const index = this._windows.indexOf(electronWindow);
|
||||
if (index === -1) {
|
||||
console.warn(`Could not dispose browser window: '${electronWindow.title}'.`);
|
||||
} else {
|
||||
this.windows.splice(index, 1);
|
||||
this._windows.splice(index, 1);
|
||||
electronWindow = undefined;
|
||||
}
|
||||
}
|
||||
@ -148,4 +148,8 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
}
|
||||
}
|
||||
|
||||
get windows(): BrowserWindow[] {
|
||||
return this._windows.slice();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { NewWindowOptions } from '@theia/core/lib/browser/window/window-service';
|
||||
import { ElectronMainWindowServiceImpl as TheiaElectronMainWindowService } from '@theia/core/lib/electron-main/electron-main-window-service-impl';
|
||||
import { ElectronMainApplication } from './electron-main-application';
|
||||
|
||||
@injectable()
|
||||
export class ElectronMainWindowServiceImpl extends TheiaElectronMainWindowService {
|
||||
|
||||
@inject(ElectronMainApplication)
|
||||
protected readonly app: ElectronMainApplication;
|
||||
|
||||
openNewWindow(url: string, { external }: NewWindowOptions): undefined {
|
||||
if (!external) {
|
||||
const existing = this.app.windows.find(window => window.webContents.getURL() === url);
|
||||
if (existing) {
|
||||
existing.focus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
return super.openNewWindow(url, { external });
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user