mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-16 00:14:23 +02:00
fix potential infinite updater loop due to stale settings sync state
This commit is contained in:
@@ -218,7 +218,8 @@
|
|||||||
"serverNotSelectedError": "no server selected",
|
"serverNotSelectedError": "no server selected",
|
||||||
"serverRequired": "server required",
|
"serverRequired": "server required",
|
||||||
"sessionExpiredError": "your session has expired",
|
"sessionExpiredError": "your session has expired",
|
||||||
"systemFontError": "an error occurred when trying to get system fonts"
|
"systemFontError": "an error occurred when trying to get system fonts",
|
||||||
|
"settingsSyncError": "discrepancies were found between the settings in the renderer and the main process. restart the application to apply the changes"
|
||||||
},
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"album": "$t(entity.album_one)",
|
"album": "$t(entity.album_one)",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import isElectron from 'is-electron';
|
import isElectron from 'is-electron';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
|
import i18n from '/@/i18n/i18n';
|
||||||
import { openRestartRequiredToast } from '/@/renderer/features/settings/restart-toast';
|
import { openRestartRequiredToast } from '/@/renderer/features/settings/restart-toast';
|
||||||
import { useSettingsStore } from '/@/renderer/store/settings.store';
|
import { useSettingsStore } from '/@/renderer/store/settings.store';
|
||||||
import { logFn } from '/@/renderer/utils/logger';
|
import { logFn } from '/@/renderer/utils/logger';
|
||||||
@@ -10,14 +11,6 @@ import { logMsg } from '/@/renderer/utils/logger-message';
|
|||||||
// on app initialization. If there are differences, it updates the main store and shows
|
// on app initialization. If there are differences, it updates the main store and shows
|
||||||
// a restart required toast.
|
// a restart required toast.
|
||||||
export const useSyncSettingsToMain = () => {
|
export const useSyncSettingsToMain = () => {
|
||||||
const settings = useSettingsStore((state) => ({
|
|
||||||
general: state.general,
|
|
||||||
hotkeys: state.hotkeys,
|
|
||||||
lyrics: state.lyrics,
|
|
||||||
playback: state.playback,
|
|
||||||
window: state.window,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const hasRunRef = useRef(false);
|
const hasRunRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -30,11 +23,22 @@ export const useSyncSettingsToMain = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait a small amount of time to ensure the store is hydrated from localStorage
|
// Wait some before checking for differences to ensure the store is hydrated from localStorage
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
if (hasRunRef.current) {
|
if (hasRunRef.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settingsFromStore = useSettingsStore.getState();
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
general: settingsFromStore.general,
|
||||||
|
hotkeys: settingsFromStore.hotkeys,
|
||||||
|
lyrics: settingsFromStore.lyrics,
|
||||||
|
playback: settingsFromStore.playback,
|
||||||
|
window: settingsFromStore.window,
|
||||||
|
};
|
||||||
|
|
||||||
hasRunRef.current = true;
|
hasRunRef.current = true;
|
||||||
|
|
||||||
const localSettings = window.api.localSettings;
|
const localSettings = window.api.localSettings;
|
||||||
@@ -113,14 +117,15 @@ export const useSyncSettingsToMain = () => {
|
|||||||
// Show restart toast if there were differences
|
// Show restart toast if there were differences
|
||||||
if (hasDifferences) {
|
if (hasDifferences) {
|
||||||
logFn.info(logMsg.system.settingsSynchronized);
|
logFn.info(logMsg.system.settingsSynchronized);
|
||||||
openRestartRequiredToast();
|
openRestartRequiredToast(
|
||||||
|
i18n.t('error.settingsSyncError', { postProcess: 'sentenceCase' }),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 5000);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
};
|
};
|
||||||
// Only run once on mount
|
// Only run once on mount
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1530,10 +1530,16 @@ export const useSettingsStore = createWithEqualityFn<SettingsSlice>()(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version 16 introduced a bug where the release channel may have been reset
|
||||||
|
// to the latest channel. This is to revert it.
|
||||||
|
if (version === 16) {
|
||||||
|
state.window.releaseChannel = 'beta';
|
||||||
|
}
|
||||||
|
|
||||||
return persistedState;
|
return persistedState;
|
||||||
},
|
},
|
||||||
name: 'store_settings',
|
name: 'store_settings',
|
||||||
version: 16,
|
version: 17,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user