Skip to content

Commit 7d1dc38

Browse files
committed
Add autostart
1 parent ae122f8 commit 7d1dc38

File tree

7 files changed

+77
-10
lines changed

7 files changed

+77
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@vueuse/core": "^9.12.0",
1616
"pinia": "^2.0.29",
1717
"redaxios": "^0.5.1",
18+
"tauri-plugin-autostart-api": "github:tauri-apps/tauri-plugin-autostart",
1819
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
1920
"vue": "^3.2.45"
2021
},

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.lock

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typed-html = { git = "https://github.com/bodil/typed-html", rev = "4c13ecca" }
2323
ascii = "1.1.0"
2424
rodio = "0.16.0"
2525
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
26+
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
2627

2728
[features]
2829
# by default Tauri runs in production mode

src-tauri/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ fn handle_window_event(event: GlobalWindowEvent) {
7878
}
7979
}
8080

81+
use tauri_plugin_autostart::MacosLauncher;
82+
8183
fn main() {
8284
let tray = SystemTray::new();
8385

@@ -86,6 +88,10 @@ fn main() {
8688
play_notification_sound,
8789
set_icon_template
8890
])
91+
.plugin(tauri_plugin_autostart::init(
92+
MacosLauncher::LaunchAgent,
93+
None,
94+
))
8995
.plugin(tauri_plugin_store::Builder::default().build())
9096
.system_tray(tray)
9197
.on_system_tray_event(handle_system_tray_event)

src/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import 'focus-visible'
33

44
import { createApp } from 'vue'
55
import { createPinia } from 'pinia'
6+
import { isEnabled as isAutostartEnabled } from 'tauri-plugin-autostart-api'
67
import App from './App.vue'
78
import { AppStorage, cacheStorageFromDisk } from './storage'
89
import { useStore } from './stores/store'
910
import { Page } from './constants'
1011
import { initDevtools } from './utils/initDevtools'
12+
import { useKey } from './composables/useKey'
1113

1214
window.addEventListener('contextmenu', e => e.preventDefault())
1315

@@ -22,6 +24,7 @@ app.use(pinia)
2224
const store = useStore(pinia)
2325
const token = AppStorage.get('accessToken')
2426
const user = AppStorage.get('user')
27+
AppStorage.set('openAtStartup', await isAutostartEnabled())
2528

2629
if (token && user)
2730
store.setPage(Page.Home)
@@ -31,8 +34,5 @@ app.use(pinia)
3134

3235
if (import.meta.env.DEV) {
3336
initDevtools()
34-
window.addEventListener('keydown', (event) => {
35-
if ((event.key === 'r' || event.key === 'r') && event.metaKey)
36-
location.reload()
37-
})
37+
useKey('command+r', () => location.reload(), { prevent: true })
3838
}

src/utils/notification.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { invoke } from '@tauri-apps/api/tauri'
21
import { markRaw } from 'vue'
32
import type { Thread } from '../api/notifications'
43
import { Icons } from '../components/Icons'
@@ -14,10 +13,6 @@ export function formatReason(reason: NotificationReason) {
1413
return reasonFormatMap[reason] || 'Unknown reason'
1514
}
1615

17-
export function playNotificationSound() {
18-
invoke('play_notification_sound')
19-
}
20-
2116
function notificationListItemFromThread(thread: Thread): NotificationListDataItem {
2217
return {
2318
id: thread.id,

0 commit comments

Comments
 (0)