Add initial-state
repod / xml (push) Successful in 28s Details
repod / php (push) Successful in 1m23s Details
repod / nodejs (push) Successful in 2m35s Details

This commit is contained in:
Michel Roux 2023-12-24 00:24:46 +01:00
parent 14cd1e9cbb
commit 1eeb718a88
5 changed files with 17 additions and 25 deletions

View File

@ -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
View File

@ -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",

View File

@ -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",

View File

@ -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>

View File

@ -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