“tray” prefix for disabledActions

This commit is contained in:
FTCHD
2025-01-31 16:23:45 +02:00
parent 1864b3bb6d
commit 4a65ebd61e
3 changed files with 71 additions and 43 deletions
+7 -7
View File
@@ -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',
+24 -4
View File
@@ -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<PersistedState>()(
})),
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',
+40 -32
View File
@@ -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({
>
<div className="flex flex-col gap-2">
<Checkbox
isSelected={!config?.hideTray || false}
onValueChange={(value) => {
if (value) {
setConfig((prev) => ({
...prev,
hideTray: undefined,
}))
} else {
setConfig((prev) => ({
...prev,
hideTray: true,
}))
}
}}
>
Show in tray menu
</Checkbox>
<Checkbox
isSelected={!config?.disabledActions?.includes('mount')}
isSelected={!config?.disabledActions?.includes('tray')}
onValueChange={(value) => {
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
</Checkbox>
<Checkbox
isSelected={
!config?.disabledActions?.includes('tray-mount')
}
onValueChange={(value) => {
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({
</Checkbox>
<Checkbox
isSelected={
!config?.disabledActions?.includes('browse')
!config?.disabledActions?.includes('tray-browse')
}
onValueChange={(value) => {
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({
</Checkbox>
<Checkbox
isSelected={
!config?.disabledActions?.includes('remove')
!config?.disabledActions?.includes('tray-remove')
}
onValueChange={(value) => {
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({
</Button>
<Button
color="primary"
isLoading={isSaving}
isDisabled={isSaving}
onPress={handleSubmit}
data-focus-visible="false"
>
{isSaving ? 'Saving...' : 'Save Changes'}
Save Changes
</Button>
</DrawerFooter>
</>