Skip to content

Commit cdfd0b6

Browse files
authored
feat: 新增「通用设置 > 应用设置 > 显示托盘图标」配置项 (#910)
1 parent 204797b commit cdfd0b6

11 files changed

Lines changed: 93 additions & 61 deletions

File tree

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CheckMenuItem, MenuItem, PredefinedMenuItem, Submenu } from '@tauri-apps/api/menu'
2+
import { exit, relaunch } from '@tauri-apps/plugin-process'
23
import { range } from 'es-toolkit'
34
import { useI18n } from 'vue-i18n'
45

@@ -7,7 +8,7 @@ import { showWindow } from '@/plugins/window'
78
import { useCatStore } from '@/stores/cat'
89
import { isMac } from '@/utils/platform'
910

10-
export function useSharedMenu() {
11+
export function useAppMenu() {
1112
const catStore = useCatStore()
1213
const { t } = useI18n()
1314

@@ -59,39 +60,54 @@ export function useSharedMenu() {
5960
return Promise.all(items)
6061
}
6162

62-
const getSharedMenu = async () => {
63+
const getBaseMenu = async () => {
6364
return await Promise.all([
6465
MenuItem.new({
65-
text: t('composables.useSharedMenu.labels.preference'),
66+
text: t('composables.useAppMenu.labels.preference'),
6667
accelerator: isMac ? 'Cmd+,' : '',
6768
action: () => showWindow(WINDOW_LABEL.PREFERENCE),
6869
}),
6970
MenuItem.new({
70-
text: catStore.window.visible ? t('composables.useSharedMenu.labels.hideCat') : t('composables.useSharedMenu.labels.showCat'),
71+
text: catStore.window.visible ? t('composables.useAppMenu.labels.hideCat') : t('composables.useAppMenu.labels.showCat'),
7172
action: () => {
7273
catStore.window.visible = !catStore.window.visible
7374
},
7475
}),
7576
PredefinedMenuItem.new({ item: 'Separator' }),
7677
CheckMenuItem.new({
77-
text: t('composables.useSharedMenu.labels.passThrough'),
78+
text: t('composables.useAppMenu.labels.passThrough'),
7879
checked: catStore.window.passThrough,
7980
action: () => {
8081
catStore.window.passThrough = !catStore.window.passThrough
8182
},
8283
}),
8384
Submenu.new({
84-
text: t('composables.useSharedMenu.labels.windowSize'),
85+
text: t('composables.useAppMenu.labels.windowSize'),
8586
items: await getScaleMenuItems(),
8687
}),
8788
Submenu.new({
88-
text: t('composables.useSharedMenu.labels.opacity'),
89+
text: t('composables.useAppMenu.labels.opacity'),
8990
items: await getOpacityMenuItems(),
9091
}),
9192
])
9293
}
9394

95+
const getExitMenu = async () => {
96+
return await Promise.all([
97+
MenuItem.new({
98+
text: t('composables.useAppMenu.labels.restartApp'),
99+
action: relaunch,
100+
}),
101+
MenuItem.new({
102+
text: t('composables.useAppMenu.labels.quitApp'),
103+
accelerator: isMac ? 'Cmd+Q' : '',
104+
action: () => exit(0),
105+
}),
106+
])
107+
}
108+
94109
return {
95-
getSharedMenu,
110+
getBaseMenu,
111+
getExitMenu,
96112
}
97113
}

src/composables/useTray.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Menu, MenuItem, PredefinedMenuItem } from '@tauri-apps/api/menu'
66
import { resolveResource } from '@tauri-apps/api/path'
77
import { TrayIcon } from '@tauri-apps/api/tray'
88
import { openUrl } from '@tauri-apps/plugin-opener'
9-
import { exit, relaunch } from '@tauri-apps/plugin-process'
109
import { watchDebounced } from '@vueuse/core'
1110
import { watch } from 'vue'
1211
import { useI18n } from 'vue-i18n'
@@ -15,7 +14,7 @@ import { GITHUB_LINK, LISTEN_KEY } from '../constants'
1514
import { showWindow } from '../plugins/window'
1615
import { isMac } from '../utils/platform'
1716

18-
import { useSharedMenu } from './useSharedMenu'
17+
import { useAppMenu } from './useAppMenu'
1918

2019
import { useCatStore } from '@/stores/cat'
2120
import { useGeneralStore } from '@/stores/general'
@@ -25,7 +24,7 @@ const TRAY_ID = 'BONGO_CAT_TRAY'
2524
export function useTray() {
2625
const catStore = useCatStore()
2726
const generalStore = useGeneralStore()
28-
const { getSharedMenu } = useSharedMenu()
27+
const { getBaseMenu, getExitMenu } = useAppMenu()
2928
const { t } = useI18n()
3029

3130
watch([() => catStore.window.visible, () => catStore.window.passThrough, () => generalStore.appearance.language], () => {
@@ -36,6 +35,10 @@ export function useTray() {
3635
updateTrayMenu()
3736
}, { debounce: 200 })
3837

38+
const getTrayById = () => {
39+
return TrayIcon.getById(TRAY_ID)
40+
}
41+
3942
const createTray = async () => {
4043
const tray = await getTrayById()
4144

@@ -61,15 +64,11 @@ export function useTray() {
6164
return TrayIcon.new(options)
6265
}
6366

64-
const getTrayById = () => {
65-
return TrayIcon.getById(TRAY_ID)
66-
}
67-
6867
const getTrayMenu = async () => {
6968
const appVersion = await getVersion()
7069

7170
const items = await Promise.all([
72-
...await getSharedMenu(),
71+
...await getBaseMenu(),
7372
PredefinedMenuItem.new({ item: 'Separator' }),
7473
MenuItem.new({
7574
text: t('composables.useTray.checkUpdate'),
@@ -88,15 +87,7 @@ export function useTray() {
8887
text: `v${appVersion}`,
8988
enabled: false,
9089
}),
91-
MenuItem.new({
92-
text: t('composables.useTray.restartApp'),
93-
action: relaunch,
94-
}),
95-
MenuItem.new({
96-
text: t('composables.useTray.quitApp'),
97-
accelerator: isMac ? 'Cmd+Q' : '',
98-
action: () => exit(0),
99-
}),
90+
...await getExitMenu(),
10091
])
10192

10293
return Menu.new({ items })
@@ -112,7 +103,11 @@ export function useTray() {
112103
tray.setMenu(menu)
113104
}
114105

115-
return {
116-
createTray,
117-
}
106+
watch(() => generalStore.app.trayVisible, async (visible) => {
107+
const tray = await getTrayById() ?? await createTray()
108+
109+
if (!tray) return
110+
111+
tray.setVisible(visible)
112+
}, { immediate: true })
118113
}

src/locales/en-US.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"appSettings": "Application Settings",
4545
"launchOnStartup": "Launch on Startup",
4646
"showTaskbarIcon": "Show Taskbar Icon",
47+
"showTrayIcon": "Show Tray Icon",
4748
"appearanceSettings": "Appearance Settings",
4849
"themeMode": "Theme Mode",
4950
"language": "Language",
@@ -59,6 +60,7 @@
5960
},
6061
"hints": {
6162
"showTaskbarIcon": "When enabled, the window can be captured via OBS Studio.",
63+
"showTrayIcon": "When enabled, the app icon is displayed in the system tray.",
6264
"inputMonitoringPermission": "Enable input monitoring to receive keyboard and mouse events from the system.",
6365
"inputMonitoringPermissionGuide": "If the permission is already enabled, select it and click the \"-\" button to remove it, then manually add it again and restart the app."
6466
},
@@ -161,21 +163,21 @@
161163
}
162164
},
163165
"composables": {
164-
"useSharedMenu": {
166+
"useAppMenu": {
165167
"labels": {
166168
"preference": "Preferences...",
167169
"hideCat": "Hide Cat",
168170
"showCat": "Show Cat",
169171
"passThrough": "Pass Through",
170172
"windowSize": "Window Size",
171-
"opacity": "Opacity"
173+
"opacity": "Opacity",
174+
"restartApp": "Restart App",
175+
"quitApp": "Quit App"
172176
}
173177
},
174178
"useTray": {
175179
"checkUpdate": "Check for Updates",
176-
"openSource": "Open Source",
177-
"restartApp": "Restart App",
178-
"quitApp": "Quit App"
180+
"openSource": "Open Source"
179181
}
180182
},
181183
"utils": {

src/locales/pt-BR.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"appSettings": "Configurações do aplicativo",
4545
"launchOnStartup": "Iniciar na inicialização",
4646
"showTaskbarIcon": "Mostrar ícone na barra de tarefas",
47+
"showTrayIcon": "Mostrar ícone na bandeja",
4748
"appearanceSettings": "Configurações de aparência",
4849
"themeMode": "Tema",
4950
"language": "Idiomas",
@@ -59,6 +60,7 @@
5960
},
6061
"hints": {
6162
"showTaskbarIcon": "Uma vez ativado, você pode capturar a janela via OBS Studio.",
63+
"showTrayIcon": "Quando ativado, o ícone do aplicativo é exibido na bandeja do sistema.",
6264
"inputMonitoringPermission": "Ative a permissão de monitoramento de entrada para receber eventos de teclado e mouse do sistema para responder às suas ações.",
6365
"inputMonitoringPermissionGuide": "Se a permissão já estiver ativada, primeiro selecione-a e clique no botão \"-\" para removê-la. Em seguida, adicione-a novamente manualmente e reinicie o aplicativo para garantir que a permissão entre em vigor."
6466
},
@@ -161,21 +163,21 @@
161163
}
162164
},
163165
"composables": {
164-
"useSharedMenu": {
166+
"useAppMenu": {
165167
"labels": {
166168
"preference": "Preferências...",
167169
"hideCat": "Ocultar Gato",
168170
"showCat": "Mostrar Gato",
169171
"passThrough": "Janela Transparente",
170172
"windowSize": "Tamanho da Janela",
171-
"opacity": "Opacidade"
173+
"opacity": "Opacidade",
174+
"restartApp": "Reiniciar",
175+
"quitApp": "Sair"
172176
}
173177
},
174178
"useTray": {
175179
"checkUpdate": "Verificar atualizações",
176-
"openSource": "Código Fonte",
177-
"restartApp": "Reiniciar",
178-
"quitApp": "Sair"
180+
"openSource": "Código Fonte"
179181
}
180182
},
181183
"utils": {

src/locales/vi-VN.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"appSettings": "Cài đặt ứng dụng",
4545
"launchOnStartup": "Khởi động cùng hệ thống",
4646
"showTaskbarIcon": "Hiện biểu tượng trên thanh tác vụ (icon taskbar)",
47+
"showTrayIcon": "Hiện biểu tượng trên khay hệ thống (tray)",
4748
"appearanceSettings": "Cài đặt giao diện",
4849
"themeMode": "Giao diện",
4950
"language": "Ngôn ngữ",
@@ -59,6 +60,7 @@
5960
},
6061
"hints": {
6162
"showTaskbarIcon": "Bật để có thể quay cửa sổ qua OBS.",
63+
"showTrayIcon": "Bật để hiện biểu tượng ứng dụng trên khay hệ thống.",
6264
"inputMonitoringPermission": "Bật quyền giám sát để nhận sự kiện bàn phím và chuột từ hệ thống nhằm phản hồi thao tác của bạn.",
6365
"inputMonitoringPermissionGuide": "Nếu quyền đã được bật, hãy chọn nó và nhấn nút \"-\" để xóa. Sau đó thêm lại thủ công và khởi động lại ứng dụng để đảm bảo quyền được áp dụng."
6466
},
@@ -161,21 +163,21 @@
161163
}
162164
},
163165
"composables": {
164-
"useSharedMenu": {
166+
"useAppMenu": {
165167
"labels": {
166168
"preference": "Tùy chỉnh...",
167169
"hideCat": "Ẩn Mèo",
168170
"showCat": "Hiện Mèo",
169171
"passThrough": "Click xuyên",
170172
"windowSize": "Kích thước",
171-
"opacity": "Độ mờ"
173+
"opacity": "Độ mờ",
174+
"restartApp": "Khởi động lại",
175+
"quitApp": "Thoát"
172176
}
173177
},
174178
"useTray": {
175179
"checkUpdate": "Kiểm tra cập nhật",
176-
"openSource": "Mã nguồn",
177-
"restartApp": "Khởi động lại",
178-
"quitApp": "Thoát"
180+
"openSource": "Mã nguồn"
179181
}
180182
},
181183
"utils": {

src/locales/zh-CN.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"appSettings": "应用设置",
4545
"launchOnStartup": "开机自启动",
4646
"showTaskbarIcon": "显示任务栏图标",
47+
"showTrayIcon": "显示托盘图标",
4748
"appearanceSettings": "外观设置",
4849
"themeMode": "主题模式",
4950
"language": "语言",
@@ -59,6 +60,7 @@
5960
},
6061
"hints": {
6162
"showTaskbarIcon": "启用后,即可通过 OBS Studio 捕获窗口。",
63+
"showTrayIcon": "启用后,在系统托盘中显示应用图标。",
6264
"inputMonitoringPermission": "开启输入监控权限,以便接收系统的键盘和鼠标事件来响应你的操作。",
6365
"inputMonitoringPermissionGuide": "如果权限已开启,请先选中并点击“-”按钮将其删除,然后重新手动添加,最后重启应用以确保权限生效。"
6466
},
@@ -161,21 +163,21 @@
161163
}
162164
},
163165
"composables": {
164-
"useSharedMenu": {
166+
"useAppMenu": {
165167
"labels": {
166168
"preference": "偏好设置...",
167169
"hideCat": "隐藏猫咪",
168170
"showCat": "显示猫咪",
169171
"passThrough": "窗口穿透",
170172
"windowSize": "窗口尺寸",
171-
"opacity": "不透明度"
173+
"opacity": "不透明度",
174+
"restartApp": "重启应用",
175+
"quitApp": "退出应用"
172176
}
173177
},
174178
"useTray": {
175179
"checkUpdate": "检查更新",
176-
"openSource": "开源地址",
177-
"restartApp": "重启应用",
178-
"quitApp": "退出应用"
180+
"openSource": "开源地址"
179181
}
180182
},
181183
"utils": {

src/locales/zh-TW.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"appSettings": "應用程式設定",
4545
"launchOnStartup": "開機自動啟動",
4646
"showTaskbarIcon": "顯示工作列圖示",
47+
"showTrayIcon": "顯示托盤圖示",
4748
"appearanceSettings": "外觀設定",
4849
"themeMode": "主題模式",
4950
"language": "語言",
@@ -59,6 +60,7 @@
5960
},
6061
"hints": {
6162
"showTaskbarIcon": "啟用後,即可透過 OBS Studio 擷取視窗。",
63+
"showTrayIcon": "啟用後,在系統托盤中顯示應用程式圖示。",
6264
"inputMonitoringPermission": "開啟輸入監控權限,以便接收系統的鍵盤和滑鼠游標事件來回應您的操作。",
6365
"inputMonitoringPermissionGuide": "如果權限已開啟,請先選中並點擊「-」按鈕將其刪除,然後重新手動新增,最後重啟應用程式以確保權限生效。"
6466
},
@@ -161,21 +163,21 @@
161163
}
162164
},
163165
"composables": {
164-
"useSharedMenu": {
166+
"useAppMenu": {
165167
"labels": {
166168
"preference": "偏好設定…",
167169
"hideCat": "隱藏貓咪",
168170
"showCat": "顯示貓咪",
169171
"passThrough": "視窗穿透",
170172
"windowSize": "視窗尺寸",
171-
"opacity": "不透明度"
173+
"opacity": "不透明度",
174+
"restartApp": "重啟應用程式",
175+
"quitApp": "退出應用程式"
172176
}
173177
},
174178
"useTray": {
175179
"checkUpdate": "檢查更新",
176-
"openSource": "開源網址",
177-
"restartApp": "重啟應用程式",
178-
"quitApp": "退出應用程式"
180+
"openSource": "開源網址"
179181
}
180182
},
181183
"utils": {

0 commit comments

Comments
 (0)