Skip to content

Commit

Permalink
feat: Restore ability to toggle darkmode
Browse files Browse the repository at this point in the history
  • Loading branch information
sprout2000 committed Oct 22, 2024
1 parent 10d1621 commit 6610a1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/@types/Store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ declare type StoreType = {
height: number | undefined;
language?: string;
showmenu: boolean;
darkmode: boolean;
};
11 changes: 11 additions & 0 deletions src/createMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type MenuItemConstructorOptions,
app,
dialog,
nativeTheme,
shell,
} from "electron";

Expand Down Expand Up @@ -115,6 +116,16 @@ export const createMenu = (win: BrowserWindow, store: Conf<StoreType>) => {
visible: false,
},
{ type: "separator" },
{
label: i18next.t("Toggle Dark Mode"),
accelerator: "CmdOrCtrl+T",
type: "checkbox",
checked: store.get("darkmode"),
click: () => {
nativeTheme.themeSource = store.get("darkmode") ? "light" : "dark";
store.set("darkmode", !store.get("darkmode"));
},
},
];

if (!isDarwin) {
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const store = new Conf<StoreType>({
width: initWidth,
height: initHeight,
showmenu: true,
darkmode: true,
},
});

Expand Down Expand Up @@ -69,15 +70,15 @@ const createWindow = () => {
width: store.get("width"),
height: store.get("height"),
icon: path.join(getResourceDirectory(), "images/logo.png"),
backgroundColor: "#1e1e1e",
backgroundColor: nativeTheme.shouldUseDarkColors ? "#1e1e1e" : "#f6f6f6",
webPreferences: {
safeDialogs: true,
preload: path.join(__dirname, "preload.js"),
},
});

if (!isDarwin) mainWindow.setMenuBarVisibility(store.get("showmenu"));
nativeTheme.themeSource = "dark";
nativeTheme.themeSource = store.get("darkmode") ? "dark" : "light";

const menu = createMenu(mainWindow, store);
Menu.setApplicationMenu(menu);
Expand Down

0 comments on commit 6610a1f

Please sign in to comment.