8000 Save dialog for closing temporary sketch and unsaved files by msujew · Pull Request #893 · arduino/arduino-ide · GitHub
[go: up one dir, main page]

Skip to content

Save dialog for closing temporary sketch and unsaved files #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed FS path vs encoded URL comparision when handling stop request.
Ref: eclipse-theia/theia#11226
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed May 31, 2022
commit c1125f33159731bd7946eceb08805ba62b1d0ca5
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
IDEUpdaterPath,
} from '../common/protocol/ide-updater';
import { IDEUpdaterImpl } from './ide-updater/ide-updater-impl';
import { TheiaElectronWindow } from './theia/theia-electron-window';
import { TheiaElectronWindow as DefaultTheiaElectronWindow } from '@theia/core/lib/electron-main/theia-electron-window';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ElectronMainApplication).toSelf().inSingletonScope();
Expand Down Expand Up @@ -56,4 +58,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
)
)
.inSingletonScope();

bind(TheiaElectronWindow).toSelf();
rebind(DefaultTheiaElectronWindow).toService(TheiaElectronWindow);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { injectable } from '@theia/core/shared/inversify';
import { isWindows } from '@theia/core/lib/common/os';
import { StopReason } from '@theia/core/lib/electron-common/messaging/electron-messages';
import { TheiaElectronWindow as DefaultTheiaElectronWindow } from '@theia/core/lib/electron-main/theia-electron-window';
import { FileUri } from '@theia/core/lib/node';

@injectable()
export class TheiaElectronWindow extends DefaultTheiaElectronWindow {
protected async handleStopRequest(
onSafeCallback: () => unknown,
reason: StopReason
): Promise<boolean> {
// Only confirm close to windows that have loaded our front end.
let currentUrl = this.window.webContents.getURL(); // this comes from electron, expected to be an URL encoded string. e.g: space will be `%20`
let frontendUri = FileUri.create(
this.globals.THEIA_FRONTEND_HTML_PATH
).toString(false); // Map the FS path to an URI, ensure the encoding is not skipped, so that a space will be `%20`.
// Since our resolved frontend HTML path might contain backward slashes on Windows, we normalize everything first.
if (isWindows) {
currentUrl = currentUrl.replace(/\\/g, '/');
frontendUri = frontendUri.replace(/\\/g, '/');
}
const safeToClose =
!currentUrl.includes(frontendUri) || (await this.checkSafeToStop(reason));
if (safeToClose) {
try {
await onSafeCallback();
return true;
} catch (e) {
console.warn(`Request ${StopReason[reason]} failed.`, e);
}
}
return false;
}
}
0