|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Http\Controllers; |
| 6 | + |
| 7 | +use App\Http\Resources\ProjectResource; |
| 8 | +use App\Models\Project; |
| 9 | +use App\Services\TimestampService; |
| 10 | +use App\Services\TrayIconService; |
| 11 | +use App\Settings\ProjectSettings; |
| 12 | +use Illuminate\Http\RedirectResponse; |
| 13 | +use Inertia\Inertia; |
| 14 | +use Inertia\Response; |
| 15 | +use Native\Laravel\Facades\MenuBar; |
| 16 | + |
| 17 | +class FlyTimerController extends Controller |
| 18 | +{ |
| 19 | + public function index(ProjectSettings $projectSettings): Response |
| 20 | + { |
| 21 | + |
| 22 | + $currentProject = $projectSettings->currentProject; |
| 23 | + if ($currentProject) { |
| 24 | + $currentProject = Project::find($currentProject); |
| 25 | + if (! $currentProject) { |
| 26 | + $projectSettings->currentProject = null; |
| 27 | + $projectSettings->save(); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + return Inertia::render('FlyTimer/Index', [ |
| 32 | + 'workTime' => TimestampService::getWorkTime(), |
| 33 | + 'breakTime' => TimestampService::getBreakTime(), |
| 34 | + 'currentType' => TimestampService::getCurrentType(), |
| 35 | + 'currentProject' => fn () => $currentProject ? ProjectResource::make($currentProject) : null, |
| 36 | + ]); |
| 37 | + } |
| 38 | + |
| 39 | + public function storeBreak(): RedirectResponse |
| 40 | + { |
| 41 | + TimestampService::startBreak(); |
| 42 | + |
| 43 | + return redirect()->route('fly-timer.index'); |
| 44 | + } |
| 45 | + |
| 46 | + public function storeWork(ProjectSettings $projectSettings): RedirectResponse |
| 47 | + { |
| 48 | + TimestampService::startWork(); |
| 49 | + |
| 50 | + return redirect()->route('fly-timer.index'); |
| 51 | + } |
| 52 | + |
| 53 | + public function storeStop(): RedirectResponse |
| 54 | + { |
| 55 | + TimestampService::stop(); |
| 56 | + |
| 57 | + MenuBar::label(''); |
| 58 | + MenuBar::icon(TrayIconService::getIcon()); |
| 59 | + |
| 60 | + return redirect()->route('fly-timer.index'); |
| 61 | + } |
| 62 | +} |
0 commit comments