From 1eeb718a884af3a7edb9f84639193ac85ea49d39 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 24 Dec 2023 00:24:46 +0100 Subject: [PATCH] Add initial-state --- lib/AppInfo/Application.php | 26 ++++++-------------------- package-lock.json | 1 + package.json | 1 + src/App.vue | 12 +++++++++--- src/main.js | 2 -- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 3ab54e6..56611b7 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -10,14 +10,12 @@ use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\Server; -use OCP\Util; +use OCP\AppFramework\Services\IInitialState; class Application extends App implements IBootstrap { public const APP_ID = 'repod'; private const GPODDERSYNC_ID = 'gpoddersync'; - private const GPODDERSYNC_MIN_VERSION = '3.8.1'; public function __construct() { parent::__construct(self::APP_ID); @@ -30,6 +28,9 @@ class Application extends App implements IBootstrap /** @var IAppManager $appManager */ $appManager = $appContainer->get(IAppManager::class); + /** @var IInitialState $initialState */ + $initialState = $appContainer->get(IInitialState::class); + $gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID); if (!$gpoddersync) { try { @@ -38,24 +39,9 @@ class Application extends App implements IBootstrap } } - /** @psalm-suppress DeprecatedMethod */ - Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); + $gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID); + $initialState->provideInitialState('gpodder', $gpoddersync); } public function register(IRegistrationContext $context): void {} - - public static function extendJsConfig(array $settings): void { - /** @var IAppManager $appManager */ - $appManager = Server::get(IAppManager::class); - - if (is_array($settings['array']) && array_key_exists('oc_appconfig', $settings['array'])) { - /** @var array $appConfig */ - $appConfig = json_decode((string) $settings['array']['oc_appconfig'], true); - $appConfig['repod'] = [ - 'gpodder' => $appManager->isEnabledForUser(self::GPODDERSYNC_ID) - && version_compare($appManager->getAppVersion(self::GPODDERSYNC_ID), self::GPODDERSYNC_MIN_VERSION) >= 0, - ]; - $settings['array']['oc_appconfig'] = json_encode($appConfig); - } - } } diff --git a/package-lock.json b/package-lock.json index 5720f15..77a60c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@nextcloud/axios": "^2.4.0", "@nextcloud/dialogs": "^5.0.3", + "@nextcloud/initial-state": "^2.1.0", "@nextcloud/l10n": "^2.2.0", "@nextcloud/moment": "^1.2.2", "@nextcloud/router": "^2.2.0", diff --git a/package.json b/package.json index 0b9d6bb..feaeb91 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "@nextcloud/axios": "^2.4.0", "@nextcloud/dialogs": "^5.0.3", + "@nextcloud/initial-state": "^2.1.0", "@nextcloud/l10n": "^2.2.0", "@nextcloud/moment": "^1.2.2", "@nextcloud/router": "^2.2.0", diff --git a/src/App.vue b/src/App.vue index 0d733be..43c61ad 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,8 +1,8 @@ @@ -13,6 +13,7 @@ import Bar from './components/Player/Bar.vue' import GPodder from './views/GPodder.vue' import { NcContent } from '@nextcloud/vue' import Subscriptions from './components/Sidebar/Subscriptions.vue' +import { loadState } from '@nextcloud/initial-state' export default { name: 'App', @@ -22,5 +23,10 @@ export default { NcContent, Subscriptions, }, + computed: { + gpodder() { + return loadState('repod', 'gpodder', false) + }, + }, } diff --git a/src/main.js b/src/main.js index 214866f..c48ca10 100644 --- a/src/main.js +++ b/src/main.js @@ -13,8 +13,6 @@ const n = (...args) => translatePlural('repod', ...args) Vue.mixin({ methods: { t, n } }) -Vue.prototype.AppConfig = window.oc_appconfig - Vue.filter('stripHTML', (value) => { const div = document.createElement('div') div.innerHTML = value