Skip to content

Commit 76bdf70

Browse files
committed
chore: nothing interesting
1 parent bc65d99 commit 76bdf70

File tree

3 files changed

+103
-16
lines changed

3 files changed

+103
-16
lines changed

src-tauri/src/main.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ mod clipboard_hotkey;
88
use crate::clipboard_hotkey::ClipboardHotkey;
99
use rdev::listen_non_blocking;
1010
use std::cell::UnsafeCell;
11-
use tauri::{Manager, RunEvent, WindowEvent};
11+
use tauri::{Manager, WindowEvent};
1212
use tray_item::TrayItem;
1313

1414
fn main() {
15-
let app = tauri::Builder::default()
15+
tauri::Builder::default()
1616
.setup(|app| {
1717
let app_handle = app.handle();
1818
let mut clipboard_hotkey = ClipboardHotkey::new();
@@ -37,19 +37,21 @@ fn main() {
3737

3838
Ok(())
3939
})
40-
.build(tauri::generate_context!())
40+
.on_window_event(|event| {
41+
match event.event() {
42+
WindowEvent::CloseRequested { api, .. } => {
43+
event
44+
.window()
45+
.emit("show-egg", ())
46+
.expect("Cannot emit show-egg event");
47+
// TODO: Once https://github.com/tauri-apps/tauri/issues/3084 is solved:
48+
// - hide the window here
49+
// - restore the window on dock-click/option+tab ("activate" macos event).
50+
api.prevent_close();
51+
}
52+
_ => {}
53+
}
54+
})
55+
.run(tauri::generate_context!())
4156
.expect("error while running tauri application");
42-
43-
app.run(|_, e| match e {
44-
RunEvent::WindowEvent {
45-
event: WindowEvent::CloseRequested { api, .. },
46-
..
47-
} => {
48-
// TODO: Once https://github.com/tauri-apps/tauri/issues/3084 is solved:
49-
// - hide the window here
50-
// - restore the window on dock-click/option+tab ("activate" macos event).
51-
api.prevent_close();
52-
}
53-
_ => {}
54-
});
5557
}

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Summary } from './Summary';
77
import { core } from './core';
88
import { Settings } from './Settings';
99
import { IntervalBasedCronScheduler, parseCronExpression } from 'cron-schedule';
10+
import Egg from './Egg';
1011

1112
function App() {
1213
const [error, setError] = useState('');
@@ -129,6 +130,7 @@ function App() {
129130
<Settings close={() => setSettingsOpened(false)} />
130131
</div>
131132
)}
133+
<Egg />
132134
</>
133135
);
134136
}

src/Egg.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { useEffect, useState } from 'react';
2+
import { appWindow } from '@tauri-apps/api/window';
3+
4+
let isRunning = false;
5+
6+
export default function Egg() {
7+
const [isVisible, setIsVisible] = useState(false);
8+
const [text, setText] = useState('');
9+
useEffect(() => {
10+
appWindow.listen('show-egg', () => {
11+
setIsVisible(true);
12+
(async () => {
13+
if (isRunning) {
14+
return;
15+
}
16+
isRunning = true;
17+
setText('');
18+
for (const row of song.trim().split('\n')) {
19+
for (const item of row.split(' ')) {
20+
if (item.match(/^\d+$/)) {
21+
const delay = parseInt(item, 10);
22+
await new Promise((resolve) => {
23+
setTimeout(() => {
24+
resolve(null);
25+
}, delay);
26+
});
27+
} else {
28+
setText((text) => text + ' ' + item);
29+
}
30+
}
31+
setText((text) => text + '\n');
32+
}
33+
isRunning = false;
34+
})();
35+
});
36+
}, []);
37+
return (
38+
<div
39+
style={
40+
isVisible
41+
? {
42+
height: '100%',
43+
width: '100%',
44+
position: 'fixed',
45+
left: 0,
46+
top: 0,
47+
backgroundColor: 'white',
48+
padding: '10px',
49+
zIndex: '100',
50+
}
51+
: { display: 'none' }
52+
}
53+
>
54+
<pre>{text}</pre>
55+
<pre>
56+
&nbsp;
57+
<a
58+
href="https://github.com/Leksat/aptt/blob/bc65d99d647b542b65695be27e3d56cbb7ab0ba2/src-tauri/src/main.rs#L48-L51"
59+
target="_blank"
60+
>
61+
WTF
62+
</a>
63+
</pre>
64+
<button
65+
onClick={() => {
66+
setIsVisible(false);
67+
}}
68+
>
69+
Hide
70+
</button>
71+
</div>
72+
);
73+
}
74+
75+
const song = `
76+
Don't 1000 close 700 me 600 now 500
77+
🎵 300 🎵 300 🎵 300 🎵 300 🎵 300 🎵 600
78+
Don't 1000 close 700 me 300
79+
'Cause 300 I'm 300 better 400 than 500 awesome, 1000 better 400 than 300 awesome 1300
80+
I'm 100 a 300 perfect 300 app 800 helping 300 track 300 you 300 time 1500
81+
Straight 300 to 300 Jira 1100 I 300 can 300 submit 1500
82+
. 200 . 200 .
83+
`;

0 commit comments

Comments
 (0)