mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-07 00:30:14 +08:00
✨ Feature(custom): refactor all main ipc event
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
PicList - {{ version }}
|
||||
</div>
|
||||
<div
|
||||
v-if="os !== 'darwin'"
|
||||
v-if="osGlobal !== 'darwin'"
|
||||
class="handle-bar"
|
||||
>
|
||||
<el-icon
|
||||
@@ -68,7 +68,6 @@
|
||||
:default-active="defaultActive"
|
||||
:unique-opened="true"
|
||||
@select="handleSelect"
|
||||
@open="handleGetPicPeds"
|
||||
>
|
||||
<el-menu-item :index="routerConfig.UPLOAD_PAGE">
|
||||
<el-icon>
|
||||
@@ -101,7 +100,7 @@
|
||||
<span>{{ $T('PICBEDS_SETTINGS') }}</span>
|
||||
</template>
|
||||
<template
|
||||
v-for="item in picBed"
|
||||
v-for="item in picBedGlobal"
|
||||
>
|
||||
<el-menu-item
|
||||
v-if="item.visible"
|
||||
@@ -188,7 +187,7 @@
|
||||
teleported
|
||||
>
|
||||
<el-option
|
||||
v-for="item in picBed"
|
||||
v-for="item in picBedGlobal"
|
||||
:key="item.type"
|
||||
:label="item.name"
|
||||
:value="item.type"
|
||||
@@ -247,26 +246,21 @@ import InputBoxDialog from '@/components/InputBoxDialog.vue'
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import * as config from '@/router/config'
|
||||
import { getConfig, saveConfig } from '@/utils/dataSender'
|
||||
import { openURL, sendToMain } from '@/utils/common'
|
||||
import { sendRPC } from '@/utils/common'
|
||||
import { osGlobal, picBedGlobal, updatePicBedGlobal } from '@/utils/global'
|
||||
|
||||
import {
|
||||
MINIMIZE_WINDOW,
|
||||
CLOSE_WINDOW,
|
||||
SHOW_MAIN_PAGE_MENU,
|
||||
SHOW_MAIN_PAGE_QRCODE,
|
||||
GET_PICBEDS
|
||||
SHOW_MAIN_PAGE_QRCODE
|
||||
} from '#/events/constants'
|
||||
import { configPaths, manualPageOpenType } from '#/utils/configPaths'
|
||||
import { II18nLanguage } from '#/types/enum'
|
||||
import { II18nLanguage, IRPCActionType } from '#/types/enum'
|
||||
|
||||
import pkg from 'root/package.json'
|
||||
|
||||
const version = ref(process.env.NODE_ENV === 'production' ? pkg.version : 'Dev')
|
||||
const routerConfig = reactive(config)
|
||||
const defaultActive = ref(routerConfig.UPLOAD_PAGE)
|
||||
const os = ref('')
|
||||
const $router = useRouter()
|
||||
const picBed: Ref<IPicBedType[]> = ref([])
|
||||
const qrcodeVisible = ref(false)
|
||||
const picBedConfigString = ref('')
|
||||
const choosedPicBedForQRCode: Ref<string[]> = ref([])
|
||||
@@ -277,10 +271,7 @@ const isShowprogress = ref(false)
|
||||
const progress = ref(0)
|
||||
|
||||
onBeforeMount(() => {
|
||||
os.value = process.platform
|
||||
sendToMain(GET_PICBEDS)
|
||||
ipcRenderer.on(GET_PICBEDS, getPicBeds)
|
||||
handleGetPicPeds()
|
||||
updatePicBedGlobal()
|
||||
ipcRenderer.on(SHOW_MAIN_PAGE_QRCODE, () => {
|
||||
qrcodeVisible.value = true
|
||||
})
|
||||
@@ -300,17 +291,13 @@ watch(() => choosedPicBedForQRCode, (val) => {
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
const handleGetPicPeds = () => {
|
||||
sendToMain(GET_PICBEDS)
|
||||
}
|
||||
|
||||
const handleSelect = async (index: string) => {
|
||||
defaultActive.value = index
|
||||
if (index === routerConfig.DocumentPage) {
|
||||
const manualPageOpenSetting = await getConfig<manualPageOpenType>(configPaths.settings.manualPageOpen)
|
||||
const lang = await getConfig(configPaths.settings.language) || II18nLanguage.ZH_CN
|
||||
const openManual = () => ipcRenderer.send('openManualWindow')
|
||||
const openExternal = () => openURL(lang === II18nLanguage.ZH_CN ? 'https://piclist.cn/app.html' : 'https://piclist.cn/en/app.html')
|
||||
const openManual = () => sendRPC(IRPCActionType.OPEN_MANUAL_WINDOW)
|
||||
const openExternal = () => sendRPC(IRPCActionType.OPEN_URL, lang === II18nLanguage.ZH_CN ? 'https://piclist.cn/app.html' : 'https://piclist.cn/en/app.html')
|
||||
|
||||
if (!manualPageOpenSetting) {
|
||||
ElMessageBox.confirm($T('MANUAL_PAGE_OPEN_TIP'), $T('MANUAL_PAGE_OPEN_TIP_TITLE'), {
|
||||
@@ -347,19 +334,19 @@ const handleSelect = async (index: string) => {
|
||||
}
|
||||
|
||||
function minimizeWindow () {
|
||||
sendToMain(MINIMIZE_WINDOW)
|
||||
sendRPC(IRPCActionType.MINIMIZE_WINDOW)
|
||||
}
|
||||
|
||||
function closeWindow () {
|
||||
sendToMain(CLOSE_WINDOW)
|
||||
sendRPC(IRPCActionType.CLOSE_WINDOW)
|
||||
}
|
||||
|
||||
function openMenu () {
|
||||
sendToMain(SHOW_MAIN_PAGE_MENU)
|
||||
sendRPC(IRPCActionType.SHOW_MAIN_PAGE_MENU)
|
||||
}
|
||||
|
||||
function openMiniWindow () {
|
||||
sendToMain('openMiniWindow')
|
||||
sendRPC(IRPCActionType.OPEN_MINI_WINDOW)
|
||||
}
|
||||
|
||||
function handleCopyPicBedConfig () {
|
||||
@@ -367,13 +354,9 @@ function handleCopyPicBedConfig () {
|
||||
$message.success($T('COPY_PICBED_CONFIG_SUCCEED'))
|
||||
}
|
||||
|
||||
function getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
|
||||
picBed.value = picBeds
|
||||
}
|
||||
|
||||
function setAlwaysOnTop () {
|
||||
isAlwaysOnTop.value = !isAlwaysOnTop.value
|
||||
sendToMain('toggleMainWindowAlwaysOnTop', isAlwaysOnTop.value)
|
||||
sendRPC(IRPCActionType.MAIN_WINDOW_ON_TOP)
|
||||
}
|
||||
|
||||
onBeforeRouteUpdate(async (to) => {
|
||||
@@ -385,7 +368,6 @@ onBeforeRouteUpdate(async (to) => {
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
ipcRenderer.removeListener(GET_PICBEDS, getPicBeds)
|
||||
ipcRenderer.removeAllListeners(SHOW_MAIN_PAGE_QRCODE)
|
||||
ipcRenderer.removeAllListeners('updateProgress')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user