Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snowflakes/config/snowflakes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [
'enabled' => env('SNOWFLAKES_ENABLED', true),
'size' => env('SNOWFLAKES_SIZE', 0.8),
'speed' => env('SNOWFLAKES_SPEED', 1),
'opacity' => env('SNOWFLAKES_OPACITY', 0.5),
Expand Down
2 changes: 2 additions & 0 deletions snowflakes/lang/en/strings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

return [
'enabled' => 'Enable Snowflakes',
'enabled_help' => 'Toggle snowflakes on or off.',
'size' => 'Size',
'size_help' => 'Size of the snowflakes.',
'speed' => 'Speed',
Expand Down
11 changes: 9 additions & 2 deletions snowflakes/src/Providers/SnowflakesPluginProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ class SnowflakesPluginProvider extends ServiceProvider
{
public function boot(): void
{
$isEnabled = config('snowflakes.enabled');

// Check user customization if the user is authenticated
if ($isEnabled && auth()->check()) {
$isEnabled = user()?->getCustomization('snowflakes_enabled') ?? true;
}

FilamentView::registerRenderHook(
PanelsRenderHook::PAGE_START,
fn () => Blade::render(<<<'HTML'
fn () => $isEnabled ? Blade::render(<<<'HTML'
<script>
window.SnowflakeConfig = {
size: {{ $size }},
Expand All @@ -26,7 +33,7 @@ public function boot(): void
};
</script>
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/snowflake@master/snowflake.min.js"></script>
HTML, config('snowflakes'))
HTML, config('snowflakes')) : ''
);
}
}
20 changes: 19 additions & 1 deletion snowflakes/src/SnowflakesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace Boy132\Snowflakes;

use App\Contracts\Plugins\HasPluginSettings;
use App\Contracts\Plugins\HasUserCustomization;
use App\Traits\EnvironmentWriterTrait;
use Filament\Contracts\Plugin;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Slider;
use Filament\Notifications\Notification;
use Filament\Panel;
use Filament\Schemas\Components\Group;

class SnowflakesPlugin implements HasPluginSettings, Plugin
class SnowflakesPlugin implements HasPluginSettings, HasUserCustomization, Plugin
{
use EnvironmentWriterTrait;

Expand All @@ -26,6 +28,11 @@ public function boot(Panel $panel): void {}
public function getSettingsForm(): array
{
$schema = [
Checkbox::make('SNOWFLAKES_ENABLED')
->label(trans('snowflakes::strings.enabled'))
->hintIcon('tabler-question-mark')
->hintIconTooltip(trans('snowflakes::strings.enabled_help'))
->default(fn () => config('snowflakes.enabled')),
Slider::make('SNOWFLAKES_SIZE')
->label(trans('snowflakes::strings.size'))
->range(minValue: 0.5, maxValue: 4)
Expand Down Expand Up @@ -89,4 +96,15 @@ public function saveSettings(array $data): void
->success()
->send();
}

public function getCustomizationForm(): array
{
return [
Checkbox::make('snowflakes_enabled')
->label(trans('snowflakes::strings.enabled'))
->hintIcon('tabler-question-mark')
->hintIconTooltip(trans('snowflakes::strings.enabled_help'))
->default(true),
];
}
}
Loading