diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 98c64db9..907c9b96 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -825,13 +825,7 @@ class ApiController extends Controller */ private function albumsIsEnabled(): bool { - if (!$this->appManager->isEnabledForUser('photos')) { - return false; - } - - $v = $this->appManager->getAppInfo('photos')['version']; - - return version_compare($v, '1.7.0', '>='); + return \OCA\Memories\Util::albumsIsEnabled($this->appManager); } /** @@ -839,7 +833,7 @@ class ApiController extends Controller */ private function tagsIsEnabled(): bool { - return $this->appManager->isEnabledForUser('systemtags'); + return \OCA\Memories\Util::tagsIsEnabled($this->appManager); } /** @@ -847,12 +841,6 @@ class ApiController extends Controller */ private function recognizeIsEnabled(): bool { - if (!$this->appManager->isEnabledForUser('recognize')) { - return false; - } - - $v = $this->appManager->getAppInfo('recognize')['version']; - - return version_compare($v, '3.0.0-alpha', '>='); + return \OCA\Memories\Util::recognizeIsEnabled($this->appManager); } } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 2c145e08..ab217746 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -86,8 +86,11 @@ class PageController extends Controller // Apps enabled $this->initialState->provideInitialState('systemtags', true === $this->appManager->isEnabledForUser('systemtags')); - $this->initialState->provideInitialState('recognize', true === $this->appManager->isEnabledForUser('recognize')); $this->initialState->provideInitialState('maps', true === $this->appManager->isEnabledForUser('maps')); + $this->initialState->provideInitialState('recognize', \OCA\Memories\Util::recognizeIsEnabled($this->appManager)); + $this->initialState->provideInitialState('albums', \OCA\Memories\Util::albumsIsEnabled($this->appManager)); + + // App version $this->initialState->provideInitialState('version', $this->appManager->getAppInfo('memories')['version']); $policy = new ContentSecurityPolicy(); diff --git a/lib/Util.php b/lib/Util.php index d1195011..3fa3fea4 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -26,4 +26,40 @@ class Util return $p; } + + /** + * Check if albums are enabled for this user. + */ + public static function albumsIsEnabled(&$appManager): bool + { + if (!$appManager->isEnabledForUser('photos')) { + return false; + } + + $v = $appManager->getAppInfo('photos')['version']; + + return version_compare($v, '1.7.0', '>='); + } + + /** + * Check if tags is enabled for this user. + */ + public static function tagsIsEnabled(&$appManager): bool + { + return $appManager->isEnabledForUser('systemtags'); + } + + /** + * Check if recognize is enabled for this user. + */ + public static function recognizeIsEnabled(&$appManager): bool + { + if (!$appManager->isEnabledForUser('recognize')) { + return false; + } + + $v = $appManager->getAppInfo('recognize')['version']; + + return version_compare($v, '3.0.0-alpha', '>='); + } } diff --git a/src/App.vue b/src/App.vue index f5650473..93ebfe8f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -130,7 +130,7 @@ export default class App extends Mixins(GlobalMixin, UserConfig) { } get showAlbums() { - return this.ncVersion >= 25; // todo: and photos enabled + return this.config_albumsEnabled; } get removeOuterGap() { diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index 329ce9ea..1de723a2 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -141,6 +141,7 @@ export default class SelectionHandler extends Mixins(GlobalMixin, UserConfig) { name: t('memories', 'Add to album'), icon: AlbumsIcon, callback: this.addToAlbum.bind(this), + if: (self: any) => self.config_albumsEnabled, }, { name: t('memories', 'Move to another person'), @@ -171,7 +172,7 @@ export default class SelectionHandler extends Mixins(GlobalMixin, UserConfig) { /** Get the actions list */ private getActions(): ISelectionAction[] { - return this.defaultActions.filter(a => !a.if || a.if()); + return this.defaultActions.filter(a => !a.if || a.if(this)); } /** Clear all selected photos */ diff --git a/src/mixins/UserConfig.ts b/src/mixins/UserConfig.ts index 62f2ece0..1cfb74b1 100644 --- a/src/mixins/UserConfig.ts +++ b/src/mixins/UserConfig.ts @@ -38,6 +38,7 @@ export default class UserConfig extends Vue { config_tagsEnabled = Boolean(loadState('memories', 'systemtags')); config_recognizeEnabled = Boolean(loadState('memories', 'recognize')); config_mapsEnabled = Boolean(loadState('memories', 'maps')); + config_albumsEnabled = Boolean(loadState('memories', 'albums')); config_squareThumbs = localStorage.getItem('memories_squareThumbs') === '1'; config_showFaceRect = localStorage.getItem('memories_showFaceRect') === '1'; diff --git a/src/types.ts b/src/types.ts index fdd82e53..752aa8d5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -197,5 +197,5 @@ export type ISelectionAction = { /** Action to perform */ callback: (selection: Map) => Promise; /** Condition to check for including */ - if?: () => boolean; + if?: (self?: any) => boolean; }