66import type { MaybeRefOrGetter } from 'vue'
77import type { IAppstoreApp , IAppstoreExApp } from '../apps.d.ts'
88
9- import { mdiCheck , mdiClose , mdiDownload , mdiTrashCanOutline , mdiUpdate } from '@mdi/js'
9+ import { mdiAlertCircleCheckOutline , mdiCheck , mdiClose , mdiDownload , mdiTrashCanOutline , mdiUpdate } from '@mdi/js'
1010import { t } from '@nextcloud/l10n'
1111import { computed , toValue } from 'vue'
1212import { useAppsStore } from '../store/apps.ts'
1313import { useUpdatesStore } from '../store/updates.ts'
14- import { canDisable , canEnable , canForceEnable , canInstall , canUninstall , canUpdate } from '../utils/appStatus.ts'
14+ import { canDisable , canEnable , canInstall , canUninstall , canUpdate , needForceEnable } from '../utils/appStatus.ts'
15+
16+ type AppAction = {
17+ id : string
18+ icon : string
19+ label : ( app : IAppstoreApp | IAppstoreExApp ) => string
20+ callback : ( app : IAppstoreApp | IAppstoreExApp ) => Promise < void >
21+ variant ?: 'primary' | 'error' | 'warning'
22+ inline ?: boolean
23+ }
1524
1625const AppAction = Object . freeze ( {
1726 INSTALL : {
1827 id : 'install' ,
1928 icon : mdiDownload ,
20- variant : 'primary' ,
2129 label : ( app : IAppstoreApp | IAppstoreExApp ) => {
2230 if ( app . app_api ) {
2331 return t ( 'appstore' , 'Deploy and enable' )
2432 }
25- return t ( 'appstore' , 'Download and enable' )
33+ if ( app . needsDownload ) {
34+ return t ( 'appstore' , 'Download and enable' )
35+ }
36+ return t ( 'appstore' , 'Install and enable' )
2637 } ,
2738 async callback ( app : IAppstoreApp | IAppstoreExApp ) {
2839 const store = useAppsStore ( )
2940 await store . enableApp ( app . id )
3041 } ,
31- } as const ,
42+ } as AppAction ,
3243 ENABLE : {
3344 id : 'enable' ,
3445 icon : mdiCheck ,
@@ -38,37 +49,38 @@ const AppAction = Object.freeze({
3849 const store = useAppsStore ( )
3950 await store . enableApp ( app . id )
4051 } ,
41- } as const ,
52+ } as AppAction ,
4253 FORCE_ENABLE : {
4354 id : 'force-enable' ,
44- icon : mdiCheck ,
45- variant : 'primary' ,
55+ icon : mdiAlertCircleCheckOutline ,
56+ inline : false ,
4657 label : ( ) => t ( 'appstore' , 'Force enable' ) ,
58+ variant : 'warning' ,
4759 async callback ( app : IAppstoreApp | IAppstoreExApp ) {
4860 const store = useAppsStore ( )
4961 await store . forceEnableApp ( app . id )
5062 } ,
51- } as const ,
63+ } as AppAction ,
5264 DISABLE : {
5365 id : 'disable' ,
5466 icon : mdiClose ,
55- variant : 'tertiary' ,
5667 label : ( ) => t ( 'appstore' , 'Disable' ) ,
5768 async callback ( app : IAppstoreApp | IAppstoreExApp ) {
5869 const store = useAppsStore ( )
5970 await store . disableApp ( app . id )
6071 } ,
61- } as const ,
72+ } as AppAction ,
6273 REMOVE : {
6374 id : 'remove' ,
6475 icon : mdiTrashCanOutline ,
6576 variant : 'error' ,
77+ inline : false ,
6678 label : ( ) => t ( 'appstore' , 'Remove' ) ,
6779 async callback ( app : IAppstoreApp | IAppstoreExApp ) {
6880 const store = useAppsStore ( )
6981 await store . uninstallApp ( app . id )
7082 } ,
71- } as const ,
83+ } as AppAction ,
7284 UPDATE : {
7385 id : 'update' ,
7486 icon : mdiUpdate ,
@@ -78,7 +90,7 @@ const AppAction = Object.freeze({
7890 const store = useUpdatesStore ( )
7991 await store . updateApp ( app . id )
8092 } ,
81- } as const ,
93+ } as AppAction ,
8294} )
8395
8496/**
@@ -97,12 +109,12 @@ export function useActions(app: MaybeRefOrGetter<IAppstoreApp | IAppstoreExApp>)
97109 actions . push ( AppAction . DISABLE )
98110 }
99111
100- if ( canInstall ( toValue ( app ) ) ) {
112+ if ( needForceEnable ( toValue ( app ) ) ) {
113+ actions . push ( AppAction . FORCE_ENABLE )
114+ } else if ( canInstall ( toValue ( app ) ) ) {
101115 actions . push ( AppAction . INSTALL )
102116 } else if ( canEnable ( toValue ( app ) ) ) {
103117 actions . push ( AppAction . ENABLE )
104- } else if ( canForceEnable ( toValue ( app ) ) ) {
105- actions . push ( AppAction . FORCE_ENABLE )
106118 }
107119
108120 if ( canUninstall ( toValue ( app ) ) ) {
0 commit comments