Skip to content

Commit e03e538

Browse files
authored
Merge pull request #50 from WINBIGFOX/fly-timer
Fly timer
2 parents e0c42fa + 4fcfaf3 commit e03e538

File tree

13 files changed

+426
-22
lines changed

13 files changed

+426
-22
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}

app/Http/Controllers/WindowController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Services\WindowService;
8+
use App\Settings\FlyTimerSettings;
89

910
class WindowController extends Controller
1011
{
@@ -27,4 +28,18 @@ public function openNewProject(bool $darkMode): void
2728
{
2829
WindowService::openHome($darkMode, 'project.create');
2930
}
31+
32+
public function openFlyTimer(FlyTimerSettings $flyTimerSettings): void
33+
{
34+
WindowService::openFlyTimer();
35+
$flyTimerSettings->showWithStart = true;
36+
$flyTimerSettings->save();
37+
}
38+
39+
public function closeFlyTimer(FlyTimerSettings $flyTimerSettings): void
40+
{
41+
WindowService::closeFlyTimer();
42+
$flyTimerSettings->showWithStart = false;
43+
$flyTimerSettings->save();
44+
}
3045
}

app/Listeners/WindowClosing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function handle(WindowClosed $event): void
2626
{
2727
if (Environment::isMac()) {
2828
$windows = Window::all();
29-
if (count($windows) === 0) {
29+
if (count($windows) === 0 || (count($windows) === 1 && $windows[0]->id === 'fly-timer')) {
3030
Dock::hide();
3131
}
3232
}

app/Listeners/WindowOpening.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct()
2323
*/
2424
public function handle(WindowShown $event): void
2525
{
26-
if (Environment::isMac()) {
26+
if (Environment::isMac() && ! $event->id === 'fly-timer') {
2727
Dock::show();
2828
}
2929
}

app/Providers/NativeAppServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Services\LocaleService;
1010
use App\Services\TrayIconService;
1111
use App\Services\WindowService;
12+
use App\Settings\FlyTimerSettings;
1213
use App\Settings\GeneralSettings;
1314
use Native\Laravel\Contracts\ProvidesPhpIni;
1415
use Native\Laravel\Enums\SystemThemesEnum;
@@ -68,6 +69,12 @@ public function boot(): void
6869

6970
if (! $settings->wizard_completed) {
7071
WindowService::openWelcome();
72+
} else {
73+
$flyTimerSettings = app(FlyTimerSettings::class);
74+
75+
if ($flyTimerSettings->showWithStart) {
76+
WindowService::openFlyTimer();
77+
}
7178
}
7279

7380
Menu::create(

app/Services/WindowService.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ public static function openUpdater(bool $darkMode): void
7575
}
7676
}
7777

78+
public static function openFlyTimer(): void
79+
{
80+
self::closeFlyTimer();
81+
Window::open('fly-timer')
82+
->webPreferences([
83+
'devTools' => false,
84+
])
85+
->height(70)
86+
->width(200)
87+
->route('fly-timer.index')
88+
->alwaysOnTop()
89+
->maximizable(false)
90+
->fullscreenable(false)
91+
->trafficLightPosition(0, -30)
92+
->resizable(false)
93+
->minimizable(false)
94+
->showDevTools(false)
95+
->hiddenInMissionControl()
96+
->skipTaskbar()
97+
->rememberState()
98+
->invisibleFrameless()
99+
->titleBarHidden()
100+
->hideMenu();
101+
}
102+
78103
public static function closeWelcome(): void
79104
{
80105
Window::close('welcome');
@@ -89,4 +114,9 @@ public static function closeUpdater(): void
89114
{
90115
Window::close('updater');
91116
}
117+
118+
public static function closeFlyTimer(): void
119+
{
120+
Window::close('fly-timer');
121+
}
92122
}

app/Settings/FlyTimerSettings.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Settings;
6+
7+
use Spatie\LaravelSettings\Settings;
8+
9+
class FlyTimerSettings extends Settings
10+
{
11+
public bool $showWithStart = false;
12+
13+
public static function group(): string
14+
{
15+
return 'fly_timer';
16+
}
17+
}

config/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
\App\Settings\GeneralSettings::class,
1313
\App\Settings\AutoUpdaterSettings::class,
1414
\App\Settings\ProjectSettings::class,
15+
\App\Settings\FlyTimerSettings::class,
1516
],
1617

1718
/*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Spatie\LaravelSettings\Migrations\SettingsMigration;
6+
7+
return new class extends SettingsMigration
8+
{
9+
public function up(): void
10+
{
11+
$this->migrator->add('fly_timer.showWithStart', false);
12+
}
13+
14+
public function down(): void
15+
{
16+
$this->migrator->deleteIfExists('fly_timer.showWithStart');
17+
}
18+
};

0 commit comments

Comments
 (0)