From 5629f8034ae41d924d14887cdd28273934565a62 Mon Sep 17 00:00:00 2001 From: Quentin Decaunes Date: Thu, 19 Mar 2020 16:33:39 +0100 Subject: [PATCH] fix: Auto apply presets wasn't working as expected in some cases. --- src/contexts/RyzenControllerAppContext.tsx | 1 + src/scenes/Scene.tsx | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/contexts/RyzenControllerAppContext.tsx b/src/contexts/RyzenControllerAppContext.tsx index bb7b3f2..7620551 100644 --- a/src/contexts/RyzenControllerAppContext.tsx +++ b/src/contexts/RyzenControllerAppContext.tsx @@ -416,4 +416,5 @@ export { executeRyzenAdjUsingPreset, checkIfNewerReleaseExist as checkNewVersion, isPresetValid, + appContextSettingsKey, }; diff --git a/src/scenes/Scene.tsx b/src/scenes/Scene.tsx index e0ccba8..d973943 100644 --- a/src/scenes/Scene.tsx +++ b/src/scenes/Scene.tsx @@ -6,13 +6,13 @@ import RyzenControllerAppContext, { persistentSave, getSettingDefinition, executeRyzenAdjUsingPreset, + appContextSettingsKey, } from "../contexts/RyzenControllerAppContext"; import RyzenAdjScene from "../scenes/RyzenAdjScene"; import PresetsScene from "../scenes/PresetsScene"; import SettingsScene from "../scenes/SettingsScene"; import NotificationContext from "../contexts/NotificationContext"; import { getTranslation } from "../contexts/LocaleContext"; -import AppVersion from "../contexts/AppVersion"; const electronSettings = window.require("electron-settings"); const powerMonitor = window.require("electron").remote.powerMonitor; @@ -32,10 +32,8 @@ class Scene extends React.Component<{}, RyzenControllerAppContextType> { }; componentDidMount() { - let settings = electronSettings.get(AppVersion.string); - if (settings) { - settings = settings.settings; - } else { + let settings = electronSettings.get(`${appContextSettingsKey}.settings`); + if (!settings) { settings = defaultRyzenControllerAppContext.settings; } let newSettingsPromises: Array> = []; @@ -63,7 +61,7 @@ class Scene extends React.Component<{}, RyzenControllerAppContextType> { } powerMonitor.on("unlock-screen", () => { - const presetName = electronSettings.get(AppVersion.string)?.settings?.onSessionResume; + const presetName = electronSettings.get(`${appContextSettingsKey}.settings.onSessionResume`); if (presetName) { executeRyzenAdjUsingPreset(presetName); } @@ -80,15 +78,15 @@ class Scene extends React.Component<{}, RyzenControllerAppContextType> { handleBatteryStatusChange() { powerMonitor.on("on-ac", () => { - const presetName = electronSettings.get(AppVersion.string)?.settings?.onLaptopPluggedIn; - if (presetName !== false && presetName !== "") { + const presetName = electronSettings.get(`${appContextSettingsKey}.settings.onLaptopPluggedIn`); + if (presetName) { executeRyzenAdjUsingPreset(presetName); } }); powerMonitor.on("on-battery", () => { - const presetName = electronSettings.get(AppVersion.string)?.settings?.onLaptopPluggedOut; - if (presetName !== false && presetName !== "") { + const presetName = electronSettings.get(`${appContextSettingsKey}.settings.onLaptopPluggedOut`); + if (presetName) { executeRyzenAdjUsingPreset(presetName); } });