mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-10 03:27:05 +00:00
fix(settings): harden audited state synchronization
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
resolveCategoryDestination
|
||||
} from '../utils/downloadLocations';
|
||||
import { canPauseDownload, canStartDownload } from '../utils/downloadActions';
|
||||
import { updateDockBadge } from '../utils/dockBadge';
|
||||
import i18n from '../i18n';
|
||||
|
||||
export type { DownloadCategory } from '../utils/downloads';
|
||||
@@ -487,7 +488,7 @@ export const getSiteLogin = (url: string, settings: ReturnType<typeof useSetting
|
||||
const syncSystemIntegrations = () => {
|
||||
const settings = useSettingsStore.getState();
|
||||
const activeCount = useDownloadStore.getState().downloads.filter(d => isTransferActiveStatus(d.status)).length;
|
||||
invoke('update_dock_badge', { count: settings.showDockBadge ? activeCount : 0 }).catch(() => {});
|
||||
updateDockBadge(settings.showDockBadge ? activeCount : 0).catch(() => {});
|
||||
};
|
||||
|
||||
const effectiveDestinationForItem = async (
|
||||
|
||||
@@ -37,6 +37,19 @@ describe('useSettingsStore global speed limit persistence', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('useSettingsStore dock badge synchronization', () => {
|
||||
it('increments the badge sync version for every toggle without issuing out-of-band clears', () => {
|
||||
vi.clearAllMocks();
|
||||
const initialVersion = useSettingsStore.getState().dockBadgeSyncVersion;
|
||||
|
||||
useSettingsStore.getState().setShowDockBadge(false);
|
||||
useSettingsStore.getState().setShowDockBadge(true);
|
||||
|
||||
expect(useSettingsStore.getState().dockBadgeSyncVersion).toBe(initialVersion + 2);
|
||||
expect(ipc.invokeCommand).not.toHaveBeenCalledWith('update_dock_badge', { count: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('useSettingsStore credential-store startup flow', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -203,6 +203,8 @@ export interface SettingsState {
|
||||
appFontSize: AppFontSize;
|
||||
listRowDensity: ListRowDensity;
|
||||
showDockBadge: boolean;
|
||||
/** Forces the App-level badge effect to run for every toggle request. */
|
||||
dockBadgeSyncVersion: number;
|
||||
showMenuBarIcon: boolean;
|
||||
proxyMode: ProxyMode;
|
||||
proxyHost: string;
|
||||
@@ -320,6 +322,7 @@ export const useSettingsStore = create<SettingsState>()(
|
||||
appFontSize: 'standard',
|
||||
listRowDensity: 'standard',
|
||||
showDockBadge: true,
|
||||
dockBadgeSyncVersion: 0,
|
||||
showMenuBarIcon: true,
|
||||
proxyMode: 'none',
|
||||
proxyHost: '',
|
||||
@@ -392,8 +395,10 @@ export const useSettingsStore = create<SettingsState>()(
|
||||
setAppFontSize: (appFontSize) => set({ appFontSize }),
|
||||
setListRowDensity: (listRowDensity) => set({ listRowDensity }),
|
||||
setShowDockBadge: (showDockBadge) => {
|
||||
set({ showDockBadge });
|
||||
if (!showDockBadge) invoke('update_dock_badge', { count: 0 }).catch(console.error);
|
||||
set(state => ({
|
||||
showDockBadge,
|
||||
dockBadgeSyncVersion: state.dockBadgeSyncVersion + 1
|
||||
}));
|
||||
},
|
||||
setShowMenuBarIcon: (showMenuBarIcon) => set({ showMenuBarIcon }),
|
||||
setProxyMode: (proxyMode) => set({ proxyMode }),
|
||||
|
||||
Reference in New Issue
Block a user