Skip to content

Commit 75014c8

Browse files
authored
Merge pull request #937 from keriati/privateAppSupport
Improve Private App support
2 parents e2ba89c + 386e4c7 commit 75014c8

File tree

3 files changed

+70
-19
lines changed

3 files changed

+70
-19
lines changed

app/Application.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public static function single($appid)
110110
{
111111
$apps = self::apps();
112112
$app = $apps->where('appid', $appid)->first();
113+
114+
if ($app === null) {
115+
// Try in db for Private App
116+
$appModel = self::where('appid', $appid)->first();
117+
$app = json_decode($appModel->toJson());
118+
}
119+
113120
if ($app === null) {
114121
return null;
115122
}
@@ -128,6 +135,15 @@ public static function applist()
128135
$list[$app->appid] = $app->name;
129136
}
130137

138+
// Check for private apps in the db
139+
$appsListFromDB = self::all(['appid', 'name']);
140+
141+
foreach($appsListFromDB as $app) {
142+
// Already existing keys are overwritten,
143+
// only private apps should be added at the end
144+
$list[$app->appid] = $app->name;
145+
}
146+
131147
return $list;
132148
}
133149
}

app/Console/Commands/RegisterApp.php

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Application;
66
use App\SupportedApps;
77
use Illuminate\Console\Command;
8+
use Illuminate\Support\Facades\Storage;
89

910
class RegisterApp extends Command
1011
{
@@ -13,7 +14,7 @@ class RegisterApp extends Command
1314
*
1415
* @var string
1516
*/
16-
protected $signature = 'register:app {folder}';
17+
protected $signature = 'register:app {folder} {--remove}';
1718

1819
/**
1920
* The console command description.
@@ -49,29 +50,47 @@ public function handle()
4950
$this->addApp($folder);
5051
}
5152
} else {
52-
$this->addApp($folder);
53+
$this->addApp($folder, $this->option('remove'));
5354
}
5455
}
5556

56-
public function addApp($folder)
57+
public function addApp($folder, $remove = false)
5758
{
5859
$json = app_path('SupportedApps/'.$folder.'/app.json');
59-
if (file_exists($json)) {
60-
$app = json_decode(file_get_contents($json));
61-
if (isset($app->appid)) {
62-
$exists = Application::find($app->appid);
63-
if ($exists) {
64-
$this->error('Application already registered - '.$exists->name.' - '.$exists->appid);
65-
} else {
66-
// Doesn't exist so add it
67-
SupportedApps::saveApp($app, new Application);
68-
$this->info('Application Added - '.$app->name.' - '.$app->appid);
69-
}
70-
} else {
71-
$this->error('No App ID for - '.$folder);
60+
61+
if (!file_exists($json)) {
62+
$this->error('Could not find ' . $json);
63+
return;
64+
}
65+
66+
$app = json_decode(file_get_contents($json));
67+
68+
if (!isset($app->appid)) {
69+
$this->error('No App ID for - ' . $folder);
70+
return;
71+
}
72+
73+
$exists = Application::find($app->appid);
74+
75+
if ($exists) {
76+
if ($remove) {
77+
$exists->delete();
78+
$this->info('Application Removed - ' . $app->name . ' - ' . $app->appid);
79+
return;
7280
}
73-
} else {
74-
$this->error('Could not find '.$json);
81+
$this->error('Application already registered - ' . $exists->name . ' - ' . $exists->appid);
82+
return;
7583
}
84+
85+
// Doesn't exist so add it
86+
SupportedApps::saveApp($app, new Application);
87+
$this->saveIcon($folder, $app->icon);
88+
$this->info('Application Added - ' . $app->name . ' - ' . $app->appid);
89+
}
90+
91+
private function saveIcon($appFolder, $icon) {
92+
$iconPath = app_path('SupportedApps/' . $appFolder . '/' . $icon);
93+
$contents = file_get_contents($iconPath);
94+
Storage::disk('public')->put('icons/'.$icon, $contents);
7695
}
7796
}

app/Http/Controllers/ItemController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Illuminate\Support\Facades\Log;
1818
use Illuminate\Support\Facades\Route;
1919
use Illuminate\Support\Facades\Storage;
20+
use Illuminate\Support\Facades\URL;
2021

2122
class ItemController extends Controller
2223
{
@@ -208,6 +209,11 @@ public function storelogic($request, $id = null)
208209
$icon .= '.'.$path_parts['extension'];
209210
}
210211
$path = 'icons/'.$icon;
212+
213+
// Private apps could have here duplicated icons folder
214+
if (strpos($path, 'icons/icons/') !== false) {
215+
$path = str_replace('icons/icons/','icons/',$path);
216+
}
211217
Storage::disk('public')->put($path, $contents);
212218
$request->merge([
213219
'icon' => $path,
@@ -376,7 +382,17 @@ public function appload(Request $request)
376382
}
377383

378384
$output['colour'] = ($app->tile_background == 'light') ? '#fafbfc' : '#161b1f';
379-
$output['iconview'] = config('app.appsource').'icons/'.$app->icon;
385+
386+
if(strpos($app->icon, '://') !== false) {
387+
$output['iconview'] = $app->icon;
388+
} elseif(strpos($app->icon, 'icons/') !== false) {
389+
// Private apps have the icon locally
390+
$output['iconview'] = URL::to('/').'/storage/'.$app->icon;
391+
$output['icon'] = str_replace('icons/', '', $output['icon']);
392+
} else {
393+
$output['iconview'] = config('app.appsource').'icons/'.$app->icon;
394+
}
395+
380396

381397
return json_encode($output);
382398
}

0 commit comments

Comments
 (0)