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
This commit is contained in:
Mohammed Zaid R Nadaf 2024-12-30 21:27:59 +05:30 committed by GitHub
parent cb2cd72cd4
commit a1f26ba455
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 17 deletions

View File

@ -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):

View File

@ -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"

View File

@ -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,

View File

@ -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;

View File

@ -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"

View File

@ -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"`