From 48fef0d9938a62940eccf347d65837230792bece Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Tue, 4 Jul 2023 17:43:58 +0200 Subject: [PATCH] Begin to work on no gpodder enabled --- lib/AppInfo/Application.php | 30 +++++++-- lib/Controller/TopController.php | 6 +- src/App.vue | 103 ++--------------------------- src/main.js | 2 + src/views/GPodder.vue | 9 +++ src/views/Index.vue | 108 +++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 104 deletions(-) create mode 100644 src/views/GPodder.vue create mode 100644 src/views/Index.vue diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 281ce06..15e5e93 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -4,12 +4,14 @@ declare(strict_types=1); namespace OCA\RePod\AppInfo; +use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\IUserSession; +use OCP\Server; +use OCP\Util; class Application extends App implements IBootstrap { @@ -25,15 +27,33 @@ class Application extends App implements IBootstrap $appContainer = $context->getAppContainer(); /** @var IAppManager $appManager */ $appManager = $appContainer->get(IAppManager::class); - /** @var IUserSession $userSession */ - $userSession = $appContainer->get(IUserSession::class); - $gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID, $userSession->getUser()); + $gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID); if (!$gpoddersync) { - $appManager->enableApp(self::GPODDERSYNC_ID); + try { + $appManager->enableApp(self::GPODDERSYNC_ID); + } catch (AppPathNotFoundException $e) { + } } + + /** @psalm-suppress DeprecatedMethod */ + Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); } 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) + ]; + $settings['array']['oc_appconfig'] = json_encode($appConfig); + } + } } diff --git a/lib/Controller/TopController.php b/lib/Controller/TopController.php index e5dc542..a98229e 100644 --- a/lib/Controller/TopController.php +++ b/lib/Controller/TopController.php @@ -19,7 +19,7 @@ class TopController extends Controller public function __construct( IRequest $request, private IClientService $clientService, - private IFactory $l10nFactory, + private IFactory $l10n, private IUserSession $userSession ) { parent::__construct(Application::APP_ID, $request); @@ -35,7 +35,7 @@ class TopController extends Controller } try { - $lang = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); + $lang = $this->l10n->getUserLanguage($this->userSession->getUser()); $lang = explode('_', $lang); $lang = count($lang) > 1 ? $lang[1] : $lang[0]; $lang = $lang === 'en' ? 'us' : $lang; @@ -43,7 +43,7 @@ class TopController extends Controller $client = $this->clientService->newClient(); $response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json"); /** @var array $json */ - $json = json_decode((string) $response->getBody(), flags: JSON_THROW_ON_ERROR); + $json = json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR); return new JSONResponse($json, $response->getStatusCode()); } catch (Exception $e) { return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); diff --git a/src/App.vue b/src/App.vue index cef0423..34f1ca1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,111 +1,22 @@ diff --git a/src/main.js b/src/main.js index 6dbf0da..f9d2b10 100644 --- a/src/main.js +++ b/src/main.js @@ -15,6 +15,8 @@ Vue.mixin({ methods: { t, n } }) Vue.use(Plugin) Vue.prototype.OC = window.OC Vue.prototype.OCA = window.OCA +Vue.prototype.OCP = window.OCP +Vue.prototype.AppConfig = window.oc_appconfig export default new Vue({ el: '#content', diff --git a/src/views/GPodder.vue b/src/views/GPodder.vue new file mode 100644 index 0000000..6b75cff --- /dev/null +++ b/src/views/GPodder.vue @@ -0,0 +1,9 @@ + + + diff --git a/src/views/Index.vue b/src/views/Index.vue new file mode 100644 index 0000000..1981715 --- /dev/null +++ b/src/views/Index.vue @@ -0,0 +1,108 @@ + + +