initial commit
This commit is contained in:
		
							
								
								
									
										9
									
								
								lib/AppConstants.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								lib/AppConstants.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace OCA\PrideFlags;
 | 
			
		||||
 | 
			
		||||
abstract class AppConstants {
 | 
			
		||||
	public const APP_ID = 'pride_flags';
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								lib/AppInfo/Application.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								lib/AppInfo/Application.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
<?php
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace OCA\PrideFlags\AppInfo;
 | 
			
		||||
 | 
			
		||||
use OCA\PrideFlags\AppConstants;
 | 
			
		||||
use OCP\Util;
 | 
			
		||||
use OCP\AppFramework\App;
 | 
			
		||||
use OCP\AppFramework\Bootstrap\IBootContext;
 | 
			
		||||
use OCP\AppFramework\Bootstrap\IBootstrap;
 | 
			
		||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
 | 
			
		||||
use OCP\IConfig;
 | 
			
		||||
 | 
			
		||||
class Application extends App implements IBootstrap {
 | 
			
		||||
	const APP_ID = AppConstants::APP_ID;
 | 
			
		||||
	public function __construct(array $urlParams = []) {
 | 
			
		||||
		parent::__construct(AppConstants::APP_ID, $urlParams);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function register(IRegistrationContext $ctx): void {
 | 
			
		||||
		$config = \OC::$server->get(IConfig::class);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function boot(IBootContext $ctx): void {
 | 
			
		||||
		Util::addStyle(AppConstants::APP_ID, 'pride');
 | 
			
		||||
		Util::addScript(AppConstants::APP_ID, 'pride');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								lib/Controller/SettingsController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								lib/Controller/SettingsController.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace OCA\PrideFlags\Controller;
 | 
			
		||||
 | 
			
		||||
use OCA\PrideFlags\Settings\AppSettings;
 | 
			
		||||
use OCP\IRequest;
 | 
			
		||||
use OCP\IConfig;
 | 
			
		||||
use OCP\Framework\Http;
 | 
			
		||||
use OCP\Framework\Http\JSONResponse;
 | 
			
		||||
 | 
			
		||||
class SettingsController {
 | 
			
		||||
	public function __construct($appName, IRequest $request, AppSettings $settings) {}
 | 
			
		||||
 | 
			
		||||
	public function get(): JSONResponse {
 | 
			
		||||
		return $this->makeJSONResponse(fn () => $this->settings->getAll());	
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function set(string $folderVariant, string $buttonVariant): JSONResponse {
 | 
			
		||||
		$this->settings->set($folderVariant, $buttonVariant);
 | 
			
		||||
		return $this->makeJSONResponse(fn () => $this->settings->getAll());	
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected function makeJSONResponse(Closure $closure): JSONResponse {
 | 
			
		||||
		try {
 | 
			
		||||
			return new JSONResponse($closure(), HTTP::STATUS_OK);
 | 
			
		||||
		} catch (Exception $e) {
 | 
			
		||||
			return new JSONResponse(['message' => $e->getMessage()], HTTP::INTERNAL_SERVER_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								lib/Settings/AppSettings.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								lib/Settings/AppSettings.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
<?
 | 
			
		||||
 | 
			
		||||
namespace OCA\PrideFlags\Settings;
 | 
			
		||||
 | 
			
		||||
use OCA\PrideFlags\AppConstants;
 | 
			
		||||
use OCP\IConfig;
 | 
			
		||||
 | 
			
		||||
class AppSettings {
 | 
			
		||||
	public const FOLDER_VARIANT = 'folderVariant';
 | 
			
		||||
	public const BUTTON_VARIANT = 'buttonVariant';
 | 
			
		||||
 | 
			
		||||
	public function __construct(private IConfig $config) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getStringSetting(string $key, string $default = ''): string {
 | 
			
		||||
		return $this->config->getAppValue(AppConstants::APP_ID, $key) ?: $default;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function setStringSetting(string $key, string $value): string {
 | 
			
		||||
		return $this->config->setAppValue(AppConstants::APP_ID, $key, $value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAll(): array {
 | 
			
		||||
		return [
 | 
			
		||||
			AppSettings::FOLDER_VARIANT => $this->getStringSetting(AppSettings::FOLDER_VARIANT, 'pride'),
 | 
			
		||||
			AppSettings::BUTTON_VARIANT => $this->getStringSetting(AppSettings::BUTTON_VARIANT, 'trans'),
 | 
			
		||||
		]
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function set($folder, $button): void {
 | 
			
		||||
		$this->setStringSetting(AppSettings::FOLDER_VARIANT, $folder);
 | 
			
		||||
		$this->setStringSetting(AppSettings::BUTTON_VARIANT, $button);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								lib/Settings/PersonalSection.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								lib/Settings/PersonalSection.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace OCA\PrideFlags\Settings;
 | 
			
		||||
 | 
			
		||||
use OCA\PrideFlags\AppConstants;
 | 
			
		||||
use OCP\IL10N;
 | 
			
		||||
use OCP\IURLGenerator;
 | 
			
		||||
use OCP\Settings\IIConSection;
 | 
			
		||||
 | 
			
		||||
class PersonalSection implements IIconSection {
 | 
			
		||||
	public function __construct(private IL10N $l10n, private IURLGenerator $urlGenerator) {}
 | 
			
		||||
 | 
			
		||||
	public function getID(): string {
 | 
			
		||||
		return AppConstants::APP_ID;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getName(): string {
 | 
			
		||||
		return 'Pride';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getPriority(): int {
 | 
			
		||||
		return 100;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getIcon(): string {
 | 
			
		||||
		return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								lib/Settings/PersonalSettings.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								lib/Settings/PersonalSettings.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace OCA\PrideFlags\Settings;
 | 
			
		||||
 | 
			
		||||
use OCA\PrideFlags\AppConstants;
 | 
			
		||||
use OCP\AppFramework\Http\TemplateResponse;
 | 
			
		||||
use OCP\Settings\ISettings;
 | 
			
		||||
use OCP\Util;
 | 
			
		||||
 | 
			
		||||
class PersonalSettings implements ISettings {
 | 
			
		||||
	public function getForm(): TemplateResponse {
 | 
			
		||||
		Util::addScript(AppConstants::APP_ID, 'pride-settings');
 | 
			
		||||
		return new TemplateResponse(AppConstants::APP_ID, 'settings', []);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getSection(): string {
 | 
			
		||||
		return AppConstants::APP_ID;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getPriority(): int {
 | 
			
		||||
		return 50;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user