2023-06-22 20:10:30 +02:00
|
|
|
<?php
|
2023-06-23 09:44:48 +02:00
|
|
|
|
2023-06-22 20:10:30 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\RePod\AppInfo;
|
|
|
|
|
2023-07-04 17:43:58 +02:00
|
|
|
use OCP\App\AppPathNotFoundException;
|
2023-07-03 16:17:00 +02:00
|
|
|
use OCP\App\IAppManager;
|
2023-06-22 20:10:30 +02:00
|
|
|
use OCP\AppFramework\App;
|
2023-07-03 16:17:00 +02:00
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
2023-07-04 17:43:58 +02:00
|
|
|
use OCP\Server;
|
|
|
|
use OCP\Util;
|
2023-06-22 20:10:30 +02:00
|
|
|
|
2023-07-03 16:17:00 +02:00
|
|
|
class Application extends App implements IBootstrap
|
2023-06-24 18:37:25 +02:00
|
|
|
{
|
2023-06-22 20:10:30 +02:00
|
|
|
public const APP_ID = 'repod';
|
2023-07-03 16:17:00 +02:00
|
|
|
private const GPODDERSYNC_ID = 'gpoddersync';
|
2023-08-30 09:33:15 +02:00
|
|
|
private const GPODDERSYNC_MIN_VERSION = '3.8.1';
|
2023-06-22 20:10:30 +02:00
|
|
|
|
2023-12-23 17:25:20 +01:00
|
|
|
public function __construct() {
|
2023-06-22 20:10:30 +02:00
|
|
|
parent::__construct(self::APP_ID);
|
|
|
|
}
|
2023-07-03 16:17:00 +02:00
|
|
|
|
2023-12-23 17:25:20 +01:00
|
|
|
public function boot(IBootContext $context): void {
|
2023-07-03 16:17:00 +02:00
|
|
|
/** @psalm-suppress DeprecatedInterface */
|
|
|
|
$appContainer = $context->getAppContainer();
|
2023-07-27 23:01:24 +02:00
|
|
|
|
2023-07-03 16:17:00 +02:00
|
|
|
/** @var IAppManager $appManager */
|
|
|
|
$appManager = $appContainer->get(IAppManager::class);
|
|
|
|
|
2023-07-04 17:43:58 +02:00
|
|
|
$gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID);
|
2023-07-03 16:17:00 +02:00
|
|
|
if (!$gpoddersync) {
|
2023-07-04 17:43:58 +02:00
|
|
|
try {
|
|
|
|
$appManager->enableApp(self::GPODDERSYNC_ID);
|
|
|
|
} catch (AppPathNotFoundException $e) {
|
|
|
|
}
|
2023-07-03 16:17:00 +02:00
|
|
|
}
|
2023-07-04 17:43:58 +02:00
|
|
|
|
|
|
|
/** @psalm-suppress DeprecatedMethod */
|
|
|
|
Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
|
2023-07-03 16:17:00 +02:00
|
|
|
}
|
|
|
|
|
2023-12-23 17:25:20 +01:00
|
|
|
public function register(IRegistrationContext $context): void {}
|
2023-07-04 17:43:58 +02:00
|
|
|
|
2023-12-23 17:25:20 +01:00
|
|
|
public static function extendJsConfig(array $settings): void {
|
2023-07-04 17:43:58 +02:00
|
|
|
/** @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'] = [
|
2023-08-30 09:33:15 +02:00
|
|
|
'gpodder' => $appManager->isEnabledForUser(self::GPODDERSYNC_ID)
|
|
|
|
&& version_compare($appManager->getAppVersion(self::GPODDERSYNC_ID), self::GPODDERSYNC_MIN_VERSION) >= 0,
|
2023-07-04 17:43:58 +02:00
|
|
|
];
|
|
|
|
$settings['array']['oc_appconfig'] = json_encode($appConfig);
|
|
|
|
}
|
|
|
|
}
|
2023-06-22 20:10:30 +02:00
|
|
|
}
|