mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
add toggle for app-suspension for powersave block (#1992)
This commit is contained in:
@@ -1008,6 +1008,8 @@
|
||||
"audioFadeOnStatusChange_description": "enables fade out and fade in when play/pause status changes",
|
||||
"preventSleepOnPlayback_description": "prevent the display from sleeping while music is playing",
|
||||
"preventSleepOnPlayback": "prevent sleep on playback",
|
||||
"preventSuspendOnPlayback_description": "prevent the application from suspending while music is playing",
|
||||
"preventSuspendOnPlayback": "prevent suspend on playback",
|
||||
"remotePassword_description": "sets the password for the remote control server. These credentials are by default transferred insecurely, so you should use a unique password that you do not care about",
|
||||
"remotePassword": "remote control server password",
|
||||
"remotePort_description": "sets the port for the remote control server",
|
||||
|
||||
+4
-2
@@ -931,12 +931,14 @@ ipcMain.on(
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle('power-save-blocker-start', () => {
|
||||
ipcMain.handle('power-save-blocker-start', (_event, { full }: { full: boolean }) => {
|
||||
if (powerSaveBlockerId !== null) {
|
||||
return powerSaveBlockerId;
|
||||
}
|
||||
|
||||
powerSaveBlockerId = powerSaveBlocker.start('prevent-display-sleep');
|
||||
powerSaveBlockerId = powerSaveBlocker.start(
|
||||
full ? 'prevent-display-sleep' : 'prevent-app-suspension',
|
||||
);
|
||||
return powerSaveBlockerId;
|
||||
});
|
||||
|
||||
|
||||
@@ -8,17 +8,17 @@ const ipc = isElectron() ? window.api.ipc : null;
|
||||
|
||||
export const usePowerSaveBlocker = () => {
|
||||
const status = usePlayerStatus();
|
||||
const { preventSleepOnPlayback } = useWindowSettings();
|
||||
const { preventSleepOnPlayback, preventSuspendOnPlayback } = useWindowSettings();
|
||||
|
||||
const startPowerSaveBlocker = useCallback(async () => {
|
||||
if (!ipc) return;
|
||||
|
||||
try {
|
||||
await ipc.invoke('power-save-blocker-start');
|
||||
await ipc.invoke('power-save-blocker-start', { full: preventSleepOnPlayback });
|
||||
} catch (error) {
|
||||
console.error('Failed to start power save blocker:', error);
|
||||
}
|
||||
}, []);
|
||||
}, [preventSleepOnPlayback]);
|
||||
|
||||
const stopPowerSaveBlocker = useCallback(async () => {
|
||||
if (!ipc) return;
|
||||
@@ -31,16 +31,21 @@ export const usePowerSaveBlocker = () => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!preventSleepOnPlayback) return;
|
||||
if (!preventSleepOnPlayback || !preventSuspendOnPlayback) return;
|
||||
|
||||
if (status === PlayerStatus.PLAYING) {
|
||||
startPowerSaveBlocker();
|
||||
} else {
|
||||
stopPowerSaveBlocker();
|
||||
}
|
||||
}, [status, preventSleepOnPlayback, startPowerSaveBlocker, stopPowerSaveBlocker]);
|
||||
}, [
|
||||
status,
|
||||
preventSleepOnPlayback,
|
||||
startPowerSaveBlocker,
|
||||
stopPowerSaveBlocker,
|
||||
preventSuspendOnPlayback,
|
||||
]);
|
||||
|
||||
// Clean up on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
stopPowerSaveBlocker();
|
||||
@@ -56,8 +61,11 @@ const PowerSaveBlockerHookInner = () => {
|
||||
export const PowerSaveBlockerHook = () => {
|
||||
const isElectronEnv = isElectron();
|
||||
const preventSleepOnPlayback = useSettingsStore((state) => state.window.preventSleepOnPlayback);
|
||||
const preventSuspendOnPlayback = useSettingsStore(
|
||||
(state) => state.window.preventSuspendOnPlayback,
|
||||
);
|
||||
|
||||
if (!isElectronEnv || !preventSleepOnPlayback) {
|
||||
if (!isElectronEnv || !preventSleepOnPlayback || !preventSuspendOnPlayback) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ export const WindowSettings = memo(() => {
|
||||
<Switch
|
||||
aria-label="Toggle prevent sleep on playback"
|
||||
defaultChecked={settings.preventSleepOnPlayback}
|
||||
disabled={!isElectron()}
|
||||
disabled={!isElectron() || settings.preventSuspendOnPlayback}
|
||||
onChange={(e) => {
|
||||
if (!e) return;
|
||||
localSettings?.set(
|
||||
@@ -206,6 +206,33 @@ export const WindowSettings = memo(() => {
|
||||
isHidden: !isElectron(),
|
||||
title: t('setting.preventSleepOnPlayback', { postProcess: 'sentenceCase' }),
|
||||
},
|
||||
{
|
||||
control: (
|
||||
<Switch
|
||||
aria-label="Toggle prevent suspend on playback"
|
||||
defaultChecked={settings.preventSuspendOnPlayback}
|
||||
disabled={!isElectron() || settings.preventSleepOnPlayback}
|
||||
onChange={(e) => {
|
||||
if (!e) return;
|
||||
localSettings?.set(
|
||||
'window_prevent_suspend_on_playback',
|
||||
e.currentTarget.checked,
|
||||
);
|
||||
setSettings({
|
||||
window: {
|
||||
preventSuspendOnPlayback: e.currentTarget.checked,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
),
|
||||
description: t('setting.preventSuspendOnPlayback', {
|
||||
context: 'description',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
isHidden: !isElectron(),
|
||||
title: t('setting.preventSuspendOnPlayback', { postProcess: 'sentenceCase' }),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
@@ -638,6 +638,7 @@ const WindowSettingsSchema = z.object({
|
||||
exitToTray: z.boolean(),
|
||||
minimizeToTray: z.boolean(),
|
||||
preventSleepOnPlayback: z.boolean(),
|
||||
preventSuspendOnPlayback: z.boolean(),
|
||||
releaseChannel: z.enum(['alpha', 'beta', 'latest']),
|
||||
startMinimized: z.boolean(),
|
||||
tray: z.boolean(),
|
||||
@@ -1914,6 +1915,7 @@ const initialState: SettingsState = {
|
||||
exitToTray: false,
|
||||
minimizeToTray: false,
|
||||
preventSleepOnPlayback: false,
|
||||
preventSuspendOnPlayback: false,
|
||||
releaseChannel: 'latest',
|
||||
startMinimized: false,
|
||||
tray: true,
|
||||
|
||||
Reference in New Issue
Block a user