Skip to content
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 support for mouse wheel zoom #32

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion src/app/components/mini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const Mini: React.FC = () => {
</span>
:{" "}
<span
style={{ color: radio.currentlyRx ? "green" : "inherit" }}
style={{
color: radio.currentlyRx ? "lightgreen" : "inherit",
pierr3 marked this conversation as resolved.
Show resolved Hide resolved
}}
>
{radio.lastReceivedCallsign ? radio.lastReceivedCallsign : ""}
</span>
Expand Down
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { getKeyFromNumber } from "./helper";
declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;

// The increment for window zoom with each mouse wheel movement
const ZOOM_DELTA = 0.2;

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require("electron-squirrel-startup")) app.quit();

Expand Down Expand Up @@ -100,10 +103,19 @@ const createWindow = (): void => {
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
// Required to handle resetting the zoom level to 1.0 on app launch
show: false,
});

mainWindow.setAlwaysOnTop(currentConfiguration.alwaysOnTop || false);

// Reset the zoom level to 1.0 on app launch. This is to work around a long-standing
// bug in Electron that was opened in 2017 and closed without fixing. See
// https://github.com/electron/electron/issues/10572 for more details.
mainWindow.once("ready-to-show", () => {
mainWindow.webContents.zoomFactor = 1.0;
});

if (process.platform !== "darwin") {
mainWindow.setMenu(null);
}
Expand All @@ -130,6 +142,24 @@ const createWindow = (): void => {
}
}
});

// Support setting window zoom via ctrl + mouse wheel
mainWindow.webContents.on("zoom-changed", (_, zoomDirection) => {
const currentZoom = mainWindow.webContents.getZoomFactor();
const newZoom =
zoomDirection === "in"
? currentZoom + ZOOM_DELTA
: currentZoom - ZOOM_DELTA;

// Cap the zoom level between 100% and 300%. There's a setVisualZoomLevelLimits() in electron
// but it's async, and also appears to only limit the pinch-to-zoom level, not the zoom level
// set via setZoomFactor().
if (newZoom > 1 && newZoom < 3) {
mainWindow.webContents.setZoomFactor(newZoom);
}
});

mainWindow.show();
};

// This method will be called when Electron has finished
Expand Down
Loading