Skip to content
Open
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
1 change: 1 addition & 0 deletions src/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare type DesktopConfig = {
spellchecker: boolean;
hardwareAcceleration: boolean;
discordRpc: boolean;
enableDevtoolsUntilTimestamp: number;
windowState: {
x: number;
y: number;
Expand Down
15 changes: 15 additions & 0 deletions src/native/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const store = new Store({
spellchecker: true,
hardwareAcceleration: true,
discordRpc: true,
enableDevtoolsUntilTimestamp: 0,
windowState: {
x: 0,
y: 0,
Expand All @@ -83,6 +84,7 @@ class Config {
spellchecker: this.spellchecker,
hardwareAcceleration: this.hardwareAcceleration,
discordRpc: this.discordRpc,
enableDevtoolsUntilTimestamp: this.enableDevtoolsUntilTimestamp,
windowState: this.windowState,
});
}
Expand Down Expand Up @@ -192,6 +194,19 @@ class Config {
this.sync();
}

get enableDevtoolsUntilTimestamp() {
return (store as never as { get(k: string): number }).get("discordRpc");
}

set enableDevtoolsUntilTimestamp(value: number) {
(store as never as { set(k: string, value: number): void }).set(
"enableDevtoolsUntilTimestamp",
value,
);

this.sync();
}

get windowState() {
return (
store as never as { get(k: string): DesktopConfig["windowState"] }
Expand Down
29 changes: 29 additions & 0 deletions src/native/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import windowIconAsset from "../../assets/desktop/icon.png?asset";
import { config } from "./config";
import { updateTrayMenu } from "./tray";

// Surprisingly, I am having a lot of trouble figuring out what to name this?
// I want the warning to actually warn the end user instead of just being a
// very generic "I know what I am doing" dialog that is instinctively skipped.
const bypassDevtoolsExpirationSetting = process.argv.includes(
"--bypass-devtools-expiration-and-i-am-not-being-told-to-paste-scripts"
);

// global reference to main window
export let mainWindow: BrowserWindow;

Expand Down Expand Up @@ -141,6 +148,28 @@ export function createMainWindow() {
}
});

// Afaik, this is the easiest way to let the app
// turn the keybinds for opening devtools on/off.
// Adapted from: https://stackoverflow.com/a/75716165
mainWindow.webContents.on("before-input-event", (_, input) => {
if (input.type !== "keyDown") {
return;
}

const devtoolsExpired = config.enableDevtoolsUntilTimestamp < Date.now();
if (devtoolsExpired && !bypassDevtoolsExpirationSetting) {
config.enableDevtoolsUntilTimestamp = 0;
return;
}

// `input.key`, for letters, is UPPERCASE if shift is pressed, lowercase otherwise.
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
const ctrlShiftI = input.control && input.key === "I";
if (ctrlShiftI || input.key === "F12") {
mainWindow.webContents.toggleDevTools();
}
});

// send the config
mainWindow.webContents.on("did-finish-load", () => config.sync());

Expand Down