info('Nitro update check...'); if ($this->option('diagnose')) { return $this->diagnose($nitroService); } if ($this->option('repair')) { return $this->repair($alertService, $nitroService); } $isForced = $this->option('force'); $buildOnly = $this->option('build-only'); $full = $this->option('full'); if ($buildOnly) { return $this->buildOnly($alertService, $nitroService); } if (! $isForced && ! $this->isScheduledTime()) { $this->line('Niet de geplande tijd, overslaan.'); return Command::SUCCESS; } $repo = setting('nitro_github_url', 'duckietm/Nitro-V3 (default)'); $this->info("GitHub: {$repo}"); if ($full) { return $this->fullReinstall($alertService, $nitroService); } $status = $nitroService->getStatus(); $this->info('Client: ' . ($status['client_installed'] ? '✅' : '❌')); $this->info('Renderer: ' . ($status['renderer_installed'] ? '✅' : '❌')); $this->info('Build: ' . ($status['build_exists'] ? '✅' : '❌')); $this->info('Deployed: ' . ($status['deployed'] ? '✅' : '❌')); if (! $status['client_installed'] || ! $status['renderer_installed']) { $this->warn('Nitro niet volledig geïnstalleerd. Voer --full uit voor volledige installatie.'); if ($this->confirm('Wil je nu volledig installeren?')) { return $this->fullReinstall($alertService, $nitroService); } return Command::SUCCESS; } $this->line('✅ Nitro client is up-to-date.'); if ($isForced) { $this->warn('Force update aangevraagd...'); return $this->fullReinstall($alertService, $nitroService); } Cache::put(self::CACHE_KEY_LAST_UPDATE, now()->toIso8601String()); return Command::SUCCESS; } private function diagnose(NitroUpdateService $nitroService): int { $this->info('🔍 Nitro diagnose...'); $diagnosis = $nitroService->diagnose(); $this->newLine(); $this->info('=== Controle Resultaten ==='); $checks = $diagnosis['checks'] ?? []; foreach ($checks as $key => $value) { if (is_bool($value)) { $this->line(($value ? '✅' : '❌') . ' ' . $key); } elseif (is_array($value)) { $this->line($key . ': ' . count($value) . ' items'); } else { $this->line($key . ': ' . $value); } } if (! empty($diagnosis['issues'])) { $this->newLine(); $this->error('=== Problemen ==='); foreach ($diagnosis['issues'] as $issue) { $this->line('❌ ' . $issue); } } if (! empty($diagnosis['recommendations'])) { $this->newLine(); $this->info('=== Aanbevelingen ==='); foreach ($diagnosis['recommendations'] as $rec) { $this->line('💡 ' . $rec); } } return Command::SUCCESS; } private function repair(AlertService $alertService, NitroUpdateService $nitroService): int { $this->warn('🔧 Nitro repair modus gestart...'); $this->info('Dit zal de Nitro installatie controleren en repareren.'); try { $repairResult = $nitroService->repair(); if ($repairResult['success']) { $this->info('✅ Repair succesvol!'); foreach ($repairResult['actions'] ?? [] as $action) { $this->line(' - ' . $action); } $alertService->send( AlertType::EMULATOR_UPDATE, 'Nitro client gerepareerd', ['actions' => $repairResult['actions'] ?? []], AlertChannel::DISCORD, ); return Command::SUCCESS; } $this->error('❌ Repair mislukt: ' . ($repairResult['error'] ?? 'Onbekende fout')); if (! empty($repairResult['actions'])) { $this->line('Uitgevoerde acties:'); foreach ($repairResult['actions'] as $action) { $this->line(' - ' . $action); } } if (! empty($repairResult['errors'])) { $this->line('Fouten:'); foreach ($repairResult['errors'] as $error) { $this->line(' ❌ ' . $error); } } $alertService->send( AlertType::EMULATOR_ERROR, 'Nitro repair mislukt: ' . ($repairResult['error'] ?? 'Onbekende fout'), [], AlertChannel::DISCORD, ); return Command::FAILURE; } catch (\Exception $e) { $this->error('❌ Repair exception: ' . $e->getMessage()); return Command::FAILURE; } } private function buildOnly(AlertService $alertService, NitroUpdateService $nitroService): int { $this->info('Build en deploy uitvoeren...'); $buildResult = $nitroService->buildClient(); if (! $buildResult['success']) { $this->error('Build mislukt: ' . ($buildResult['error'] ?? 'Onbekend')); return Command::FAILURE; } $nitroService->deployClient(); $nitroService->generateConfigs(); $this->info('Client succesvol gedeployed!'); $alertService->send( AlertType::EMULATOR_UPDATE, 'Nitro client opnieuw gedeployed', [], AlertChannel::DISCORD, ); return Command::SUCCESS; } private function fullReinstall(AlertService $alertService, NitroUpdateService $nitroService): int { $this->warn('Volledige reinstall wordt uitgevoerd...'); try { $result = $nitroService->updateNitro(); if ($result['success']) { $this->info('Nitro succesvol opnieuw geïnstalleerd!'); $alertService->send( AlertType::EMULATOR_UPDATE, 'Nitro client succesvol geüpdatet en gedeployed', [], AlertChannel::DISCORD, ); return Command::SUCCESS; } $this->error('Reinstall mislukt: ' . ($result['error'] ?? 'Onbekende fout')); $alertService->send( AlertType::CRITICAL_ERROR, 'Nitro Update Mislukt: ' . ($result['error'] ?? 'Onbekende fout'), [], AlertChannel::DISCORD, ); return Command::FAILURE; } catch (\Exception $e) { $this->error('Reinstall exception: ' . $e->getMessage()); return Command::FAILURE; } } private function isScheduledTime(): bool { $scheduleTime = setting('nitro_auto_update_schedule', '03:00'); $scheduleDays = setting('nitro_auto_update_days', '0,6'); $enabled = setting('nitro_auto_update_enabled', false); if (! $enabled) { return false; } $now = now(); $currentTime = $now->format('H:i'); $currentDay = (int) $now->dayOfWeek; $allowedDays = array_map(intval(...), explode(',', $scheduleDays)); if (! in_array($currentDay, $allowedDays)) { return false; } if ($currentTime !== $scheduleTime) { $minuteDiff = abs(strtotime($currentTime) - strtotime((string) $scheduleTime)) / 60; if ($minuteDiff > 5) { return false; } } return true; } }