Skip to content

Commit 9ac4053

Browse files
author
Akos Kitta
committed
Fixed reload issue due to missing listeners.
The listeners were not attached to the first window. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 25e7c60 commit 9ac4053

File tree

2 files changed

+10
-47
lines changed

2 files changed

+10
-47
lines changed

arduino-ide-extension/src/electron-main/splash/splash-screen.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ let splashScreen: Electron.BrowserWindow | null;
111111
* @param config - Configures splashscreen
112112
* @returns {BrowserWindow} the main browser window ready for loading
113113
*/
114-
export const initSplashScreen = (
114+
export const initSplashScreen = async (
115115
config: Config,
116+
windowFactory: (
117+
options: Electron.BrowserViewConstructorOptions
118+
) => Promise<BrowserWindow>,
116119
onCloseRequested?: Event<void>
117-
): BrowserWindow => {
120+
): Promise<BrowserWindow> => {
118121
const xConfig: Required<Config> = {
119122
windowOpts: config.windowOpts,
120123
templateUrl: config.templateUrl,
@@ -126,7 +129,7 @@ export const initSplashScreen = (
126129
xConfig.splashScreenOpts.center = true;
127130
xConfig.splashScreenOpts.frame = false;
128131
xConfig.windowOpts.show = false;
129-
const window = new BrowserWindow(xConfig.windowOpts);
132+
const window = await windowFactory(xConfig.windowOpts);
130133
splashScreen = new BrowserWindow(xConfig.splashScreenOpts);
131134
splashScreen.loadURL(`file://${xConfig.templateUrl}`);
132135
xConfig.closeWindow &&
@@ -153,26 +156,3 @@ export const initSplashScreen = (
153156
window.on('closed', () => closeSplashScreen(window, 0)); // XXX: close splash when main window is closed
154157
return window;
155158
};
156-
/** Return object for `initDynamicSplashScreen()`. */
157-
export interface DynamicSplashScreen {
158-
/** The main browser window ready for loading */
159-
main: BrowserWindow;
160-
/** The splashscreen browser window so you can communicate with splashscreen in more complex use cases. */
161-
splashScreen: Electron.BrowserWindow;
162-
}
163-
/**
164-
* Initializes a splashscreen that will show/hide smartly (and handle show/hiding of main window).
165-
* Use this function if you need to send/receive info to the splashscreen (e.g., you want to send
166-
* IPC messages to the splashscreen to inform the user of the app's loading state).
167-
* @param config - Configures splashscreen
168-
* @returns {DynamicSplashScreen} the main browser window and the created splashscreen
169-
*/
170-
export const initDynamicSplashScreen = (
171-
config: Config
172-
): DynamicSplashScreen => {
173-
return {
174-
main: initSplashScreen(config),
175-
// initSplashScreen initializes splashscreen so this is a safe cast.
176-
splashScreen: splashScreen as Electron.BrowserWindow,
177-
};
178-
};

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

Lines changed: 4 additions & 21 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

@@ -182,7 +180,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
182180
let options = await asyncOptions;
183181
options = this.avoidOverlap(options);
184182
let electronWindow: BrowserWindow | undefined;
185-
if (this._windows.length) {
183+
if (this.windows.size) {
186184
electronWindow = await super.createWindow(options);
187185
} else {
188186
const { bounds } = screen.getDisplayNearestPoint(
@@ -205,7 +203,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
205203
hasShadow: false,
206204
resizable: false,
207205
};
208-
electronWindow = initSplashScreen(
206+
electronWindow = await initSplashScreen(
209207
{
210208
windowOpts: options,
211209
templateUrl: join(
@@ -223,6 +221,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
223221
minVisible: 2000,
224222
splashScreenOpts,
225223
},
224+
(windowOptions) => super.createWindow(windowOptions),
226225
this.splashService.onCloseRequested
227226
);
228227
}
@@ -254,23 +253,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
254253
}
255254
}
256255
);
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-
});
272256
this.attachClosedWorkspace(electronWindow);
273-
electronRemoteMain.enable(electronWindow.webContents);
274257
return electronWindow;
275258
}
276259

@@ -376,6 +359,6 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
376359
}
377360

378361
get browserWindows(): BrowserWindow[] {
379-
return this._windows;
362+
return Array.from(this.windows.values()).map(({ window }) => window);
380363
}
381364
}

0 commit comments

Comments
 (0)