Skip to content

Commit

Permalink
update load setting
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Mar 15, 2024
1 parent 0a0e646 commit fe9b60d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/util/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class QAMPatch {
this.perfStore = perfStoreClass?.Get();
count++;
if (count >= 10) {
console.error("获取perfStore失败结束修补");
console.error("获取perfStore失败, 结束修补");
}
}
this.TDP_Patch = new TDPPatch();
Expand Down Expand Up @@ -108,10 +108,10 @@ class TDPPatch {
}

public setTDPRange(min?: number, max?: number) {
if (min) {
if (min && this.perfStore.msgLimits.tdp_limit_min != undefined) {
this.perfStore.msgLimits.tdp_limit_min = min;
}
if (max) {
if (max && this.perfStore.msgLimits.tdp_limit_max != undefined) {
this.perfStore.msgLimits.tdp_limit_max = max;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/pluginMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class PluginManager{
Backend.applySettings(APPLYTYPE.SET_ALL);
} catch (e) {
console.error("Error while applying settings", e);
Settings.resetToLocalStorage();
Settings.resetToLocalStorage(false);
}
PluginManager.suspendEndHook = SteamClient.System.RegisterForOnResumeFromSuspend(async () => {
setTimeout(() => {
Expand Down
14 changes: 9 additions & 5 deletions src/util/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ export class Settings {
return this._instance.data.fanSettings?.[fanProfileName];
}

// @ts-ignore
private static loadSettingsFromLocalStorage() {
const settingsString = localStorage.getItem(SETTINGS_KEY) || "{}";
const settingsJson = JSON.parse(settingsString);
Expand All @@ -782,10 +783,11 @@ export class Settings {
const settingsData = await Backend.getSettings();
if (settingsData) {
this._instance.data.deepCopy(settingsData);
} else {
// 从本地存储获取配置 (兼容旧版本数据)
this.loadSettingsFromLocalStorage();
}
// else {
// // 从本地存储获取配置 (兼容旧版本数据)
// this.loadSettingsFromLocalStorage();
// }
}

static saveSettingsToLocalStorage() {
Expand All @@ -796,13 +798,15 @@ export class Settings {
Backend.setSettings(this._instance.data);
}

static resetToLocalStorage() {
static resetToLocalStorage(apply = true) {
console.log(">>>>> resetToLocalStorage");
localStorage.removeItem(SETTINGS_KEY);
const _data = new SettingsData();
Backend.setSettings(_data);
Settings._instance.data.deepCopy(_data);
// Settings.loadSettingsFromLocalStorage();
Backend.applySettings(APPLYTYPE.SET_ALL);
if (apply) {
Backend.applySettings(APPLYTYPE.SET_ALL);
}
}
}

0 comments on commit fe9b60d

Please sign in to comment.