From 4a65ebd61eadd766bd4ce508560d769566aaab0e Mon Sep 17 00:00:00 2001 From: FTCHD Date: Fri, 31 Jan 2025 16:23:45 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Ctray=E2=80=9D=20prefix=20for=20disable?= =?UTF-8?q?dActions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/menu.ts | 14 ++--- lib/store.ts | 28 ++++++++-- src/components/RemoteDefaultsDrawer.tsx | 72 ++++++++++++++----------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/lib/menu.ts b/lib/menu.ts index 90f7829..391cdd2 100644 --- a/lib/menu.ts +++ b/lib/menu.ts @@ -32,7 +32,7 @@ export async function buildMenu() { // Add remote submenus for (const remote of remotes) { const remoteConfig = persistedStoreState.remoteConfigList?.[remote] - if (remoteConfig?.hideTray) { + if (remoteConfig?.disabledActions?.includes('tray')) { continue } @@ -87,7 +87,7 @@ export async function buildMenu() { submenuItems.push(openInFinderItem) } - if (!alreadyMounted && !remoteConfig?.disabledActions?.includes('mount')) { + if (!alreadyMounted && !remoteConfig?.disabledActions?.includes('tray-mount')) { const mountMenuItem = await MenuItem.new({ id: `mount-${remote}`, text: 'Quick Mount', @@ -205,7 +205,7 @@ export async function buildMenu() { submenuItems.push(mountMenuItem) } - if (!remoteConfig?.disabledActions?.includes('browse')) { + if (!remoteConfig?.disabledActions?.includes('tray-browse')) { const browseMenuItem = await MenuItem.new({ id: `browse-${remote}`, text: 'Browse', @@ -222,7 +222,7 @@ export async function buildMenu() { submenuItems.push(browseMenuItem) } - if (!remoteConfig?.disabledActions?.includes('remove')) { + if (!remoteConfig?.disabledActions?.includes('tray-remove')) { const removeMenuItem = await MenuItem.new({ id: `remove-${remote}`, text: 'Remove', @@ -258,7 +258,7 @@ export async function buildMenu() { menuItems.push(item) }) - if (!persistedStoreState.disabledActions?.includes('mount')) { + if (!persistedStoreState.disabledActions?.includes('tray-mount')) { const mountToMenuItem = await MenuItem.new({ id: 'mount', text: 'Mount', @@ -272,7 +272,7 @@ export async function buildMenu() { menuItems.push(mountToMenuItem) } - if (!persistedStoreState.disabledActions?.includes('copy')) { + if (!persistedStoreState.disabledActions?.includes('tray-copy')) { const copyMenuItem = await MenuItem.new({ id: 'copy', text: 'Copy', @@ -286,7 +286,7 @@ export async function buildMenu() { menuItems.push(copyMenuItem) } - if (!persistedStoreState.disabledActions?.includes('sync')) { + if (!persistedStoreState.disabledActions?.includes('tray-sync')) { const syncMenuItem = await MenuItem.new({ id: 'sync', text: 'Sync', diff --git a/lib/store.ts b/lib/store.ts index bb5ceac..9491cac 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -7,9 +7,7 @@ import { type StateStorage, createJSONStorage, persist } from 'zustand/middlewar const store = new LazyStore('store.json') export interface RemoteConfig { - hideTray?: boolean - - disabledActions?: ('mount' | 'browse' | 'remove')[] + disabledActions?: ('tray' | 'tray-mount' | 'tray-browse' | 'tray-remove')[] defaultRemotePath?: string defaultMountPoint?: string @@ -46,7 +44,18 @@ interface PersistedState { setRemoteConfig: (remote: string, config: RemoteConfig) => void mergeRemoteConfig: (remote: string, config: RemoteConfig) => void - disabledActions: ('mount' | 'sync' | 'copy' | 'serve')[] + disabledActions: ('tray-mount' | 'tray-sync' | 'tray-copy' | 'tray-serve')[] + setDisabledActions: ( + actions: ('tray-mount' | 'tray-sync' | 'tray-copy' | 'tray-serve')[] + ) => void + + settingsPass: string | undefined + setSettingsPass: (pass: string | undefined) => void + + licenseKey: string | undefined + setLicenseKey: (key: string | undefined) => void + licenseValid: boolean + setLicenseValid: (valid: boolean) => void } const getStorage = (store: LazyStore): StateStorage => ({ @@ -111,6 +120,17 @@ export const usePersistedStore = create()( })), disabledActions: [], + setDisabledActions: ( + actions: ('tray-mount' | 'tray-sync' | 'tray-copy' | 'tray-serve')[] + ) => set((_) => ({ disabledActions: actions })), + + settingsPass: undefined, + setSettingsPass: (pass: string | undefined) => set((_) => ({ settingsPass: pass })), + + licenseKey: undefined, + setLicenseKey: (key: string | undefined) => set((_) => ({ licenseKey: key })), + licenseValid: false, + setLicenseValid: (valid: boolean) => set((_) => ({ licenseValid: valid })), }), { name: 'store', diff --git a/src/components/RemoteDefaultsDrawer.tsx b/src/components/RemoteDefaultsDrawer.tsx index b3c6a83..bf832c8 100644 --- a/src/components/RemoteDefaultsDrawer.tsx +++ b/src/components/RemoteDefaultsDrawer.tsx @@ -58,7 +58,7 @@ export default function RemoteDefaultsDrawer({ if (config?.disabledActions?.length === 3) { setConfig((prev) => ({ ...prev, - hideTray: true, + disabledActions: [...(prev?.disabledActions || []), 'tray'], })) } }, [config?.disabledActions?.length]) @@ -70,7 +70,7 @@ export default function RemoteDefaultsDrawer({ setConfig(remoteConfig) console.log('remoteName', remoteName) - console.log(JSON.stringify(remoteConfig, null, 2)) + // console.log(JSON.stringify(remoteConfig, null, 2)) setCopyOptionsJson(JSON.stringify(remoteConfig?.copyDefaults, null, 2) || '{}') setSyncOptionsJson(JSON.stringify(remoteConfig?.syncDefaults, null, 2) || '{}') @@ -82,7 +82,7 @@ export default function RemoteDefaultsDrawer({ const handleSubmit = useCallback(async () => { if (!config) { console.log('No config') - console.log(JSON.stringify(config, null, 2)) + // console.log(JSON.stringify(config, null, 2)) return } @@ -177,32 +177,14 @@ export default function RemoteDefaultsDrawer({ >
{ - if (value) { - setConfig((prev) => ({ - ...prev, - hideTray: undefined, - })) - } else { - setConfig((prev) => ({ - ...prev, - hideTray: true, - })) - } - }} - > - Show in tray menu - - { if (value) { setConfig((prev) => ({ ...prev, disabledActions: prev?.disabledActions?.filter( - (action) => action !== 'mount' + (action) => action !== 'tray' ), })) } else { @@ -210,7 +192,33 @@ export default function RemoteDefaultsDrawer({ ...prev, disabledActions: [ ...(prev?.disabledActions || []), - 'mount', + 'tray', + ], + })) + } + }} + > + Show in tray menu + + { + if (value) { + setConfig((prev) => ({ + ...prev, + disabledActions: + prev?.disabledActions?.filter( + (action) => action !== 'tray-mount' + ), + })) + } else { + setConfig((prev) => ({ + ...prev, + disabledActions: [ + ...(prev?.disabledActions || []), + 'tray-mount', ], })) } @@ -222,7 +230,7 @@ export default function RemoteDefaultsDrawer({ { if (value) { @@ -230,7 +238,7 @@ export default function RemoteDefaultsDrawer({ ...prev, disabledActions: prev?.disabledActions?.filter( - (action) => action !== 'browse' + (action) => action !== 'tray-browse' ), })) } else { @@ -238,7 +246,7 @@ export default function RemoteDefaultsDrawer({ ...prev, disabledActions: [ ...(prev?.disabledActions || []), - 'browse', + 'tray-browse', ], })) } @@ -250,7 +258,7 @@ export default function RemoteDefaultsDrawer({ { if (value) { @@ -258,7 +266,7 @@ export default function RemoteDefaultsDrawer({ ...prev, disabledActions: prev?.disabledActions?.filter( - (action) => action !== 'remove' + (action) => action !== 'tray-remove' ), })) } else { @@ -266,7 +274,7 @@ export default function RemoteDefaultsDrawer({ ...prev, disabledActions: [ ...(prev?.disabledActions || []), - 'remove', + 'tray-remove', ], })) } @@ -524,11 +532,11 @@ export default function RemoteDefaultsDrawer({