Skip to content

Commit

Permalink
fix for dark-white auto toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Jan 24, 2025
1 parent 27b5bfa commit 3510d76
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
58 changes: 51 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1390,15 +1390,42 @@ ipcMain.on("settings-win-context-menu", function (event, message) {
}
})

nativeTheme.on('updated', () => {
isDarkMode(); // also toggle for dark mode
});

function isDarkMode() {
if (app.isReady()) {
if (store.has("dark-or-white")) {
if (store.get("dark-or-white") === "light") {
if (win != null) win.setBackgroundColor('#fefefe');
if (customDialogWin != null) customDialogWin.setBackgroundColor('#fefefe');
if (store.has("dark-or-white") && store.get("dark-or-white") !== 0) {
if (store.get("dark-or-white") === 1) {
if (win != null) {
win.setBackgroundColor('#fefefe');
win.webContents.send('darkModeChanges');
}
if (customDialogWin != null) {
customDialogWin.setBackgroundColor('#fefefe');
customDialogWin.webContents.send('darkModeChanges');
}
if (settingsWin != null) {
settingsWin.setBackgroundColor('#fefefe');
settingsWin.webContents.send('darkModeChanges-settings');
}
styleCache.set('isdark', false);
return false;
} else {
if (customDialogWin != null) customDialogWin.setBackgroundColor('#191919');
if (win != null) {
win.setBackgroundColor('#191919');
win.webContents.send('darkModeChanges');
}
if (customDialogWin != null) {
customDialogWin.setBackgroundColor('#191919');
customDialogWin.webContents.send('darkModeChanges');
}
if (settingsWin != null) {
settingsWin.setBackgroundColor('#191919');
settingsWin.webContents.send('darkModeChanges-settings');
}
styleCache.set('isdark', true);
return true;
}
} else {
Expand All @@ -1410,17 +1437,34 @@ function isDarkMode() {
}

function darkModeSettingsFinder() {
if (nativeTheme.shouldUseDarkColors && store.get("dark-or-white") !== "light") {
if (nativeTheme.shouldUseDarkColors && store.get("dark-or-white") !== 1) {
styleCache.set('isdark', true);
if (win != null) {
win.setBackgroundColor('#191919');
win.webContents.send('darkModeChanges');
}
if (customDialogWin != null) customDialogWin.setBackgroundColor('#191919');
if (customDialogWin != null) {
customDialogWin.setBackgroundColor('#191919');
customDialogWin.webContents.send('darkModeChanges');
}
if (settingsWin != null) {
settingsWin.setBackgroundColor('#191919');
settingsWin.webContents.send('darkModeChanges-settings');
}
} else {
styleCache.set('isdark', false);
if (win != null) {
win.setBackgroundColor('#fefefe');
win.webContents.send('darkModeChanges');
}
if (customDialogWin != null) {
customDialogWin.setBackgroundColor('#fefefe');
customDialogWin.webContents.send('darkModeChanges');
}
if (settingsWin != null) {
settingsWin.setBackgroundColor('#fefefe');
settingsWin.webContents.send('darkModeChanges-settings');
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion supporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function getHelp(idCode) {
}

function isInDark() {
if (store.get("dark-or-white") === 0) {
if (store.get("dark-or-white") === 0 || !store.has("dark-or-white")) {
isDarkMode = styleCache.get('isdark');
} else {
isDarkMode = store.get("dark-or-white") === 2;
Expand Down

0 comments on commit 3510d76

Please sign in to comment.