From a1f26ba455d385cb566e0043437817adac18ec58 Mon Sep 17 00:00:00 2001 From: Mohammed Zaid R Nadaf Date: Mon, 30 Dec 2024 21:27:59 +0530 Subject: [PATCH] window-dimensions and zoom crash fixed (#1652) fixed issue #1613 partially, added window:dimensions as a setting which gives the user to define dimensions. fixed the zoom in and out logic to prevent the app from crashing. Had issues with getting setting zoomfactor in emain-tabview.ts. will fix it --- docs/docs/config.mdx | 1 + emain/emain-window.ts | 27 ++++++++++++++++++++++++++- emain/menu.ts | 20 ++++---------------- frontend/types/gotypes.d.ts | 2 ++ pkg/wconfig/metaconsts.go | 2 ++ pkg/wconfig/settingsconfig.go | 2 ++ 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/docs/docs/config.mdx b/docs/docs/config.mdx index 7d4225d74..4c2f8d492 100644 --- a/docs/docs/config.mdx +++ b/docs/docs/config.mdx @@ -79,6 +79,7 @@ wsh editconfig | 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`) | +| window:dimensions | string | set the default dimensions for new windows using the format "WIDTHxHEIGHT" (e.g. "1920x1080"). when a new window is created, these dimensions will be automatically applied. The width and height values should be specified in pixels. | | telemetry:enabled | bool | set to enable/disable telemetry | For reference, this is the current default configuration (v0.10.4): diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 539297cff..7fb1494f2 100644 --- a/emain/emain-window.ts +++ b/emain/emain-window.ts @@ -73,11 +73,37 @@ export class WaveBrowserWindow extends BaseWindow { private actionQueue: WindowActionQueueEntry[]; constructor(waveWindow: WaveWindow, fullConfig: FullConfigType, opts: WindowOpts) { + const settings = fullConfig?.settings; + console.log("create win", waveWindow.oid); let winWidth = waveWindow?.winsize?.width; let winHeight = waveWindow?.winsize?.height; let winPosX = waveWindow.pos.x; let winPosY = waveWindow.pos.y; + + if ( + (winWidth == null || winWidth === 0 || winHeight == null || winHeight === 0) && + settings?.["window:dimensions"] + ) { + const dimensions = settings["window:dimensions"]; + const match = dimensions.match(/^(\d+)[xX](\d+)$/); + + if (match) { + const [, dimensionWidth, dimensionHeight] = match; + const parsedWidth = parseInt(dimensionWidth, 10); + const parsedHeight = parseInt(dimensionHeight, 10); + + if ((!winWidth || winWidth === 0) && Number.isFinite(parsedWidth) && parsedWidth > 0) { + winWidth = parsedWidth; + } + if ((!winHeight || winHeight === 0) && Number.isFinite(parsedHeight) && parsedHeight > 0) { + winHeight = parsedHeight; + } + } else { + console.warn('Invalid window:dimensions format. Expected "widthxheight".'); + } + } + if (winWidth == null || winWidth == 0) { const primaryDisplay = screen.getPrimaryDisplay(); const { width } = primaryDisplay.workAreaSize; @@ -101,7 +127,6 @@ export class WaveBrowserWindow extends BaseWindow { height: winHeight, }; winBounds = ensureBoundsAreVisible(winBounds); - const settings = fullConfig?.settings; const winOpts: BaseWindowConstructorOptions = { titleBarStyle: opts.unamePlatform === "darwin" diff --git a/emain/menu.ts b/emain/menu.ts index 0aea5f125..3c1b29104 100644 --- a/emain/menu.ts +++ b/emain/menu.ts @@ -206,10 +206,7 @@ async function getAppMenu(callbacks: AppMenuCallbacks, workspaceId?: string): Pr if (wc == null) { return; } - if (wc.getZoomFactor() >= 5) { - return; - } - wc.setZoomFactor(wc.getZoomFactor() + 0.2); + wc.setZoomFactor(Math.min(5, wc.getZoomFactor() + 0.2)); }, }, { @@ -220,10 +217,7 @@ async function getAppMenu(callbacks: AppMenuCallbacks, workspaceId?: string): Pr if (wc == null) { return; } - if (wc.getZoomFactor() >= 5) { - return; - } - wc.setZoomFactor(wc.getZoomFactor() + 0.2); + wc.setZoomFactor(Math.min(5, wc.getZoomFactor() + 0.2)); }, visible: false, acceleratorWorksWhenHidden: true, @@ -236,10 +230,7 @@ async function getAppMenu(callbacks: AppMenuCallbacks, workspaceId?: string): Pr if (wc == null) { return; } - if (wc.getZoomFactor() <= 0.2) { - return; - } - wc.setZoomFactor(wc.getZoomFactor() - 0.2); + wc.setZoomFactor(Math.max(0.2, wc.getZoomFactor() - 0.2)); }, }, { @@ -250,10 +241,7 @@ async function getAppMenu(callbacks: AppMenuCallbacks, workspaceId?: string): Pr if (wc == null) { return; } - if (wc.getZoomFactor() <= 0.2) { - return; - } - wc.setZoomFactor(wc.getZoomFactor() - 0.2); + wc.setZoomFactor(Math.max(0.2, wc.getZoomFactor() - 0.2)); }, visible: false, acceleratorWorksWhenHidden: true, diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 0e3780761..10b0c8643 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -636,6 +636,8 @@ declare global { "window:magnifiedblockblursecondarypx"?: number; "window:confirmclose"?: boolean; "window:savelastwindow"?: boolean; + "window:dimensions"?: string; + "window:zoom"?: number; "telemetry:*"?: boolean; "telemetry:enabled"?: boolean; "conn:*"?: boolean; diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index e7cf00c0a..79f915548 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -81,6 +81,8 @@ const ( ConfigKey_WindowMagnifiedBlockBlurSecondaryPx = "window:magnifiedblockblursecondarypx" ConfigKey_WindowConfirmClose = "window:confirmclose" ConfigKey_WindowSaveLastWindow = "window:savelastwindow" + ConfigKey_WindowDimensions = "window:dimensions" + ConfigKey_WindowZoom = "window:zoom" ConfigKey_TelemetryClear = "telemetry:*" ConfigKey_TelemetryEnabled = "telemetry:enabled" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index e4325fb66..8d1afef54 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -108,6 +108,8 @@ type SettingsType struct { WindowMagnifiedBlockBlurSecondaryPx *int64 `json:"window:magnifiedblockblursecondarypx,omitempty"` WindowConfirmClose bool `json:"window:confirmclose,omitempty"` WindowSaveLastWindow bool `json:"window:savelastwindow,omitempty"` + WindowDimensions string `json:"window:dimensions,omitempty"` + WindowZoom *float64 `json:"window:zoom,omitempty"` TelemetryClear bool `json:"telemetry:*,omitempty"` TelemetryEnabled bool `json:"telemetry:enabled,omitempty"`