-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add zoom slider, match official client zoom #370
base: main
Are you sure you want to change the base?
Changes from all commits
54dd33d
d516595
47aff14
1e333fa
9f9038c
1cb5680
2bbc8d3
436837d
5b66750
2412da5
63a625d
43f92c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import { | |||||
BrowserWindow, | ||||||
BrowserWindowConstructorOptions, | ||||||
dialog, | ||||||
globalShortcut, | ||||||
Menu, | ||||||
MenuItemConstructorOptions, | ||||||
nativeTheme, | ||||||
|
@@ -235,14 +236,14 @@ function initMenuBar(win: BrowserWindow) { | |||||
click() { | ||||||
app.quit(); | ||||||
} | ||||||
}, | ||||||
// See https://github.com/electron/electron/issues/14742 and https://github.com/electron/electron/issues/5256 | ||||||
{ | ||||||
label: "Zoom in (hidden, hack for Qwertz and others)", | ||||||
accelerator: "CmdOrCtrl+=", | ||||||
role: "zoomIn", | ||||||
visible: false | ||||||
} | ||||||
// See https://github.com/electron/electron/issues/14742 and https://github.com/electron/electron/issues/5256 | ||||||
// { | ||||||
// label: "Zoom in (hidden, hack for Qwertz and others)", | ||||||
// accelerator: "CmdOrCtrl+=", | ||||||
// role: "zoomIn", | ||||||
// visible: false | ||||||
// } | ||||||
] satisfies MenuItemList; | ||||||
|
||||||
const menu = Menu.buildFromTemplate([ | ||||||
|
@@ -467,6 +468,36 @@ function createMainWindow() { | |||||
|
||||||
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js"))); | ||||||
|
||||||
const allowedZoomFactors = [0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2]; | ||||||
|
||||||
function handleZoomIn() { | ||||||
const zoomFactor = Settings.store.zoomFactor ?? 1; | ||||||
const currentIndex = allowedZoomFactors.indexOf(zoomFactor); | ||||||
if (currentIndex < allowedZoomFactors.length - 1) { | ||||||
const newZoomFactor = allowedZoomFactors[currentIndex + 1]; | ||||||
Settings.setData({ zoomFactor: newZoomFactor }); | ||||||
mainWin.webContents.setZoomFactor(newZoomFactor); | ||||||
mainWin.webContents.send("zoomChanged", newZoomFactor); | ||||||
} | ||||||
} | ||||||
|
||||||
function handleZoomOut() { | ||||||
const zoomFactor = Settings.store.zoomFactor ?? 1; | ||||||
const currentIndex = allowedZoomFactors.indexOf(zoomFactor); | ||||||
if (currentIndex > 0) { | ||||||
const newZoomFactor = allowedZoomFactors[currentIndex - 1]; | ||||||
Settings.setData({ zoomFactor: newZoomFactor }); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setData changes the entire underlying settings data. this will effectively reset all settings. what you instead want is to set the property on store
Suggested change
there are more locations with the same error, those also need fixing |
||||||
mainWin.webContents.setZoomFactor(newZoomFactor); | ||||||
mainWin.webContents.send("zoomChanged", newZoomFactor); | ||||||
} | ||||||
} | ||||||
|
||||||
function resetZoom() { | ||||||
Settings.setData({ zoomFactor: 1 }); | ||||||
mainWin.webContents.setZoomFactor(1); | ||||||
mainWin.webContents.send("zoomChanged", 1); | ||||||
} | ||||||
|
||||||
export async function createWindows() { | ||||||
const startMinimized = process.argv.includes("--start-minimized"); | ||||||
const splash = createSplashWindow(startMinimized); | ||||||
|
@@ -480,6 +511,8 @@ export async function createWindows() { | |||||
mainWin.webContents.on("did-finish-load", () => { | ||||||
splash.destroy(); | ||||||
|
||||||
mainWin.webContents.setZoomFactor(Settings.store.zoomFactor ?? 1); | ||||||
|
||||||
if (!startMinimized) { | ||||||
mainWin!.show(); | ||||||
if (State.store.maximized && !isDeckGameMode) mainWin!.maximize(); | ||||||
|
@@ -497,6 +530,32 @@ export async function createWindows() { | |||||
mainWin!.maximize(); | ||||||
} | ||||||
}); | ||||||
|
||||||
mainWin.on("focus", () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a really bad way to do this. why not use menu items with accelerators like previously? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it refused to work with the menu items after hours of trying. If anyone is able to get it working that way instead that would be super helpful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it works very much the same. did you maybe forget to remove the default zoom handlers? they might take priority over your accelerators |
||||||
globalShortcut.register("CommandOrControl+0", () => { | ||||||
resetZoom(); | ||||||
}); | ||||||
globalShortcut.register("CommandOrControl+plus", () => { | ||||||
handleZoomIn(); | ||||||
}); | ||||||
globalShortcut.register("CommandOrControl+=", () => { | ||||||
handleZoomIn(); | ||||||
}); | ||||||
globalShortcut.register("CommandOrControl+-", () => { | ||||||
handleZoomOut(); | ||||||
}); | ||||||
globalShortcut.register("CommandOrControl+_", () => { | ||||||
handleZoomOut(); | ||||||
}); | ||||||
}); | ||||||
|
||||||
mainWin.on("blur", () => { | ||||||
globalShortcut.unregister("CommandOrControl+0"); | ||||||
globalShortcut.unregister("CommandOrControl+plus"); | ||||||
globalShortcut.unregister("CommandOrControl+="); | ||||||
globalShortcut.unregister("CommandOrControl+-"); | ||||||
globalShortcut.unregister("CommandOrControl+_"); | ||||||
}); | ||||||
}); | ||||||
|
||||||
// evil hack to fix electron 32 regression that makes devtools always light theme | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
/* | ||||||
* SPDX-License-Identifier: GPL-3.0 | ||||||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience | ||||||
* Copyright (c) 2023 Vendicated and Vencord contributors | ||||||
*/ | ||||||
|
||||||
import { Margins } from "@vencord/types/utils"; | ||||||
import { Forms, Slider, useEffect, useState } from "@vencord/types/webpack/common"; | ||||||
|
||||||
import { SettingsComponent } from "./Settings"; | ||||||
|
||||||
export const WindowZoom: SettingsComponent = ({ settings }) => { | ||||||
const [zoomFactor, setZoomFactor] = useState(settings.zoomFactor ?? 1); | ||||||
|
||||||
useEffect(() => { | ||||||
const handleZoomChange = event => { | ||||||
console.log("zoom changed", event.detail); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
setZoomFactor(event.detail); | ||||||
}; | ||||||
|
||||||
window.addEventListener("zoomChanged", handleZoomChange); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you shouldn't need this event. changing settings will already update your state & rerender the ui There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the listener, and the UI element does not update when the zoom gets changed, even with a listener |
||||||
|
||||||
return () => { | ||||||
window.removeEventListener("zoomChanged", handleZoomChange); | ||||||
}; | ||||||
}, []); | ||||||
|
||||||
return ( | ||||||
<> | ||||||
<Forms.FormTitle className={Margins.top16 + " " + Margins.bottom8}>Zoom Level</Forms.FormTitle> | ||||||
<Slider | ||||||
className={Margins.top20} | ||||||
initialValue={zoomFactor} | ||||||
defaultValue={1} | ||||||
onValueChange={v => { | ||||||
settings.zoomFactor = v; | ||||||
VesktopNative.win.zoom(v); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need this ipc call. you can register a settings change listener in the native process, look at the |
||||||
setZoomFactor(v); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need this state. via the parent component already uses this hook so you should not need to call it yourself |
||||||
}} | ||||||
minValue={0.5} | ||||||
maxValue={2} | ||||||
markers={[0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2]} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this constant seems duplicated across multiple files. for better maintainability, it should be moved to the shared/ folder |
||||||
stickToMarkers={true} | ||||||
onMarkerRender={v => (v === 1 ? "100" : `${Math.round(v * 100)}`)} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
></Slider> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</> | ||||||
); | ||||||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ export const enum IpcEvents { | |||||
FOCUS = "VCD_FOCUS", | ||||||
MINIMIZE = "VCD_MINIMIZE", | ||||||
MAXIMIZE = "VCD_MAXIMIZE", | ||||||
SET_ZOOM = "VCD_ZOOM", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER", | ||||||
GET_SETTINGS = "VCD_GET_SETTINGS", | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ export interface Settings { | |
arRPC?: boolean; | ||
appBadge?: boolean; | ||
disableMinSize?: boolean; | ||
zoomFactor?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't this make a lot more sense in State than in Settings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then how would it persist after restarting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. state is also persisted! |
||
clickTrayToShowHide?: boolean; | ||
customTitleBar?: boolean; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you just want to check for existence of an element, includes should be used over indexOf