mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
Merge pull request #1034 from Lyall-A/private-mode
add private mode toggle to app menu
This commit is contained in:
commit
59065d24bc
7 changed files with 81 additions and 20 deletions
|
|
@ -6,6 +6,7 @@ import { controller } from '/@/renderer/api/controller';
|
|||
import {
|
||||
DiscordDisplayType,
|
||||
getServerById,
|
||||
useAppStore,
|
||||
useDiscordSetttings,
|
||||
useGeneralSettings,
|
||||
usePlayerStore,
|
||||
|
|
@ -18,6 +19,7 @@ const discordRpc = isElectron() ? window.api.discordRpc : null;
|
|||
export const useDiscordRpc = () => {
|
||||
const discordSettings = useDiscordSetttings();
|
||||
const generalSettings = useGeneralSettings();
|
||||
const { privateMode } = useAppStore();
|
||||
const [lastUniqueId, setlastUniqueId] = useState('');
|
||||
|
||||
const setActivity = useCallback(
|
||||
|
|
@ -148,15 +150,15 @@ export const useDiscordRpc = () => {
|
|||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!discordSettings.enabled) return discordRpc?.quit();
|
||||
if (!discordSettings.enabled || privateMode) return discordRpc?.quit();
|
||||
|
||||
return () => {
|
||||
discordRpc?.quit();
|
||||
};
|
||||
}, [discordSettings.clientId, discordSettings.enabled]);
|
||||
}, [discordSettings.clientId, privateMode, discordSettings.enabled]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!discordSettings.enabled) return;
|
||||
if (!discordSettings.enabled || privateMode) return;
|
||||
const unsubSongChange = usePlayerStore.subscribe(
|
||||
(state) => [state.current.song, state.current.time, state.current.status],
|
||||
setActivity,
|
||||
|
|
@ -164,5 +166,5 @@ export const useDiscordRpc = () => {
|
|||
return () => {
|
||||
unsubSongChange();
|
||||
};
|
||||
}, [discordSettings.enabled, setActivity]);
|
||||
}, [discordSettings.enabled, privateMode, setActivity]);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { useSendScrobble } from '/@/renderer/features/player/mutations/scrobble-mutation';
|
||||
import { usePlayerStore } from '/@/renderer/store';
|
||||
import { usePlaybackSettings } from '/@/renderer/store/settings.store';
|
||||
import { useAppStore, usePlaybackSettings, usePlayerStore } from '/@/renderer/store';
|
||||
import { QueueSong, ServerType } from '/@/shared/types/domain-types';
|
||||
import { PlayerStatus } from '/@/shared/types/types';
|
||||
|
||||
|
|
@ -59,13 +58,14 @@ const checkScrobbleConditions = (args: {
|
|||
export const useScrobble = () => {
|
||||
const scrobbleSettings = usePlaybackSettings().scrobble;
|
||||
const isScrobbleEnabled = scrobbleSettings?.enabled;
|
||||
const isPrivateModeEnabled = useAppStore().privateMode;
|
||||
const sendScrobble = useSendScrobble();
|
||||
|
||||
const [isCurrentSongScrobbled, setIsCurrentSongScrobbled] = useState(false);
|
||||
|
||||
const handleScrobbleFromSeek = useCallback(
|
||||
(currentTime: number) => {
|
||||
if (!isScrobbleEnabled) return;
|
||||
if (!isScrobbleEnabled || isPrivateModeEnabled) return;
|
||||
|
||||
const currentSong = usePlayerStore.getState().current.song;
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ export const useScrobble = () => {
|
|||
serverId: currentSong?.serverId,
|
||||
});
|
||||
},
|
||||
[isScrobbleEnabled, sendScrobble],
|
||||
[isScrobbleEnabled, isPrivateModeEnabled, sendScrobble],
|
||||
);
|
||||
|
||||
const progressIntervalId = useRef<null | ReturnType<typeof setInterval>>(null);
|
||||
|
|
@ -119,7 +119,7 @@ export const useScrobble = () => {
|
|||
}, 1000);
|
||||
}
|
||||
|
||||
if (!isScrobbleEnabled) return;
|
||||
if (!isScrobbleEnabled || isPrivateModeEnabled) return;
|
||||
|
||||
if (progressIntervalId.current) {
|
||||
clearInterval(progressIntervalId.current);
|
||||
|
|
@ -201,6 +201,7 @@ export const useScrobble = () => {
|
|||
scrobbleSettings?.scrobbleAtDuration,
|
||||
scrobbleSettings?.scrobbleAtPercentage,
|
||||
isScrobbleEnabled,
|
||||
isPrivateModeEnabled,
|
||||
isCurrentSongScrobbled,
|
||||
sendScrobble,
|
||||
handleScrobbleFromSeek,
|
||||
|
|
@ -209,7 +210,7 @@ export const useScrobble = () => {
|
|||
|
||||
const handleScrobbleFromStatusChange = useCallback(
|
||||
(current: PlayerEvent, previous: PlayerEvent) => {
|
||||
if (!isScrobbleEnabled) return;
|
||||
if (!isScrobbleEnabled || isPrivateModeEnabled) return;
|
||||
|
||||
const currentSong = usePlayerStore.getState().current.song;
|
||||
|
||||
|
|
@ -293,6 +294,7 @@ export const useScrobble = () => {
|
|||
},
|
||||
[
|
||||
isScrobbleEnabled,
|
||||
isPrivateModeEnabled,
|
||||
sendScrobble,
|
||||
handleScrobbleFromSeek,
|
||||
scrobbleSettings?.scrobbleAtDuration,
|
||||
|
|
@ -306,7 +308,7 @@ export const useScrobble = () => {
|
|||
// need to perform another check to see if the scrobble conditions are met
|
||||
const handleScrobbleFromSongRestart = useCallback(
|
||||
(currentTime: number) => {
|
||||
if (!isScrobbleEnabled) return;
|
||||
if (!isScrobbleEnabled || isPrivateModeEnabled) return;
|
||||
|
||||
const currentSong = usePlayerStore.getState().current.song;
|
||||
|
||||
|
|
@ -349,6 +351,7 @@ export const useScrobble = () => {
|
|||
},
|
||||
[
|
||||
isScrobbleEnabled,
|
||||
isPrivateModeEnabled,
|
||||
scrobbleSettings?.scrobbleAtDuration,
|
||||
scrobbleSettings?.scrobbleAtPercentage,
|
||||
isCurrentSongScrobbled,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { ServerList } from '/@/renderer/features/servers';
|
|||
import { EditServerForm } from '/@/renderer/features/servers/components/edit-server-form';
|
||||
import { AppRoute } from '/@/renderer/router/routes';
|
||||
import {
|
||||
useAppStore,
|
||||
useAppStoreActions,
|
||||
useAuthStoreActions,
|
||||
useCurrentServer,
|
||||
|
|
@ -18,6 +19,7 @@ import {
|
|||
} from '/@/renderer/store';
|
||||
import { DropdownMenu } from '/@/shared/components/dropdown-menu/dropdown-menu';
|
||||
import { Icon } from '/@/shared/components/icon/icon';
|
||||
import { toast } from '/@/shared/components/toast/toast';
|
||||
import { ServerListItem, ServerType } from '/@/shared/types/domain-types';
|
||||
|
||||
const browser = isElectron() ? window.api.browser : null;
|
||||
|
|
@ -30,7 +32,8 @@ export const AppMenu = () => {
|
|||
const serverList = useServerList();
|
||||
const { setCurrentServer } = useAuthStoreActions();
|
||||
const { collapsed } = useSidebarStore();
|
||||
const { setSideBar } = useAppStoreActions();
|
||||
const { privateMode } = useAppStore();
|
||||
const { setPrivateMode, setSideBar } = useAppStoreActions();
|
||||
|
||||
const handleSetCurrentServer = (server: ServerListItem) => {
|
||||
navigate(AppRoute.HOME);
|
||||
|
|
@ -80,6 +83,22 @@ export const AppMenu = () => {
|
|||
setSideBar({ collapsed: false });
|
||||
};
|
||||
|
||||
const handlePrivateModeOff = () => {
|
||||
setPrivateMode(false);
|
||||
toast.info({
|
||||
message: t('form.privateMode.disabled', { postProcess: 'sentenceCase' }),
|
||||
title: t('form.privateMode.title', { postProcess: 'sentenceCase' }),
|
||||
});
|
||||
};
|
||||
|
||||
const handlePrivateModeOn = () => {
|
||||
setPrivateMode(true);
|
||||
toast.info({
|
||||
message: t('form.privateMode.enabled', { postProcess: 'sentenceCase' }),
|
||||
title: t('form.privateMode.title', { postProcess: 'sentenceCase' }),
|
||||
});
|
||||
};
|
||||
|
||||
const handleQuit = () => {
|
||||
browser?.quit();
|
||||
};
|
||||
|
|
@ -127,7 +146,21 @@ export const AppMenu = () => {
|
|||
>
|
||||
{t('page.appMenu.manageServers', { postProcess: 'sentenceCase' })}
|
||||
</DropdownMenu.Item>
|
||||
|
||||
{privateMode ? (
|
||||
<DropdownMenu.Item
|
||||
leftSection={<Icon color="error" icon="lock" />}
|
||||
onClick={handlePrivateModeOff}
|
||||
>
|
||||
{t('page.appMenu.privateModeOff', { postProcess: 'sentenceCase' })}
|
||||
</DropdownMenu.Item>
|
||||
) : (
|
||||
<DropdownMenu.Item
|
||||
leftSection={<Icon icon="lockOpen" />}
|
||||
onClick={handlePrivateModeOn}
|
||||
>
|
||||
{t('page.appMenu.privateModeOn', { postProcess: 'sentenceCase' })}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
<DropdownMenu.Divider />
|
||||
<DropdownMenu.Label>
|
||||
{t('page.appMenu.selectServer', { postProcess: 'sentenceCase' })}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue