mirror of
https://gitee.com/HuLaSpark/HuLa.git
synced 2024-11-29 18:28:30 +08:00
⚡ perf(setting): 优化系统托盘图标在不同窗口下显示不同功能
This commit is contained in:
parent
0289f3534a
commit
b10d5c0b96
@ -23,10 +23,12 @@
|
||||
"scripts": {
|
||||
"dev": "vite --mode dev",
|
||||
"prod": "vite --mode prod",
|
||||
"build": "vue-tsc --noEmit && vite build --mode prod",
|
||||
"build:dev": "vue-tsc --noEmit && vite build --mode dev",
|
||||
"build:prod": "vue-tsc --noEmit && vite build --mode prod",
|
||||
"preview": "vite preview",
|
||||
"tauri:dev": "tauri dev",
|
||||
"tauri:build": "tauri build",
|
||||
"tauri:build:dev": "tauri build:dev",
|
||||
"tauri:build:prod": "tauri build:prod",
|
||||
"tauri:icon": "tauri icon public/logo.png",
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"commit": "git add . && lint-staged && git-cz && conventional-changelog -p cz-config.cjs -i CHANGELOG.md -s -r 0",
|
||||
|
@ -29,11 +29,23 @@ fn red_icon(app: &AppHandle) {
|
||||
pub fn handler(app: &AppHandle, event: SystemTrayEvent) {
|
||||
match event {
|
||||
SystemTrayEvent::LeftClick { .. } => {
|
||||
// 当我点击闪烁的图标的时候就停止闪烁
|
||||
let window = app.get_window("tray").unwrap();
|
||||
window.emit("stop", false).unwrap();
|
||||
open_home(app);
|
||||
red_icon(app);
|
||||
// 检查 "login" 窗口是否已创建
|
||||
if app.get_window("login").is_some() {
|
||||
// 如果 "login" 窗口已创建,进一步检查其是否处于最小化状态
|
||||
let login_window = app.get_window("login").unwrap();
|
||||
if login_window.is_minimized().unwrap() {
|
||||
// 如果 "login" 窗口处于最小化状态,先将其还原
|
||||
login_window.unminimize().unwrap();
|
||||
} else {
|
||||
login_window.set_focus().unwrap()
|
||||
}
|
||||
} else {
|
||||
// 如果 "login" 窗口未创建,执行以下操作
|
||||
let tray_window = app.get_window("tray").unwrap();
|
||||
tray_window.emit("stop", false).unwrap();
|
||||
open_home(app);
|
||||
red_icon(app);
|
||||
}
|
||||
},
|
||||
SystemTrayEvent::RightClick { position: p, size: _, .. } => {
|
||||
// TODO 这里需要根据鼠标位置来确定窗口的位置 (nyh -> 2024-03-20 13:51:01)
|
||||
|
@ -85,7 +85,7 @@
|
||||
"center": false,
|
||||
"visible": false,
|
||||
"width": 130,
|
||||
"height": 356,
|
||||
"height": 44,
|
||||
"alwaysOnTop": true,
|
||||
"skipTaskbar": true,
|
||||
"decorations": false
|
||||
|
@ -80,6 +80,7 @@ const moreList = ref<OPT.L.MoreList[]>([
|
||||
delay(async () => {
|
||||
/* 通知全部打开的窗口然后关闭 */
|
||||
await emit(EventEnum.LOGOUT)
|
||||
await emit('logout_success')
|
||||
}, 300)
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<n-flex vertical :size="6" class="tray">
|
||||
<n-flex v-if="!isLoginWin" vertical :size="6" class="tray">
|
||||
<n-flex vertical :size="6">
|
||||
<n-flex
|
||||
v-for="(item, index) in statusItem.slice(0, 6)"
|
||||
@ -40,6 +40,12 @@
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
|
||||
<n-flex v-else vertical :size="6" class="tray">
|
||||
<n-flex @click="exit(0)" align="center" :size="10" class="p-[8px_6px] rounded-4px hover:bg-[--tray-hover-e]">
|
||||
<span>退出</span>
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
</template>
|
||||
<script setup lang="tsx">
|
||||
import { useWindow } from '@/hooks/useWindow.ts'
|
||||
@ -50,8 +56,9 @@ import { onlineStatus } from '@/stores/onlineStatus.ts'
|
||||
import { appWindow } from '@tauri-apps/api/window'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
|
||||
const { checkWinExist, createWebviewWindow } = useWindow()
|
||||
const { checkWinExist, createWebviewWindow, resizeWindow } = useWindow()
|
||||
const OLStatusStore = onlineStatus()
|
||||
const isLoginWin = ref(true)
|
||||
|
||||
const division = () => {
|
||||
return <div class={'h-1px bg-[--line-color] w-full'}></div>
|
||||
@ -62,9 +69,17 @@ const toggleStatus = (url: string, title: string) => {
|
||||
appWindow.hide()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await listen('login_success', () => {
|
||||
isLoginWin.value = false
|
||||
resizeWindow('tray', 130, 336)
|
||||
})
|
||||
await listen('logout_success', () => {
|
||||
isLoginWin.value = true
|
||||
resizeWindow('tray', 130, 24)
|
||||
})
|
||||
// 暂停图标闪烁
|
||||
listen('stop', async () => {
|
||||
await listen('stop', async () => {
|
||||
await invoke('tray_blink', { isRun: false }).catch((error) => {
|
||||
console.error('暂停闪烁失败:', error)
|
||||
})
|
||||
|
@ -152,6 +152,7 @@ import { lightTheme } from 'naive-ui'
|
||||
import { setting } from '@/stores/setting.ts'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { emit } from '@tauri-apps/api/event'
|
||||
|
||||
const settingStore = setting()
|
||||
const { login } = storeToRefs(settingStore)
|
||||
@ -247,6 +248,7 @@ const loginWin = () => {
|
||||
avatar: avatarRef.value,
|
||||
name: nameRef.value
|
||||
})
|
||||
await emit('login_success')
|
||||
await invoke('set_main_icon').catch((error) => {
|
||||
console.error('设置主要图标失败:', error)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user