fix: Auto apply presets wasn't working as expected in some cases.

This commit is contained in:
Quentin Decaunes 2020-03-19 16:33:39 +01:00
parent 347b05bad7
commit 5629f8034a
2 changed files with 9 additions and 10 deletions

View File

@ -416,4 +416,5 @@ export {
executeRyzenAdjUsingPreset,
checkIfNewerReleaseExist as checkNewVersion,
isPresetValid,
appContextSettingsKey,
};

View File

@ -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<Promise<string | boolean>> = [];
@ -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);
}
});