Fix warnings when handling system theme
@@ -3,29 +3,32 @@ import { ipcRenderer } from "electron";
import darkTheme from "!!raw-loader!../../styles/theme-dark.css";
import lightTheme from "!!raw-loader!../../styles/theme.css";
-const { systemPreferences } = require("electron").remote;
+const { nativeTheme } = require("electron").remote;
+
+const updateMyAppTheme = () => {
+ const settingsTheme = settings.get("theme");
+ const theme =
+ settingsTheme === "dark"
+ ? "dark"
+ : settingsTheme === "light"
+ ? "light"
+ : "system";
-function updateMyAppTheme() {
const darkMode =
- settings.get("theme") === "dark" ||
- (settings.get("theme") === undefined &&
- systemPreferences.isDarkMode &&
- systemPreferences.isDarkMode());
+ theme === "dark" || (theme === "system" && nativeTheme.shouldUseDarkColors);
+
const themeStyle = document.getElementById("theme");
themeStyle.innerHTML = darkMode ? darkTheme : lightTheme;
-}
-if (systemPreferences.subscribeNotification) {
- systemPreferences.subscribeNotification(
- "AppleInterfaceThemeChangedNotification",
- function theThemeHasChanged() {
- updateMyAppTheme();
- }
- );
+ nativeTheme.themeSource = theme;
}
+nativeTheme.on("updated", () => {
updateMyAppTheme();
+});
ipcRenderer.on("update-theme", () => {
updateMyAppTheme();
});
+
+updateMyAppTheme();
