Browse Source

feat: support the listing of private apps

Attila Kerekes 2 years ago
parent
commit
fe0109494e
2 changed files with 18 additions and 1 deletions
  1. 8 0
      app/Console/Commands/RegisterApp.php
  2. 10 1
      app/Http/Controllers/ItemController.php

+ 8 - 0
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);
+    }
 }

+ 10 - 1
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;
         }