From 3aa385e8b02c21123b2e5ab640ddb2af7e5b39dd Mon Sep 17 00:00:00 2001 From: Pete Bishop Date: Tue, 25 Mar 2025 14:54:25 +0000 Subject: [PATCH 1/3] Add Environment Class with OS Helpers --- src/Support/Environment.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Support/Environment.php diff --git a/src/Support/Environment.php b/src/Support/Environment.php new file mode 100644 index 00000000..70f20367 --- /dev/null +++ b/src/Support/Environment.php @@ -0,0 +1,31 @@ + Date: Tue, 25 Mar 2025 14:55:51 +0000 Subject: [PATCH 2/3] Abstract all usages of PHP_OS_FAMILY to Environment class --- src/Commands/DebugCommand.php | 7 ++++--- src/System.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Commands/DebugCommand.php b/src/Commands/DebugCommand.php index 3900d3c7..d69ee160 100644 --- a/src/Commands/DebugCommand.php +++ b/src/Commands/DebugCommand.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Process; +use Native\Laravel\Support\Environment; use function Laravel\Prompts\error; use function Laravel\Prompts\info; use function Laravel\Prompts\intro; @@ -53,7 +54,7 @@ private function processEnvironment(): static { $locationCommand = 'which'; - if (PHP_OS_FAMILY === 'Windows') { + if (Environment::isWindows()) { $locationCommand = 'where'; } @@ -154,9 +155,9 @@ private function outputToClipboard(): void $json = json_encode($this->debugInfo->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); // Copy json to clipboard - if (PHP_OS_FAMILY === 'Windows') { + if (Environment::isWindows()) { Process::run('echo '.escapeshellarg($json).' | clip'); - } elseif (PHP_OS_FAMILY === 'Linux') { + } elseif (Environment::isLinux()) { Process::run('echo '.escapeshellarg($json).' | xclip -selection clipboard'); } else { Process::run('echo '.escapeshellarg($json).' | pbcopy'); diff --git a/src/System.php b/src/System.php index b6c7e075..60221cd9 100644 --- a/src/System.php +++ b/src/System.php @@ -4,6 +4,7 @@ use Native\Laravel\Client\Client; use Native\Laravel\DataObjects\Printer; +use Native\Laravel\Support\Environment; use Native\Laravel\Support\Timezones; class System @@ -79,7 +80,7 @@ public function timezone(): string { $timezones = new Timezones; - if (PHP_OS_FAMILY === 'Windows') { + if (Environment::isWindows()) { $timezone = $timezones->translateFromWindowsString(exec('tzutil /g')); } else { $timezone = $timezones->translateFromAbbreviatedString(exec('date +%Z')); From 0806631da18a2311c16fa8f92519007faf385746 Mon Sep 17 00:00:00 2001 From: PeteBishwhip <9081809+PeteBishwhip@users.noreply.github.com> Date: Tue, 25 Mar 2025 14:57:29 +0000 Subject: [PATCH 3/3] Fix styling --- src/Alert.php | 14 +++++++------- src/Commands/DebugCommand.php | 2 +- src/Events/EventWatcher.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Alert.php b/src/Alert.php index 4ddcb8f5..d00e7eff 100644 --- a/src/Alert.php +++ b/src/Alert.php @@ -2,23 +2,23 @@ namespace Native\Laravel; -use Illuminate\Support\Traits\Conditionable; -use Illuminate\Support\Traits\Macroable; use Native\Laravel\Client\Client; -use Native\Laravel\Facades\Window; class Alert { protected ?string $type; + protected ?string $title; + protected ?string $detail; + protected ?array $buttons; + protected ?int $defaultId; + protected ?int $cancelId; - final public function __construct(protected Client $client) - { - } + final public function __construct(protected Client $client) {} public static function new() { @@ -76,7 +76,7 @@ public function show(string $message): int 'detail' => $this->detail, 'buttons' => $this->buttons, 'defaultId' => $this->defaultId, - 'cancelId' => $this->cancelId + 'cancelId' => $this->cancelId, ]); return (int) $response->json('result'); diff --git a/src/Commands/DebugCommand.php b/src/Commands/DebugCommand.php index d69ee160..ad79c3b6 100644 --- a/src/Commands/DebugCommand.php +++ b/src/Commands/DebugCommand.php @@ -8,8 +8,8 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Process; - use Native\Laravel\Support\Environment; + use function Laravel\Prompts\error; use function Laravel\Prompts\info; use function Laravel\Prompts\intro; diff --git a/src/Events/EventWatcher.php b/src/Events/EventWatcher.php index 8163e1a6..6df7e248 100644 --- a/src/Events/EventWatcher.php +++ b/src/Events/EventWatcher.php @@ -14,7 +14,7 @@ public function register(): void Event::listen('*', function (string $eventName, array $data) { $event = $data[0] ?? (object) null; - if(! is_object($event)) { + if (! is_object($event)) { return; }