Skip to content

Commit 785d261

Browse files
author
Akos Kitta
committed
Aligned the stop handler code to Theia.
Signed-off-by: Akos Kitta <[email protected]>
1 parent e8e0644 commit 785d261

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { injectable } from '@theia/core/shared/inversify';
2-
import { isWindows } from '@theia/core/lib/common/os';
32
import { StopReason } from '@theia/core/lib/electron-common/messaging/electron-messages';
43
import { TheiaElectronWindow as DefaultTheiaElectronWindow } from '@theia/core/lib/electron-main/theia-electron-window';
54
import { FileUri } from '@theia/core/lib/node';
5+
import URI from '@theia/core/lib/common/uri';
66

77
@injectable()
88
export class TheiaElectronWindow extends DefaultTheiaElectronWindow {
99
protected async handleStopRequest(
1010
onSafeCallback: () => unknown,
1111
reason: StopReason
1212
): Promise<boolean> {
13-
// Only confirm close to windows that have loaded our front end.
14-
let currentUrl = this.window.webContents.getURL(); // this comes from electron, expected to be an URL encoded string. e.g: space will be `%20`
15-
let frontendUri = FileUri.create(
13+
// Only confirm close to windows that have loaded our frontend.
14+
// Both the windows's URL and the FS path of the `index.html` should be converted to the "same" format to be able to compare them. (#11226)
15+
// Notes:
16+
// - Windows: file:///C:/path/to/somewhere vs file:///c%3A/path/to/somewhere
17+
// - macOS: file:///Applications/App%20Name.app/Contents vs /Applications/App Name.app/Contents
18+
// This URL string comes from electron, we can expect that this is properly encoded URL. For example, a space is `%20`
19+
const currentUrl = new URI(this.window.webContents.getURL()).toString();
20+
// THEIA_FRONTEND_HTML_PATH is an FS path, we have to covert to an encoded URI string.
21+
const frontendUri = FileUri.create(
1622
this.globals.THEIA_FRONTEND_HTML_PATH
17-
).toString(false); // Map the FS path to an URI, ensure the encoding is not skipped, so that a space will be `%20`.
18-
// Since our resolved frontend HTML path might contain backward slashes on Windows, we normalize everything first.
19-
if (isWindows) {
20-
currentUrl = currentUrl.replace(/\\/g, '/');
21-
frontendUri = frontendUri.replace(/\\/g, '/');
22-
}
23+
).toString();
2324
const safeToClose =
2425
!currentUrl.includes(frontendUri) || (await this.checkSafeToStop(reason));
2526
if (safeToClose) {

0 commit comments

Comments
 (0)