Skip to content

Commit

Permalink
Allow users to close windows without confirming, delete last window (#…
Browse files Browse the repository at this point in the history
…1598)

Adds `window:savelastwindow` and `window:confirmclose` settings, which
can be used to alter the default window close behavior. Both of these
default to `true` to maintain the existing default behavior.

If `window:savelastwindow` is unset, the same logic will be used as if
the user had more than one window remaining (see below).

If `window:confirmonclose` is unset, the user will no longer be prompted
to confirm if they are closing a window whose workspace has unsaved
changes (the workspace is not named and it has more than one tab).
  • Loading branch information
esimkowitz authored Dec 20, 2024
1 parent 4280a09 commit 62dcf13
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
7 changes: 6 additions & 1 deletion docs/docs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ wsh editconfig
| window:showmenubar | bool | set to use the OS-native menu bar (Windows and Linux only, requires app restart) |
| window:nativetitlebar | bool | set to use the OS-native title bar, rather than the overlay (Windows and Linux only, requires app restart) |
| window:disablehardwareacceleration | bool | set to disable Chromium hardware acceleration to resolve graphical bugs (requires app restart) |
| window:savelastwindow | bool | when `true`, the last window that is closed is preserved and is reopened the next time the app is launched (defaults to `true`) |
| window:confirmonclose | bool | when `true`, a prompt will ask a user to confirm that they want to close a window if it has an unsaved workspace with more than one tab (defaults to `true`) |
| telemetry:enabled | bool | set to enable/disable telemetry |

For reference this is the current default configuration (v0.9.3):
For reference, this is the current default configuration (v0.10.4):

```json
{
Expand All @@ -90,6 +92,7 @@ For reference this is the current default configuration (v0.9.3):
"autoupdate:installonquit": true,
"autoupdate:intervalms": 3600000,
"conn:askbeforewshinstall": true,
"conn:wshenabled": true,
"editor:minimapenabled": true,
"web:defaulturl": "https://github.com/wavetermdev/waveterm",
"web:defaultsearch": "https://www.google.com/search?q={query}",
Expand All @@ -100,6 +103,8 @@ For reference this is the current default configuration (v0.9.3):
"window:magnifiedblocksize": 0.9,
"window:magnifiedblockblurprimarypx": 10,
"window:magnifiedblockblursecondarypx": 2,
"window:confirmclose": true,
"window:savelastwindow": true,
"telemetry:enabled": true,
"term:copyonselect": true
}
Expand Down
40 changes: 20 additions & 20 deletions emain/emain-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,26 @@ export class WaveBrowserWindow extends BaseWindow {
e.preventDefault();
fireAndForget(async () => {
const numWindows = waveWindowMap.size;
if (numWindows > 1) {
console.log("numWindows > 1", numWindows);
const workspace = await WorkspaceService.GetWorkspace(this.workspaceId);
console.log("workspace", workspace);
if (isNonEmptyUnsavedWorkspace(workspace)) {
console.log("workspace has no name, icon, and multiple tabs", workspace);
const choice = dialog.showMessageBoxSync(this, {
type: "question",
buttons: ["Cancel", "Close Window"],
title: "Confirm",
message: "Window has unsaved tabs, closing window will delete existing tabs.\n\nContinue?",
});
if (choice === 0) {
console.log("user cancelled close window", this.waveWindowId);
return;
const fullConfig = await FileService.GetFullConfig();
if (numWindows > 1 || !fullConfig.settings["window:savelastwindow"]) {
console.log("numWindows > 1 or user does not want last window saved", numWindows);
if (fullConfig.settings["window:confirmclose"]) {
console.log("confirmclose", this.waveWindowId);
const workspace = await WorkspaceService.GetWorkspace(this.workspaceId);
console.log("workspace", workspace);
if (isNonEmptyUnsavedWorkspace(workspace)) {
console.log("workspace has no name, icon, and multiple tabs", workspace);
const choice = dialog.showMessageBoxSync(this, {
type: "question",
buttons: ["Cancel", "Close Window"],
title: "Confirm",
message:
"Window has unsaved tabs, closing window will delete existing tabs.\n\nContinue?",
});
if (choice === 0) {
console.log("user cancelled close window", this.waveWindowId);
return;
}
}
}
console.log("deleteAllowed = true", this.waveWindowId);
Expand All @@ -270,11 +275,6 @@ export class WaveBrowserWindow extends BaseWindow {
this.destroy();
return;
}
const numWindows = waveWindowMap.size;
if (numWindows == 0) {
console.log("win no windows left", this.waveWindowId);
return;
}
if (this.deleteAllowed) {
console.log("win removing window from backend DB", this.waveWindowId);
fireAndForget(() => WindowService.CloseWindow(this.waveWindowId, true));
Expand Down
2 changes: 2 additions & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ declare global {
"window:magnifiedblocksize"?: number;
"window:magnifiedblockblurprimarypx"?: number;
"window:magnifiedblockblursecondarypx"?: number;
"window:confirmclose"?: boolean;
"window:savelastwindow"?: boolean;
"telemetry:*"?: boolean;
"telemetry:enabled"?: boolean;
"conn:*"?: boolean;
Expand Down
4 changes: 3 additions & 1 deletion pkg/wconfig/defaultconfig/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"autoupdate:installonquit": true,
"autoupdate:intervalms": 3600000,
"conn:askbeforewshinstall": true,
"conn:wshenabled": true,
"conn:wshenabled": true,
"editor:minimapenabled": true,
"web:defaulturl": "https://github.com/wavetermdev/waveterm",
"web:defaultsearch": "https://www.google.com/search?q={query}",
Expand All @@ -18,6 +18,8 @@
"window:magnifiedblocksize": 0.9,
"window:magnifiedblockblurprimarypx": 10,
"window:magnifiedblockblursecondarypx": 2,
"window:confirmclose": true,
"window:savelastwindow": true,
"telemetry:enabled": true,
"term:copyonselect": true
}
2 changes: 2 additions & 0 deletions pkg/wconfig/metaconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const (
ConfigKey_WindowMagnifiedBlockSize = "window:magnifiedblocksize"
ConfigKey_WindowMagnifiedBlockBlurPrimaryPx = "window:magnifiedblockblurprimarypx"
ConfigKey_WindowMagnifiedBlockBlurSecondaryPx = "window:magnifiedblockblursecondarypx"
ConfigKey_WindowConfirmClose = "window:confirmclose"
ConfigKey_WindowSaveLastWindow = "window:savelastwindow"

ConfigKey_TelemetryClear = "telemetry:*"
ConfigKey_TelemetryEnabled = "telemetry:enabled"
Expand Down
2 changes: 2 additions & 0 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ type SettingsType struct {
WindowMagnifiedBlockSize *float64 `json:"window:magnifiedblocksize,omitempty"`
WindowMagnifiedBlockBlurPrimaryPx *int64 `json:"window:magnifiedblockblurprimarypx,omitempty"`
WindowMagnifiedBlockBlurSecondaryPx *int64 `json:"window:magnifiedblockblursecondarypx,omitempty"`
WindowConfirmClose bool `json:"window:confirmclose,omitempty"`
WindowSaveLastWindow bool `json:"window:savelastwindow,omitempty"`

TelemetryClear bool `json:"telemetry:*,omitempty"`
TelemetryEnabled bool `json:"telemetry:enabled,omitempty"`
Expand Down

0 comments on commit 62dcf13

Please sign in to comment.