From 533af2dc49c8387fb3a01abd97f7ca6397d104ce Mon Sep 17 00:00:00 2001 From: Attila Kerekes Date: Thu, 27 Oct 2022 21:57:23 +0000 Subject: [PATCH 1/4] feat: support the listing of private apps --- app/Application.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Application.php b/app/Application.php index 65288106..f3465957 100644 --- a/app/Application.php +++ b/app/Application.php @@ -128,6 +128,15 @@ class Application extends Model $list[$app->appid] = $app->name; } + // Check for private apps in the db + $appsListFromDB = self::all(['appid', 'name']); + + foreach($appsListFromDB as $app) { + // Already existing keys are overwritten, + // only private apps should be added at the end + $list[$app->appid] = $app->name; + } + return $list; } } From 6907695c5d10c13792c8bed2c07f14420525ec6c Mon Sep 17 00:00:00 2001 From: Attila Kerekes Date: Fri, 28 Oct 2022 09:55:16 +0000 Subject: [PATCH 2/4] feat: support the listing of private apps --- app/Application.php | 7 +++++++ app/Http/Controllers/ItemController.php | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Application.php b/app/Application.php index f3465957..8f90355b 100644 --- a/app/Application.php +++ b/app/Application.php @@ -110,6 +110,13 @@ class Application extends Model { $apps = self::apps(); $app = $apps->where('appid', $appid)->first(); + + if ($app === null) { + // Try in db for Private App + $appModel = self::where('appid', $appid)->first(); + $app = json_decode($appModel->toJson()); + } + if ($app === null) { return null; } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 1936f3ed..e30b01ce 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -17,6 +17,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\URL; class ItemController extends Controller { @@ -376,7 +377,13 @@ class ItemController extends Controller } $output['colour'] = ($app->tile_background == 'light') ? '#fafbfc' : '#161b1f'; - $output['iconview'] = config('app.appsource').'icons/'.$app->icon; + if(strpos($app->icon, 'icons/') !== false) { + // Private apps have the icon locally + $output['iconview'] = URL::to('/').'/storage/'.$app->icon; + } else { + $output['iconview'] = config('app.appsource').'icons/'.$app->icon; + } + return json_encode($output); } From fe0109494e18deef592646bf5c3332ad30bc261c Mon Sep 17 00:00:00 2001 From: Attila Kerekes Date: Fri, 28 Oct 2022 13:21:25 +0000 Subject: [PATCH 3/4] feat: support the listing of private apps --- app/Console/Commands/RegisterApp.php | 8 ++++++++ app/Http/Controllers/ItemController.php | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/RegisterApp.php b/app/Console/Commands/RegisterApp.php index aea317c0..10c7a4ea 100644 --- a/app/Console/Commands/RegisterApp.php +++ b/app/Console/Commands/RegisterApp.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Application; use App\SupportedApps; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Storage; class RegisterApp extends Command { @@ -65,6 +66,7 @@ class RegisterApp extends Command } else { // Doesn't exist so add it SupportedApps::saveApp($app, new Application); + $this->saveIcon($folder, $app->icon); $this->info('Application Added - '.$app->name.' - '.$app->appid); } } else { @@ -74,4 +76,10 @@ class RegisterApp extends Command $this->error('Could not find '.$json); } } + + private function saveIcon($appFolder, $icon) { + $iconPath = app_path('SupportedApps/' . $appFolder . '/' . $icon); + $contents = file_get_contents($iconPath); + Storage::disk('public')->put('icons/'.$icon, $contents); + } } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index e30b01ce..9935f526 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -209,6 +209,11 @@ class ItemController extends Controller $icon .= '.'.$path_parts['extension']; } $path = 'icons/'.$icon; + + // Private apps could have here duplicated icons folder + if (strpos($path, 'icons/icons/') !== false) { + $path = str_replace('icons/icons/','icons/',$path); + } Storage::disk('public')->put($path, $contents); $request->merge([ 'icon' => $path, @@ -377,9 +382,13 @@ class ItemController extends Controller } $output['colour'] = ($app->tile_background == 'light') ? '#fafbfc' : '#161b1f'; - if(strpos($app->icon, 'icons/') !== false) { + + if(strpos($app->icon, '://') !== false) { + $output['iconview'] = $app->icon; + } elseif(strpos($app->icon, 'icons/') !== false) { // Private apps have the icon locally $output['iconview'] = URL::to('/').'/storage/'.$app->icon; + $output['icon'] = str_replace('icons/', '', $output['icon']); } else { $output['iconview'] = config('app.appsource').'icons/'.$app->icon; } From 386e4c788b908fcad3c08729a51ae613d87305a9 Mon Sep 17 00:00:00 2001 From: Attila Kerekes Date: Fri, 28 Oct 2022 14:03:11 +0000 Subject: [PATCH 4/4] feat: add remove option to registerapp --- app/Console/Commands/RegisterApp.php | 51 +++++++++++++++++----------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/app/Console/Commands/RegisterApp.php b/app/Console/Commands/RegisterApp.php index 10c7a4ea..e09ef16b 100644 --- a/app/Console/Commands/RegisterApp.php +++ b/app/Console/Commands/RegisterApp.php @@ -14,7 +14,7 @@ class RegisterApp extends Command * * @var string */ - protected $signature = 'register:app {folder}'; + protected $signature = 'register:app {folder} {--remove}'; /** * The console command description. @@ -50,31 +50,42 @@ class RegisterApp extends Command $this->addApp($folder); } } else { - $this->addApp($folder); + $this->addApp($folder, $this->option('remove')); } } - public function addApp($folder) + public function addApp($folder, $remove = false) { $json = app_path('SupportedApps/'.$folder.'/app.json'); - if (file_exists($json)) { - $app = json_decode(file_get_contents($json)); - if (isset($app->appid)) { - $exists = Application::find($app->appid); - if ($exists) { - $this->error('Application already registered - '.$exists->name.' - '.$exists->appid); - } else { - // Doesn't exist so add it - SupportedApps::saveApp($app, new Application); - $this->saveIcon($folder, $app->icon); - $this->info('Application Added - '.$app->name.' - '.$app->appid); - } - } else { - $this->error('No App ID for - '.$folder); - } - } else { - $this->error('Could not find '.$json); + + if (!file_exists($json)) { + $this->error('Could not find ' . $json); + return; } + + $app = json_decode(file_get_contents($json)); + + if (!isset($app->appid)) { + $this->error('No App ID for - ' . $folder); + return; + } + + $exists = Application::find($app->appid); + + if ($exists) { + if ($remove) { + $exists->delete(); + $this->info('Application Removed - ' . $app->name . ' - ' . $app->appid); + return; + } + $this->error('Application already registered - ' . $exists->name . ' - ' . $exists->appid); + return; + } + + // Doesn't exist so add it + SupportedApps::saveApp($app, new Application); + $this->saveIcon($folder, $app->icon); + $this->info('Application Added - ' . $app->name . ' - ' . $app->appid); } private function saveIcon($appFolder, $icon) {