59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Services\SyncService;
|
|
use Filament\Notifications\Notification;
|
|
use Livewire\Component;
|
|
|
|
class SettingsDropdown extends Component
|
|
{
|
|
public bool $syncSuccess = false;
|
|
public bool $syncFailed = false;
|
|
public array $reportLines = [];
|
|
|
|
public bool $peerConnected = false;
|
|
public ?string $peerPath = null;
|
|
public bool $peerChecked = false;
|
|
|
|
public function checkPeerStatus(): void
|
|
{
|
|
$result = SyncService::fromConfig()->ping();
|
|
|
|
$this->peerConnected = $result['connected'];
|
|
$this->peerPath = $result['path'];
|
|
$this->peerChecked = true;
|
|
}
|
|
public function runSync(): void
|
|
{
|
|
$service = SyncService::fromConfig();
|
|
|
|
if (! $service->isConfigured()) {
|
|
$this->syncFailed = true;
|
|
$this->reportLines = [__('navigation.sync.error_not_configured')];
|
|
$this->dispatch('sync-finished', success: false);
|
|
|
|
return;
|
|
}
|
|
|
|
$result = $service->sync();
|
|
|
|
$this->reportLines = $result['report'] ?? [];
|
|
|
|
if ($result['success']) {
|
|
$this->syncSuccess = true;
|
|
$this->dispatch('sync-finished', success: true);
|
|
} else {
|
|
$this->syncFailed = true;
|
|
$this->dispatch('sync-finished', success: false);
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.settings-dropdown');
|
|
}
|
|
}
|