Skip to content

Allow users to close windows without confirming, delete last window #1598

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 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading