Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Development (with hot reload)
bun run dev

# Desktop development
# Desktop development (works on Windows too)
bun run dev:desktop

# Desktop development on an isolated port set
Expand All @@ -17,6 +17,9 @@ bun run start
# Build a shareable macOS .dmg (arm64 by default)
bun run dist:desktop:dmg

# Build a shareable Windows installer (.exe via NSIS)
bun run dist:desktop:win

# Or from any project directory after publishing:
npx t3
```
6 changes: 6 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { NetService } from "@t3tools/shared/Net";
import { RotatingFileSink } from "@t3tools/shared/logging";
import { showDesktopConfirmDialog } from "./confirmDialog";
import { fixPath } from "./fixPath";
import { isWindowsZoomInShortcut } from "./zoomShortcuts";
import {
getAutoUpdateDisabledReason,
shouldBroadcastDownloadProgress,
Expand Down Expand Up @@ -1115,6 +1116,11 @@ function createWindow(): BrowserWindow {
});

window.webContents.setWindowOpenHandler(() => ({ action: "deny" }));
window.webContents.on("before-input-event", (event, input) => {
if (!isWindowsZoomInShortcut(input)) return;
event.preventDefault();
window.webContents.setZoomLevel(window.webContents.getZoomLevel() + 0.5);
});
window.on("page-title-updated", (event) => {
event.preventDefault();
window.setTitle(APP_DISPLAY_NAME);
Expand Down
72 changes: 72 additions & 0 deletions apps/desktop/src/zoomShortcuts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { describe, expect, it } from "vitest";

import { isWindowsZoomInShortcut } from "./zoomShortcuts";

describe("isWindowsZoomInShortcut", () => {
it("matches Ctrl++ from the main keyboard on Windows", () => {
expect(
isWindowsZoomInShortcut(
{
type: "keyDown",
control: true,
shift: true,
key: "+",
code: "Equal",
},
"win32",
),
).toBe(true);
expect(
isWindowsZoomInShortcut(
{
type: "keyDown",
control: true,
shift: true,
key: "=",
code: "Equal",
},
"win32",
),
).toBe(true);
});

it("matches Ctrl+numpad plus on Windows", () => {
expect(
isWindowsZoomInShortcut(
{
type: "keyDown",
control: true,
key: "+",
code: "NumpadAdd",
},
"win32",
),
).toBe(true);
});

it("does not match unrelated shortcuts or other platforms", () => {
expect(
isWindowsZoomInShortcut(
{
type: "keyDown",
control: true,
key: "-",
code: "Minus",
},
"win32",
),
).toBe(false);
expect(
isWindowsZoomInShortcut(
{
type: "keyDown",
control: true,
shift: true,
key: "+",
code: "Equal",
},
"linux",
),
).toBe(false);
});
});
24 changes: 24 additions & 0 deletions apps/desktop/src/zoomShortcuts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
interface ZoomShortcutInput {
alt?: boolean;
code?: string;
control?: boolean;
key?: string;
meta?: boolean;
shift?: boolean;
type?: string;
}

export function isWindowsZoomInShortcut(
input: ZoomShortcutInput,
platform = process.platform,
): boolean {
if (platform !== "win32") return false;
if (input.type !== "keyDown") return false;
if (!input.control || input.alt || input.meta) return false;

return (
input.key === "+" ||
input.code === "NumpadAdd" ||
(input.shift === true && (input.key === "=" || input.code === "Equal"))
);
}