Skip to content

Commit

Permalink
Adding updates to Wave v3
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed Oct 12, 2024
1 parent a141f30 commit 6ae9fea
Show file tree
Hide file tree
Showing 34 changed files with 1,230 additions and 530 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ yarn-error.log
/packages
storage/app/livewire-tmp
resources/themes/.gitignore
/resources/plugins/*
!/resources/plugins/installed.json
/storage/app/public/livewire-tmp

# Ignore everything inside the resources/plugins folder
resources/plugins/*

# But do not ignore the resources/plugins folder itself
!resources/plugins/
126 changes: 126 additions & 0 deletions app/Filament/Pages/Plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

class Plugins extends Page
{
protected static ?string $navigationIcon = 'phosphor-plugs-duotone';

protected static string $view = 'filament.pages.plugins';

protected static ?int $navigationSort = 9;

public $plugins = [];

public function mount()
{
$this->refreshPlugins();
}

private function refreshPlugins()
{
$this->plugins = $this->getPluginsFromFolder();
}

private function getPluginsFromFolder()
{
$plugins = [];
$plugins_folder = resource_path('plugins');

if (!file_exists($plugins_folder)) {
mkdir($plugins_folder);
}

$scandirectory = scandir($plugins_folder);

foreach ($scandirectory as $folder) {
if ($folder === '.' || $folder === '..') continue;

$studlyFolderName = Str::studly($folder);
$pluginFile = $plugins_folder . '/' . $folder . '/' . $studlyFolderName . 'Plugin.php';

if (file_exists($pluginFile)) {
$pluginClass = "Wave\\Plugins\\{$studlyFolderName}\\{$studlyFolderName}Plugin";
if (class_exists($pluginClass) && method_exists($pluginClass, 'getPluginInfo')) {
$plugin = new $pluginClass(app());
$info = $plugin->getPluginInfo();
$info['folder'] = $folder;
$info['active'] = $this->isPluginActive($folder);
$plugins[$folder] = $info;
}
}
}

return $plugins;
}

private function isPluginActive($folder)
{
$installedPlugins = $this->getInstalledPlugins();
return in_array($folder, $installedPlugins);
}

private function getInstalledPlugins()
{
$path = resource_path('plugins/installed.json');
return File::exists($path) ? File::json($path) : [];
}

private function updateInstalledPlugins($plugins)
{
$json = json_encode($plugins);
file_put_contents(resource_path('plugins/installed.json'), $json);
}

public function activate($pluginFolder)
{
$installedPlugins = $this->getInstalledPlugins();
if (!in_array($pluginFolder, $installedPlugins)) {
$installedPlugins[] = $pluginFolder;
$this->updateInstalledPlugins($installedPlugins);

Notification::make()
->title('Successfully activated ' . $pluginFolder . ' plugin')
->success()
->send();
}

$this->refreshPlugins();
}

public function deactivate($pluginFolder)
{
$installedPlugins = $this->getInstalledPlugins();
$installedPlugins = array_diff($installedPlugins, [$pluginFolder]);
$this->updateInstalledPlugins($installedPlugins);

Notification::make()
->title('Successfully deactivated ' . $pluginFolder . ' plugin')
->success()
->send();

$this->refreshPlugins();
}

public function deletePlugin($pluginFolder)
{
$this->deactivate($pluginFolder);

$pluginPath = resource_path('plugins') . '/' . $pluginFolder;
if (file_exists($pluginPath)) {
File::deleteDirectory($pluginPath);
}

Notification::make()
->title('Successfully deleted ' . $pluginFolder . ' plugin')
->success()
->send();

$this->refreshPlugins();
}
}
2 changes: 2 additions & 0 deletions bootstrap/cache/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
'Illuminate\\Foundation\\Console\\EventCacheCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\EventClearCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\EventListCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Concurrency\\Console\\InvokeSerializedClosureCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\KeyGenerateCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\OptimizeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\OptimizeClearCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
Expand Down Expand Up @@ -215,6 +216,7 @@
'Illuminate\\Database\\Console\\Factories\\FactoryMakeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\InterfaceMakeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\JobMakeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\JobMiddlewareMakeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\LangPublishCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\ListenerMakeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
'Illuminate\\Foundation\\Console\\MailMakeCommand' => 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bezhansalleh/filament-google-analytics": "^2.0",
"codeat3/blade-phosphor-icons": "^2.0",
"devdojo/app": "0.11.0",
"devdojo/auth": "dev-magickExclude",
"devdojo/auth": "^1.0",
"devdojo/themes": "0.0.11",
"filament/filament": "^3.2",
"gehrisandro/tailwind-merge-laravel": "^1.2",
Expand Down
Loading

0 comments on commit 6ae9fea

Please sign in to comment.