Add initial-state
This commit is contained in:
parent
14cd1e9cbb
commit
1eeb718a88
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
package-lock.json
generated
1
package-lock.json
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
12
src/App.vue
12
src/App.vue
@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<NcContent app-name="repod">
|
||||
<GPodder v-if="!AppConfig.repod.gpodder" />
|
||||
<Subscriptions v-if="AppConfig.repod.gpodder" />
|
||||
<router-view v-if="AppConfig.repod.gpodder" :key="$route.path" />
|
||||
<GPodder v-if="!gpodder" />
|
||||
<Subscriptions v-if="gpodder" />
|
||||
<router-view v-if="gpodder" :key="$route.path" />
|
||||
<Bar />
|
||||
</NcContent>
|
||||
</template>
|
||||
@ -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)
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user