Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b7de377

Browse files
Got rid of _windows field, rely on superclass.
Signed-off-by: Akos Kitta <kittaakos@gmail.com>
1 parent 3ece882 commit b7de377

File tree

1 file changed

+78
-92
lines changed

1 file changed

+78
-92
lines changed

‎arduino-ide-extension/src/electron-main/theia/electron-main-application.ts‎

Lines changed: 78 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from '@theia/core/lib/electron-main/electron-main-application';
1515
import { SplashServiceImpl } from '../splash/splash-service-impl';
1616
import { URI } from '@theia/core/shared/vscode-uri';
17-
import * as electronRemoteMain from '@theia/core/electron-shared/@electron/remote/main';
1817
import { Deferred } from '@theia/core/lib/common/promise-util';
1918
import * as os from '@theia/core/lib/common/os';
2019
import { Restart } from '@theia/core/lib/electron-common/messaging/electron-messages';
@@ -37,7 +36,6 @@ const WORKSPACES = 'workspaces';
3736

3837
@injectable()
3938
export class ElectronMainApplication extends TheiaElectronMainApplication {
40-
protected _windows: BrowserWindow[] = [];
4139
protected startup = false;
4240
protected openFilePromise = new Deferred();
4341

@@ -179,99 +177,87 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
179177
async createWindow(
180178
asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultTheiaWindowOptions()
181179
): Promise<BrowserWindow> {
182-
let options = await asyncOptions;
183-
options = this.avoidOverlap(options);
184-
let electronWindow: BrowserWindow | undefined;
185-
if (this._windows.length) {
186-
electronWindow = await super.createWindow(options);
187-
} else {
188-
const { bounds } = screen.getDisplayNearestPoint(
189-
screen.getCursorScreenPoint()
190-
);
191-
const splashHeight = 450;
192-
const splashWidth = 600;
193-
const splashY = Math.floor(bounds.y + (bounds.height - splashHeight) / 2);
194-
const splashX = Math.floor(bounds.x + (bounds.width - splashWidth) / 2);
195-
const splashScreenOpts: BrowserWindowConstructorOptions = {
196-
height: splashHeight,
197-
width: splashWidth,
198-
x: splashX,
199-
y: splashY,
200-
transparent: true,
201-
alwaysOnTop: true,
202-
focusable: false,
203-
minimizable: false,
204-
maximizable: false,
205-
hasShadow: false,
206-
resizable: false,
207-
};
208-
electronWindow = initSplashScreen(
209-
{
210-
windowOpts: options,
211-
templateUrl: join(
212-
__dirname,
213-
'..',
214-
'..',
215-
'..',
216-
'src',
217-
'electron-main',
218-
'splash',
219-
'static',
220-
'splash.html'
221-
),
222-
delay: 0,
223-
minVisible: 2000,
224-
splashScreenOpts,
225-
},
226-
this.splashService.onCloseRequested
180+
const createRegularWindow = !this.windows.size;
181+
const electronWindow = await (createRegularWindow
182+
? super.createWindow(asyncOptions)
183+
: this.createSplashScreenWindow(asyncOptions));
184+
if (createRegularWindow) {
185+
electronWindow.webContents.on(
186+
'new-window',
187+
(event, url, frameName, disposition, options) => {
188+
if (frameName === 'serialPlotter') {
189+
event.preventDefault();
190+
Object.assign(options, {
191+
width: 800,
192+
minWidth: 620,
193+
height: 500,
194+
minHeight: 320,
195+
x: 100,
196+
y: 100,
197+
webPreferences: {
198+
devTools: true,
199+
nativeWindowOpen: true,
200+
openerId: electronWindow?.webContents.id,
201+
},
202+
});
203+
event.newGuest = new BrowserWindow(options);
204+
event.newGuest.setMenu(null);
205+
event.newGuest?.on('closed', (e: any) => {
206+
electronWindow?.webContents.send('CLOSE_CHILD_WINDOW');
207+
});
208+
event.newGuest?.loadURL(url);
209+
}
210+
}
227211
);
212+
this.attachClosedWorkspace(electronWindow);
228213
}
214+
return electronWindow;
215+
}
229216

230-
electronWindow.webContents.on(
231-
'new-window',
232-
(event, url, frameName, disposition, options) => {
233-
if (frameName === 'serialPlotter') {
234-
event.preventDefault();
235-
Object.assign(options, {
236-
width: 800,
237-
minWidth: 620,
238-
height: 500,
239-
minHeight: 320,
240-
x: 100,
241-
y: 100,
242-
webPreferences: {
243-
devTools: true,
244-
nativeWindowOpen: true,
245-
openerId: electronWindow?.webContents.id,
246-
},
247-
});
248-
event.newGuest = new BrowserWindow(options);
249-
event.newGuest.setMenu(null);
250-
event.newGuest?.on('closed', (e: any) => {
251-
electronWindow?.webContents.send('CLOSE_CHILD_WINDOW');
252-
});
253-
event.newGuest?.loadURL(url);
254-
}
255-
}
217+
private async createSplashScreenWindow(
218+
asyncOptions: MaybePromise<TheiaBrowserWindowOptions>
219+
): Promise<BrowserWindow> {
220+
const options = await asyncOptions;
221+
const { bounds } = screen.getDisplayNearestPoint(
222+
screen.getCursorScreenPoint()
223+
);
224+
const splashHeight = 450;
225+
const splashWidth = 600;
226+
const splashY = Math.floor(bounds.y + (bounds.height - splashHeight) / 2);
227+
const splashX = Math.floor(bounds.x + (bounds.width - splashWidth) / 2);
228+
const splashScreenOpts: BrowserWindowConstructorOptions = {
229+
height: splashHeight,
230+
width: splashWidth,
231+
x: splashX,
232+
y: splashY,
233+
transparent: true,
234+
alwaysOnTop: true,
235+
focusable: false,
236+
minimizable: false,
237+
maximizable: false,
238+
hasShadow: false,
239+
resizable: false,
240+
};
241+
return initSplashScreen(
242+
{
243+
windowOpts: options,
244+
templateUrl: join(
245+
__dirname,
246+
'..',
247+
'..',
248+
'..',
249+
'src',
250+
'electron-main',
251+
'splash',
252+
'static',
253+
'splash.html'
254+
),
255+
delay: 0,
256+
minVisible: 2000,
257+
splashScreenOpts,
258+
},
259+
this.splashService.onCloseRequested
256260
);
257-
258-
this._windows.push(electronWindow);
259-
electronWindow.on('closed', () => {
260-
if (electronWindow) {
261-
const index = this._windows.indexOf(electronWindow);
262-
if (index === -1) {
263-
console.warn(
264-
`Could not dispose browser window: '${electronWindow.title}'.`
265-
);
266-
} else {
267-
this._windows.splice(index, 1);
268-
electronWindow = undefined;
269-
}
270-
}
271-
});
272-
this.attachClosedWorkspace(electronWindow);
273-
electronRemoteMain.enable(electronWindow.webContents);
274-
return electronWindow;
275261
}
276262

277263
protected async startBackend(): Promise<number> {
@@ -376,6 +362,6 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
376362
}
377363

378364
get browserWindows(): BrowserWindow[] {
379-
return this._windows;
365+
return Array.from(this.windows.values()).map(({ window })=>window);
380366
}
381367
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /