mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-02 22:31:49 +08:00
✨ Feature(custom): refactor all main ipc event
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
teleported
|
||||
>
|
||||
<el-option
|
||||
v-for="item in picBed"
|
||||
v-for="item in picBedGlobal"
|
||||
:key="item.type"
|
||||
:label="item.name"
|
||||
:value="item.type"
|
||||
@@ -462,8 +462,7 @@
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
ipcRenderer,
|
||||
clipboard,
|
||||
IpcRendererEvent
|
||||
clipboard
|
||||
} from 'electron'
|
||||
import { CheckboxValueType, ElMessageBox, ElNotification, ElMessage } from 'element-plus'
|
||||
import { InfoFilled, Close, CaretBottom, Document, Edit, Delete, CaretTop, Sort, Refresh } from '@element-plus/icons-vue'
|
||||
@@ -475,14 +474,14 @@ import type { IResult } from '@picgo/store/dist/types'
|
||||
import ALLApi from '@/apis/allApi'
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import { customRenameFormatTable, customStrMatch, customStrReplace } from '@/manage/utils/common'
|
||||
import { sendToMain } from '@/utils/common'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
import { getConfig, saveConfig } from '@/utils/dataSender'
|
||||
import $$db from '@/utils/db'
|
||||
import { picBedGlobal } from '@/utils/global'
|
||||
|
||||
import { PASTE_TEXT, GET_PICBEDS } from '#/events/constants'
|
||||
import { configPaths } from '#/utils/configPaths'
|
||||
import { picBedsCanbeDeleted } from '#/utils/static'
|
||||
import { IPasteStyle } from '#/types/enum'
|
||||
import { IPasteStyle, IRPCActionType } from '#/types/enum'
|
||||
|
||||
const images = ref<ImgInfo[]>([])
|
||||
const dialogVisible = ref(false)
|
||||
@@ -529,7 +528,6 @@ const mathcedCount = computed(() => {
|
||||
return matchedFiles.length
|
||||
})
|
||||
const dateRange = ref('')
|
||||
const picBed = ref<IPicBedType[]>([])
|
||||
onBeforeRouteUpdate((to, from) => {
|
||||
if (from.name === 'gallery') {
|
||||
clearChoosedList()
|
||||
@@ -551,8 +549,6 @@ onBeforeMount(async () => {
|
||||
updateGallery()
|
||||
})
|
||||
})
|
||||
sendToMain(GET_PICBEDS)
|
||||
ipcRenderer.on(GET_PICBEDS, getPicBeds)
|
||||
updateGallery()
|
||||
|
||||
document.addEventListener('keydown', handleDetectShiftKey)
|
||||
@@ -588,10 +584,6 @@ function formatFileName (name: string) {
|
||||
return path.basename(name)
|
||||
}
|
||||
|
||||
function getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
|
||||
picBed.value = picBeds
|
||||
}
|
||||
|
||||
function getGallery (): IGalleryItem[] {
|
||||
if (searchText.value || choosedPicBed.value.length > 0 || searchTextURL.value || dateRange.value) {
|
||||
return images.value
|
||||
@@ -636,7 +628,7 @@ function getGallery (): IGalleryItem[] {
|
||||
}
|
||||
|
||||
async function updateGallery () {
|
||||
images.value = (await $$db.get({ orderBy: 'desc' })).data
|
||||
images.value = (await $$db.get({ orderBy: 'desc' }))!.data
|
||||
}
|
||||
|
||||
watch(() => filterList, () => {
|
||||
@@ -659,7 +651,7 @@ function handleChooseImage (val: CheckboxValueType, index: number) {
|
||||
}
|
||||
|
||||
function refreshPage () {
|
||||
ipcRenderer.send('refreshSettingWindow')
|
||||
sendRPC(IRPCActionType.REFRESH_SETTING_WINDOW)
|
||||
}
|
||||
|
||||
function clearChoosedList () {
|
||||
@@ -694,7 +686,7 @@ function handleClose () {
|
||||
|
||||
async function copy (item: ImgInfo) {
|
||||
item.config = JSON.parse(JSON.stringify(item.config) || '{}')
|
||||
const copyLink = await ipcRenderer.invoke(PASTE_TEXT, item)
|
||||
const copyLink = await triggerRPC<string>(IRPCActionType.GALLERY_PASTE_TEXT, item)
|
||||
const obj = {
|
||||
title: $T('COPY_LINK_SUCCEED'),
|
||||
body: copyLink
|
||||
@@ -733,7 +725,7 @@ function remove (item: ImgInfo) {
|
||||
}
|
||||
}
|
||||
await $$db.removeById(item.id!)
|
||||
sendToMain('removeFiles', [file])
|
||||
sendRPC(IRPCActionType.GALLERY_REMOVE_FILES, [file])
|
||||
const obj = {
|
||||
title: $T('OPERATION_SUCCEED'),
|
||||
body: ''
|
||||
@@ -858,7 +850,7 @@ function multiRemove () {
|
||||
title: $T('OPERATION_SUCCEED'),
|
||||
body: ''
|
||||
}
|
||||
sendToMain('removeFiles', files)
|
||||
sendRPC(IRPCActionType.GALLERY_REMOVE_FILES, files)
|
||||
const myNotification = new Notification(obj.title, obj)
|
||||
myNotification.onclick = () => {
|
||||
return true
|
||||
@@ -880,8 +872,8 @@ async function multiCopy () {
|
||||
if (choosedList[key]) {
|
||||
const item = await $$db.getById<ImgInfo>(key)
|
||||
if (item) {
|
||||
const txt = await ipcRenderer.invoke(PASTE_TEXT, item)
|
||||
copyString.push(txt)
|
||||
const txt = await triggerRPC<string>(IRPCActionType.GALLERY_PASTE_TEXT, item)
|
||||
copyString.push(txt!)
|
||||
choosedList[key] = false
|
||||
}
|
||||
}
|
||||
@@ -1026,7 +1018,6 @@ function handleBatchRename () {
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
ipcRenderer.removeAllListeners('updateGallery')
|
||||
ipcRenderer.removeListener(GET_PICBEDS, getPicBeds)
|
||||
})
|
||||
|
||||
onActivated(async () => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
>
|
||||
<div
|
||||
id="upload-area"
|
||||
:class="{ 'is-dragover': dragover, uploading: isShowingProgress, linux: os === 'linux' }"
|
||||
:class="{ 'is-dragover': dragover, uploading: isShowingProgress, linux: osGlobal === 'linux' }"
|
||||
:style="{ backgroundPosition: '0 ' + progress + '%'}"
|
||||
@drop.prevent="onDrop"
|
||||
@dragover.prevent="dragover = true"
|
||||
@@ -40,11 +40,12 @@ import { IConfig } from 'piclist'
|
||||
import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue'
|
||||
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import { sendToMain, invokeToMain } from '@/utils/common'
|
||||
import { invokeToMain, sendRPC } from '@/utils/common'
|
||||
import { getConfig } from '@/utils/dataSender'
|
||||
import { osGlobal } from '@/utils/global'
|
||||
|
||||
import { SHOW_MINI_PAGE_MENU, SET_MINI_WINDOW_POS } from '#/events/constants'
|
||||
import { isUrl } from '#/utils/common'
|
||||
import { IRPCActionType } from '#/types/enum'
|
||||
|
||||
const logoPath = ref('')
|
||||
const dragover = ref(false)
|
||||
@@ -55,11 +56,10 @@ const wX = ref(-1)
|
||||
const wY = ref(-1)
|
||||
const screenX = ref(-1)
|
||||
const screenY = ref(-1)
|
||||
const os = ref('')
|
||||
|
||||
async function initLogoPath () {
|
||||
const config = (await getConfig<IConfig>())!
|
||||
if (config !== undefined) {
|
||||
const config = await getConfig<IConfig>()
|
||||
if (config) {
|
||||
if (config.settings?.isCustomMiniIcon && config.settings?.customMiniIcon) {
|
||||
logoPath.value = 'data:image/jpg;base64,' + await invokeToMain('convertPathToBase64', config.settings.customMiniIcon)
|
||||
}
|
||||
@@ -67,7 +67,6 @@ async function initLogoPath () {
|
||||
}
|
||||
|
||||
onBeforeMount(async () => {
|
||||
os.value = process.platform
|
||||
await initLogoPath()
|
||||
ipcRenderer.on('uploadProgress', (_: IpcRendererEvent, _progress: number) => {
|
||||
if (_progress !== -1) {
|
||||
@@ -110,7 +109,7 @@ function onDrop (e: DragEvent) {
|
||||
} else if (items[0].type === 'text/plain') {
|
||||
const str = e.dataTransfer!.getData(items[0].type)
|
||||
if (isUrl(str)) {
|
||||
sendToMain('uploadChoosedFiles', [{ path: str }])
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, [{ path: str }])
|
||||
} else {
|
||||
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
|
||||
}
|
||||
@@ -124,7 +123,7 @@ function handleURLDrag (items: DataTransferItemList, dataTransfer: DataTransfer)
|
||||
const urlString = dataTransfer.getData(items[1].type)
|
||||
const urlMatch = urlString.match(/<img.*src="(.*?)"/)
|
||||
if (urlMatch) {
|
||||
sendToMain('uploadChoosedFiles', [
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, [
|
||||
{
|
||||
path: urlMatch[1]
|
||||
}
|
||||
@@ -154,7 +153,7 @@ function ipcSendFiles (files: FileList) {
|
||||
}
|
||||
sendFiles.push(obj)
|
||||
})
|
||||
sendToMain('uploadChoosedFiles', sendFiles)
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, sendFiles)
|
||||
}
|
||||
|
||||
function handleMouseDown (e: MouseEvent) {
|
||||
@@ -171,7 +170,7 @@ function handleMouseMove (e: MouseEvent) {
|
||||
if (draggingState.value) {
|
||||
const xLoc = e.screenX - wX.value
|
||||
const yLoc = e.screenY - wY.value
|
||||
sendToMain(SET_MINI_WINDOW_POS, {
|
||||
sendRPC(IRPCActionType.SET_MINI_WINDOW_POS, {
|
||||
x: xLoc,
|
||||
y: yLoc,
|
||||
width: 64,
|
||||
@@ -192,7 +191,7 @@ function handleMouseUp (e: MouseEvent) {
|
||||
}
|
||||
|
||||
function openContextMenu () {
|
||||
sendToMain(SHOW_MINI_PAGE_MENU)
|
||||
sendRPC(IRPCActionType.SHOW_MINI_PAGE_MENU)
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
@@ -74,13 +74,13 @@
|
||||
:value="'quiet'"
|
||||
/>
|
||||
<el-option
|
||||
v-if="os !== 'darwin'"
|
||||
v-if="osGlobal !== 'darwin'"
|
||||
key="mini"
|
||||
:label="$T('SETTINGS_START_MODE_MINI')"
|
||||
:value="'mini'"
|
||||
/>
|
||||
<el-option
|
||||
v-if="os === 'darwin'"
|
||||
v-if="osGlobal === 'darwin'"
|
||||
key="no-tray"
|
||||
:label="$T('SETTINGS_START_MODE_NO_TRAY')"
|
||||
:value="'no-tray'"
|
||||
@@ -113,7 +113,7 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="os === 'darwin'"
|
||||
v-if="osGlobal === 'darwin'"
|
||||
:label="$T('SETTINGS_ISHIDEDOCK')"
|
||||
>
|
||||
<el-switch
|
||||
@@ -136,7 +136,7 @@
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="os !== 'darwin'"
|
||||
v-if="osGlobal !== 'darwin'"
|
||||
:label="$T('SETTINGS_CLOSE_MINI_WINDOW_SYNC')"
|
||||
>
|
||||
<el-switch
|
||||
@@ -146,7 +146,7 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="os !== 'darwin'"
|
||||
v-if="osGlobal !== 'darwin'"
|
||||
:label="$T('SETTINGS_CLOSE_MAIN_WINDOW_SYNC')"
|
||||
>
|
||||
<el-switch
|
||||
@@ -156,7 +156,7 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="os !== 'darwin'"
|
||||
v-if="osGlobal !== 'darwin'"
|
||||
:label="$T('SETTINGS_MINI_WINDOW_ON_TOP')"
|
||||
>
|
||||
<el-switch
|
||||
@@ -167,7 +167,7 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="os !== 'darwin'"
|
||||
v-if="osGlobal !== 'darwin'"
|
||||
:label="$T('SETTINGS_CUSTOM_MINI_ICON')"
|
||||
>
|
||||
<el-switch
|
||||
@@ -177,7 +177,7 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="os !== 'darwin' && formOfSetting.isCustomMiniIcon"
|
||||
v-if="osGlobal !== 'darwin' && formOfSetting.isCustomMiniIcon"
|
||||
:label="$T('SETTINGS_CUSTOM_MINI_ICON_PATH')"
|
||||
>
|
||||
<el-button
|
||||
@@ -336,7 +336,7 @@
|
||||
teleported
|
||||
>
|
||||
<el-option
|
||||
v-for="item in picBed"
|
||||
v-for="item in picBedGlobal"
|
||||
:key="item.type"
|
||||
:label="item.name"
|
||||
:value="item.type"
|
||||
@@ -425,7 +425,7 @@
|
||||
:label="$T('SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD')"
|
||||
>
|
||||
<el-switch
|
||||
v-model="formOfSetting.autoCopyUrl"
|
||||
v-model="formOfSetting.autoCopy"
|
||||
:active-text="$T('SETTINGS_OPEN')"
|
||||
:inactive-text="$T('SETTINGS_CLOSE')"
|
||||
/>
|
||||
@@ -563,11 +563,11 @@
|
||||
:label="$T('CHOOSE_SHOWED_PICBED')"
|
||||
>
|
||||
<el-checkbox-group
|
||||
v-model="formOfSetting.showPicBedList"
|
||||
v-model="showPicBedList"
|
||||
@change="handleShowPicBedListChange"
|
||||
>
|
||||
<el-checkbox
|
||||
v-for="item in picBed"
|
||||
v-for="item in picBedGlobal"
|
||||
:key="item.name"
|
||||
:label="item.name"
|
||||
:value="item.name"
|
||||
@@ -730,7 +730,7 @@
|
||||
<el-form
|
||||
ref="$customLink"
|
||||
label-position="top"
|
||||
:model="formOfSetting.customLink"
|
||||
:model="customLink"
|
||||
:rules="rules"
|
||||
size="small"
|
||||
>
|
||||
@@ -745,7 +745,7 @@
|
||||
{{ $T('SETTINGS_TIPS_PLACEHOLDER_EXTNAME') }}
|
||||
</div>
|
||||
<el-input
|
||||
v-model="formOfSetting.customLink"
|
||||
v-model="customLink.value"
|
||||
class="align-center"
|
||||
:autofocus="true"
|
||||
/>
|
||||
@@ -781,7 +781,6 @@
|
||||
>
|
||||
<el-form
|
||||
label-position="right"
|
||||
:model="formOfSetting.customLink"
|
||||
label-width="120px"
|
||||
>
|
||||
<el-form-item
|
||||
@@ -825,7 +824,6 @@
|
||||
>
|
||||
<el-form
|
||||
label-position="right"
|
||||
:model="formOfSetting.customLink"
|
||||
label-width="120px"
|
||||
>
|
||||
<el-form-item
|
||||
@@ -1378,27 +1376,26 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { compare } from 'compare-versions'
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { ElForm, ElMessage as $message, ElMessage, ElMessageBox, FormRules } from 'element-plus'
|
||||
import { Reading, Close, Edit, InfoFilled } from '@element-plus/icons-vue'
|
||||
import { IConfig } from 'piclist'
|
||||
import { computed, onBeforeMount, onBeforeUnmount, reactive, ref, toRaw, watch } from 'vue'
|
||||
import { computed, onBeforeMount, reactive, ref, toRaw, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import ImageProcessSetting from '@/components/ImageProcessSetting.vue'
|
||||
import { i18nManager, T as $T } from '@/i18n/index'
|
||||
import { buildInRenameFormatTable } from '@/manage/utils/common'
|
||||
import { SHORTKEY_PAGE } from '@/router/config'
|
||||
import { getConfig, saveConfig, sendRPC } from '@/utils/dataSender'
|
||||
import { getConfig, saveConfig } from '@/utils/dataSender'
|
||||
import { osGlobal, picBedGlobal, updatePicBedGlobal } from '@/utils/global'
|
||||
|
||||
import { PICGO_OPEN_FILE, PICGO_OPEN_DIRECTORY, OPEN_URL, GET_PICBEDS, HIDE_DOCK } from '#/events/constants'
|
||||
import { II18nLanguage, IRPCActionType, ISartMode } from '#/types/enum'
|
||||
import { enforceNumber } from '#/utils/common'
|
||||
import { configPaths, ISartModeValues } from '#/utils/configPaths'
|
||||
import { getLatestVersion } from '#/utils/getLatestVersion'
|
||||
|
||||
import pkg from 'root/package.json'
|
||||
import { invokeToMain, sendToMain } from '@/utils/common'
|
||||
import { invokeToMain, sendRPC, triggerRPC } from '@/utils/common'
|
||||
|
||||
const $router = useRouter()
|
||||
const activeName = ref<'system' | 'syncAndConfigure' | 'upload' | 'advanced' | 'upadte'>('system')
|
||||
@@ -1435,7 +1432,12 @@ const manualPageOpenList = [{
|
||||
value: 'browser'
|
||||
}]
|
||||
|
||||
const picBed = ref<IPicBedType[]>([])
|
||||
const showPicBedList = computed(() => picBedGlobal.value.map(item => {
|
||||
if (item.visible) {
|
||||
return item.name
|
||||
}
|
||||
return null
|
||||
}).filter(item => item) as string[])
|
||||
|
||||
const $customLink = ref<InstanceType<typeof ElForm> | null>(null)
|
||||
|
||||
@@ -1447,9 +1449,8 @@ const customLinkRule = (_: any, value: string, callback: (arg0?: Error) => void)
|
||||
}
|
||||
}
|
||||
|
||||
const formOfSetting = ref<IStringKeyMap>({
|
||||
const formOfSetting = ref<ISettingForm>({
|
||||
showUpdateTip: true,
|
||||
showPicBedList: [],
|
||||
autoStart: false,
|
||||
rename: false,
|
||||
autoRename: false,
|
||||
@@ -1483,29 +1484,33 @@ const formOfSetting = ref<IStringKeyMap>({
|
||||
webServerHost: '0.0.0.0',
|
||||
webServerPort: 37777,
|
||||
webServerPath: '',
|
||||
customLink: '',
|
||||
registry: '',
|
||||
proxy: '',
|
||||
mainWindowWidth: 1200,
|
||||
mainWindowHeight: 800
|
||||
})
|
||||
|
||||
const proxy = ref('')
|
||||
const formKeys = Object.keys(formOfSetting.value)
|
||||
const autoWatchKeys = ['showUpdateTip', 'autoImport', 'autoImportPicBed', 'useBuiltinClipboard', 'isAutoListenClipboard', 'deleteCloudFile', 'deleteLocalFile', 'rename', 'autoRename', 'enableWebServer', 'webServerHost', 'webServerPath', 'serverKey', 'uploadNotification', 'uploadResultNotification', 'autoCloseMainWindow', 'autoCloseMiniWindow', 'isCustomMiniIcon', 'c1nToken', 'yourlsDomain', 'yourlsSignature', 'cfWorkerHost', 'registry', 'proxy', 'autoCopy', 'encodeOutputURL', 'useShortUrl']
|
||||
|
||||
autoWatchKeys.forEach(key => {
|
||||
watch(() => formOfSetting.value[key], (value) => {
|
||||
saveConfig({
|
||||
[`settings.${key}`]: value
|
||||
const addWatch = () => {
|
||||
autoWatchKeys.forEach(key => {
|
||||
watch(() => formOfSetting.value[key as keyof ISettingForm], value => {
|
||||
saveConfig({
|
||||
[`settings.${key}`]: value
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
watch(proxy, (value) => {
|
||||
saveConfig({
|
||||
'picBed.proxy': value
|
||||
const addProxyWatch = () => {
|
||||
watch(proxy, (value) => {
|
||||
saveConfig({
|
||||
'picBed.proxy': value
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const valueToOptionItem = (value: any, list: { label: string, value: any }[]) => {
|
||||
return list.find(item => item.value === value) || list[0]
|
||||
@@ -1530,6 +1535,10 @@ const imageProcessDialogVisible = ref(false)
|
||||
|
||||
const rawPicGoSize = ref(false)
|
||||
|
||||
const customLink = reactive({
|
||||
value: ''
|
||||
})
|
||||
|
||||
const rules = reactive<FormRules>({
|
||||
value: [
|
||||
{ validator: customLinkRule, trigger: 'blur' }
|
||||
@@ -1592,7 +1601,6 @@ function confirmSyncSetting () {
|
||||
|
||||
const version = pkg.version
|
||||
const latestVersion = ref('')
|
||||
const os = ref('')
|
||||
|
||||
const needUpdate = computed(() => {
|
||||
if (latestVersion.value) {
|
||||
@@ -1602,9 +1610,6 @@ const needUpdate = computed(() => {
|
||||
})
|
||||
|
||||
onBeforeMount(() => {
|
||||
os.value = process.platform
|
||||
sendToMain(GET_PICBEDS)
|
||||
ipcRenderer.on(GET_PICBEDS, getPicBeds)
|
||||
initData()
|
||||
})
|
||||
|
||||
@@ -1613,7 +1618,7 @@ async function initData () {
|
||||
const settings = config.settings || {}
|
||||
const picBed = config.picBed
|
||||
formKeys.forEach(key => {
|
||||
formOfSetting.value[key] = settings[key] ?? formOfSetting.value[key]
|
||||
(formOfSetting.value as any)[key as keyof ISettingForm] = settings[key] ?? formOfSetting.value[key as keyof ISettingForm]
|
||||
})
|
||||
formOfSetting.value.logLevel = initArray(settings.logLevel || [], ['all'])
|
||||
formOfSetting.value.autoImportPicBed = initArray(settings.autoImportPicBed || [], [])
|
||||
@@ -1621,6 +1626,7 @@ async function initData () {
|
||||
currentStartMode.value = valueToOptionItem(settings.startMode || ISartMode.QUIET, startModeList)
|
||||
currentManualPageOpen.value = valueToOptionItem(settings.manualPageOpen || 'window', manualPageOpenList)
|
||||
currentShortUrlServer.value = valueToOptionItem(settings.shortUrlServer || 'c1n', shortUrlServerList)
|
||||
customLink.value = settings.customLink || ''
|
||||
proxy.value = picBed.proxy || ''
|
||||
server.value = settings.server || {
|
||||
port: 36677,
|
||||
@@ -1648,6 +1654,8 @@ async function initData () {
|
||||
interval: 60
|
||||
}
|
||||
formOfSetting.value.logFileSizeLimit = enforceNumber(settings.logFileSizeLimit) || 10
|
||||
addProxyWatch()
|
||||
addWatch()
|
||||
}
|
||||
|
||||
function initArray (arrayT: string | string[], defaultValue: string[]) {
|
||||
@@ -1661,18 +1669,8 @@ function initArray (arrayT: string | string[], defaultValue: string[]) {
|
||||
return arrayT
|
||||
}
|
||||
|
||||
function getPicBeds (_: Event, picBeds: IPicBedType[]) {
|
||||
picBed.value = picBeds
|
||||
formOfSetting.value.showPicBedList = picBed.value.map(item => {
|
||||
if (item.visible) {
|
||||
return item.name
|
||||
}
|
||||
return null
|
||||
}).filter(item => item) as string[]
|
||||
}
|
||||
|
||||
function openFile (file: string) {
|
||||
sendToMain(PICGO_OPEN_FILE, file)
|
||||
sendRPC(IRPCActionType.PICLIST_OPEN_FILE, file)
|
||||
}
|
||||
|
||||
function handleManualPageOpenChange (val: string) {
|
||||
@@ -1682,7 +1680,7 @@ function handleManualPageOpenChange (val: string) {
|
||||
}
|
||||
|
||||
function openDirectory (directory?: string, inStorePath = true) {
|
||||
sendToMain(PICGO_OPEN_DIRECTORY, directory, inStorePath)
|
||||
sendRPC(IRPCActionType.PICLIST_OPEN_DIRECTORY, directory, inStorePath)
|
||||
}
|
||||
|
||||
function openLogSetting () {
|
||||
@@ -1691,13 +1689,13 @@ function openLogSetting () {
|
||||
|
||||
async function cancelCustomLink () {
|
||||
customLinkVisible.value = false
|
||||
formOfSetting.value.customLink = await getConfig<string>(configPaths.settings.customLink) || ''
|
||||
customLink.value = await getConfig<string>(configPaths.settings.customLink) || ''
|
||||
}
|
||||
|
||||
function confirmCustomLink () {
|
||||
$customLink.value?.validate((valid: boolean) => {
|
||||
if (valid) {
|
||||
saveConfig(configPaths.settings.customLink, formOfSetting.value.customLink)
|
||||
saveConfig(configPaths.settings.customLink, customLink.value)
|
||||
customLinkVisible.value = false
|
||||
}
|
||||
})
|
||||
@@ -1721,17 +1719,21 @@ function handleSaveAdvancedRename () {
|
||||
}
|
||||
|
||||
function handleMigrateFromPicGo () {
|
||||
ElMessageBox.confirm($T('SETTINGS_MIGRATE_FROM_PICGO_CONTENT'), $T('SETTINGS_MIGRATE_FROM_PICGO_TITLE'), {
|
||||
confirmButtonText: $T('CONFIRM'),
|
||||
cancelButtonText: $T('CANCEL'),
|
||||
type: 'warning',
|
||||
center: true
|
||||
}).then(() => {
|
||||
ipcRenderer.invoke('migrateFromPicGo').then(() => {
|
||||
ElMessage.success($T('SETTINGS_MIGRATE_FROM_PICGO_SUCCESS'))
|
||||
}).catch(() => {
|
||||
ElMessage.error($T('SETTINGS_MIGRATE_FROM_PICGO_FAILED'))
|
||||
})
|
||||
ElMessageBox.confirm(
|
||||
$T('SETTINGS_MIGRATE_FROM_PICGO_CONTENT'),
|
||||
$T('SETTINGS_MIGRATE_FROM_PICGO_TITLE'), {
|
||||
confirmButtonText: $T('CONFIRM'),
|
||||
cancelButtonText: $T('CANCEL'),
|
||||
type: 'warning',
|
||||
center: true
|
||||
}).then(() => {
|
||||
triggerRPC<boolean>(IRPCActionType.CONFIGURE_MIGRATE_FROM_PICGO)
|
||||
.then(() => {
|
||||
ElMessage.success($T('SETTINGS_MIGRATE_FROM_PICGO_SUCCESS'))
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error($T('SETTINGS_MIGRATE_FROM_PICGO_FAILED'))
|
||||
})
|
||||
}).catch(() => {
|
||||
return false
|
||||
})
|
||||
@@ -1744,11 +1746,11 @@ function handleHideDockChange (val: ICheckBoxValueType) {
|
||||
return
|
||||
}
|
||||
saveConfig(configPaths.settings.isHideDock, val)
|
||||
sendToMain(HIDE_DOCK, val)
|
||||
sendRPC(IRPCActionType.HIDE_DOCK, val)
|
||||
}
|
||||
|
||||
function handleShowPicBedListChange (val: ICheckBoxValueType[]) {
|
||||
const list = picBed.value.map(item => {
|
||||
const list = picBedGlobal.value.map(item => {
|
||||
if (!val.includes(item.name)) {
|
||||
item.visible = false
|
||||
} else {
|
||||
@@ -1759,12 +1761,12 @@ function handleShowPicBedListChange (val: ICheckBoxValueType[]) {
|
||||
saveConfig({
|
||||
[configPaths.picBed.list]: list
|
||||
})
|
||||
sendToMain(GET_PICBEDS)
|
||||
updatePicBedGlobal()
|
||||
}
|
||||
|
||||
function handleAutoStartChange (val: ICheckBoxValueType) {
|
||||
saveConfig(configPaths.settings.autoStart, val)
|
||||
sendToMain('autoStart', val)
|
||||
sendRPC(IRPCActionType.PICLIST_AUTO_START, val)
|
||||
}
|
||||
|
||||
function compareVersion2Update (current: string, latest: string): boolean {
|
||||
@@ -1793,9 +1795,9 @@ function handleWebServerPortChange (val?: number, _?: number) {
|
||||
|
||||
function confirmWebServerSetting () {
|
||||
if (formOfSetting.value.enableWebServer) {
|
||||
sendToMain('restartWebServer')
|
||||
sendRPC(IRPCActionType.ADVANCED_RESTART_WEB_SERVER)
|
||||
} else {
|
||||
sendToMain('stopWebServer')
|
||||
sendRPC(IRPCActionType.ADVANCED_STOP_WEB_SERVER)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1822,7 +1824,7 @@ async function confirmWindowSize () {
|
||||
|
||||
function handleMiniWindowOntop (val: ICheckBoxValueType) {
|
||||
saveConfig(configPaths.settings.miniWindowOntop, val)
|
||||
ipcRenderer.send('miniWindowOntop', val)
|
||||
sendRPC(IRPCActionType.MINI_WINDOW_ON_TOP, val)
|
||||
}
|
||||
|
||||
async function handleMiniIconPath (_: Event) {
|
||||
@@ -1830,7 +1832,7 @@ async function handleMiniIconPath (_: Event) {
|
||||
if (result && result[0]) {
|
||||
formOfSetting.value.customMiniIcon = result[0]
|
||||
saveConfig(configPaths.settings.customMiniIcon, formOfSetting.value.customMiniIcon)
|
||||
ipcRenderer.send('updateMiniIcon', formOfSetting.value.customMiniIcon)
|
||||
sendRPC(IRPCActionType.UPDATE_MINI_WINDOW_ICON, formOfSetting.value.customMiniIcon)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1879,40 +1881,40 @@ function syncMessage (failed: number, taskType: 'UPLOAD' | 'DOWNLOAD') {
|
||||
|
||||
const syncTaskList = [
|
||||
{
|
||||
task: 'uploadCommonConfig',
|
||||
task: IRPCActionType.CONFIGURE_UPLOAD_COMMON_CONFIG,
|
||||
label: $T('SETTINGS_SYNC_COMMON_CONFIG'),
|
||||
number: 2
|
||||
},
|
||||
{
|
||||
task: 'uploadManageConfig',
|
||||
task: IRPCActionType.CONFIGURE_UPLOAD_MANAGE_CONFIG,
|
||||
label: $T('SETTINGS_SYNC_MANAGE_CONFIG'),
|
||||
number: 2
|
||||
},
|
||||
{
|
||||
task: 'uploadAllConfig',
|
||||
task: IRPCActionType.CONFIGURE_UPLOAD_ALL_CONFIG,
|
||||
label: $T('SETTINGS_SYNC_UPLOAD_ALL'),
|
||||
number: 4
|
||||
},
|
||||
{
|
||||
task: 'downloadCommonConfig',
|
||||
task: IRPCActionType.CONFIGURE_DOWNLOAD_COMMON_CONFIG,
|
||||
label: $T('SETTINGS_SYNC_COMMON_CONFIG'),
|
||||
number: 2
|
||||
},
|
||||
{
|
||||
task: 'downloadManageConfig',
|
||||
task: IRPCActionType.CONFIGURE_DOWNLOAD_MANAGE_CONFIG,
|
||||
label: $T('SETTINGS_SYNC_MANAGE_CONFIG'),
|
||||
number: 2
|
||||
},
|
||||
{
|
||||
task: 'downloadAllConfig',
|
||||
task: IRPCActionType.CONFIGURE_DOWNLOAD_ALL_CONFIG,
|
||||
label: $T('SETTINGS_SYNC_DOWNLOAD_ALL'),
|
||||
number: 4
|
||||
}
|
||||
]
|
||||
|
||||
async function syncTaskFn (task: string, number: number) {
|
||||
const failed = number - await invokeToMain(task)
|
||||
syncMessage(failed, task.includes('upload') ? 'UPLOAD' : 'DOWNLOAD')
|
||||
async function syncTaskFn (task: IRPCActionType, number: number) {
|
||||
const failed = number - (await triggerRPC<number>(task) || 0)
|
||||
syncMessage(failed, task.includes('UPLOAD') ? 'UPLOAD' : 'DOWNLOAD')
|
||||
}
|
||||
|
||||
function confirmServerSetting () {
|
||||
@@ -1921,7 +1923,7 @@ function confirmServerSetting () {
|
||||
[configPaths.settings.server]: server.value
|
||||
})
|
||||
serverVisible.value = false
|
||||
sendToMain('updateServer')
|
||||
sendRPC(IRPCActionType.ADVANCED_UPDATE_SERVER)
|
||||
}
|
||||
|
||||
async function cancelServerSetting () {
|
||||
@@ -1959,7 +1961,7 @@ function handleLanguageChange (val: string) {
|
||||
saveConfig({
|
||||
[configPaths.settings.language]: val
|
||||
})
|
||||
sendToMain(GET_PICBEDS)
|
||||
updatePicBedGlobal()
|
||||
}
|
||||
|
||||
function handleStartModeChange (val: ISartModeValues) {
|
||||
@@ -1981,7 +1983,7 @@ async function goConfigPage () {
|
||||
const url = lang === II18nLanguage.ZH_CN
|
||||
? 'https://piclist.cn/configure.html'
|
||||
: 'https://piclist.cn/en/configure.html'
|
||||
sendToMain(OPEN_URL, url)
|
||||
sendRPC(IRPCActionType.OPEN_URL, url)
|
||||
}
|
||||
|
||||
function goShortCutPage () {
|
||||
@@ -1990,10 +1992,6 @@ function goShortCutPage () {
|
||||
})
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
ipcRenderer.removeListener(GET_PICBEDS, getPicBeds)
|
||||
})
|
||||
|
||||
</script>
|
||||
<script lang="ts">
|
||||
export default {
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
>
|
||||
<div
|
||||
class="plugin-item"
|
||||
:class="{ 'darwin': os === 'darwin' }"
|
||||
:class="{ 'darwin': osGlobal === 'darwin' }"
|
||||
>
|
||||
<div
|
||||
v-if="!item.gui"
|
||||
@@ -241,16 +241,14 @@ import { computed, ref, onBeforeMount, onBeforeUnmount, watch, onMounted, reacti
|
||||
|
||||
import ConfigForm from '@/components/ConfigFormForPlugin.vue'
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import { sendToMain } from '@/utils/common'
|
||||
import { getConfig, saveConfig, sendRPC } from '@/utils/dataSender'
|
||||
import { sendRPC } from '@/utils/common'
|
||||
import { getConfig, saveConfig } from '@/utils/dataSender'
|
||||
import { osGlobal, updatePicBedGlobal } from '@/utils/global'
|
||||
|
||||
import {
|
||||
OPEN_URL,
|
||||
PICGO_CONFIG_PLUGIN,
|
||||
PICGO_HANDLE_PLUGIN_ING,
|
||||
PICGO_TOGGLE_PLUGIN,
|
||||
SHOW_PLUGIN_PAGE_MENU,
|
||||
GET_PICBEDS,
|
||||
PICGO_HANDLE_PLUGIN_DONE
|
||||
} from '#/events/constants'
|
||||
import { IRPCActionType } from '#/types/enum'
|
||||
@@ -272,7 +270,6 @@ const pluginListToolTip = $T('PLUGIN_LIST')
|
||||
const importLocalPluginToolTip = $T('PLUGIN_IMPORT_LOCAL')
|
||||
const updateAllToolTip = $T('PLUGIN_UPDATE_ALL')
|
||||
// const id = ref('')
|
||||
const os = ref('')
|
||||
const defaultLogo = ref(`this.src="file://${__static.replace(/\\/g, '/')}/roundLogo.png"`)
|
||||
const $configForm = ref<InstanceType<typeof ConfigForm> | null>(null)
|
||||
const npmSearchText = computed(() => {
|
||||
@@ -314,7 +311,6 @@ async function getLatestVersionOfPlugIn (pluginName: string) {
|
||||
}
|
||||
|
||||
onBeforeMount(async () => {
|
||||
os.value = process.platform
|
||||
ipcRenderer.on('hideLoading', () => {
|
||||
loading.value = false
|
||||
})
|
||||
@@ -353,7 +349,7 @@ onBeforeMount(async () => {
|
||||
item.ing = false
|
||||
item.hasInstall = true
|
||||
}
|
||||
getPicBeds()
|
||||
updatePicBedGlobal()
|
||||
})
|
||||
handleReload()
|
||||
getPluginList()
|
||||
@@ -368,7 +364,7 @@ onBeforeMount(async () => {
|
||||
if (item.config.uploader.name) {
|
||||
handleRestoreState('uploader', item.config.uploader.name)
|
||||
}
|
||||
getPicBeds()
|
||||
updatePicBedGlobal()
|
||||
}
|
||||
return item.fullName !== plugin
|
||||
})
|
||||
@@ -392,7 +388,7 @@ onBeforeMount(async () => {
|
||||
const plugin = pluginList.value.find(item => item.fullName === fullName)
|
||||
if (plugin) {
|
||||
plugin.enabled = enabled
|
||||
getPicBeds()
|
||||
updatePicBedGlobal()
|
||||
needReload.value = true
|
||||
}
|
||||
})
|
||||
@@ -402,7 +398,7 @@ onBeforeMount(async () => {
|
||||
})
|
||||
|
||||
async function buildContextMenu (plugin: IPicGoPlugin) {
|
||||
sendToMain(SHOW_PLUGIN_PAGE_MENU, plugin)
|
||||
sendRPC(IRPCActionType.SHOW_PLUGIN_PAGE_MENU, plugin)
|
||||
}
|
||||
|
||||
function handleResize () {
|
||||
@@ -417,11 +413,7 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
function getPluginList () {
|
||||
sendToMain('getPluginList')
|
||||
}
|
||||
|
||||
function getPicBeds () {
|
||||
sendToMain(GET_PICBEDS)
|
||||
sendRPC(IRPCActionType.PLUGIN_GET_LIST)
|
||||
}
|
||||
|
||||
function installPlugin (item: IPicGoPlugin) {
|
||||
@@ -432,13 +424,13 @@ function installPlugin (item: IPicGoPlugin) {
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
item.ing = true
|
||||
sendToMain('installPlugin', item.fullName)
|
||||
sendRPC(IRPCActionType.PLUGIN_INSTALL, item.fullName)
|
||||
}).catch(() => {
|
||||
console.log('Install canceled')
|
||||
})
|
||||
} else {
|
||||
item.ing = true
|
||||
sendToMain('installPlugin', item.fullName)
|
||||
sendRPC(IRPCActionType.PLUGIN_INSTALL, item.fullName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,21 +550,21 @@ async function handleRestoreState (item: string, name: string) {
|
||||
|
||||
function openHomepage (url: string) {
|
||||
if (url) {
|
||||
sendToMain(OPEN_URL, url)
|
||||
sendRPC(IRPCActionType.OPEN_URL, url)
|
||||
}
|
||||
}
|
||||
|
||||
function goAwesomeList () {
|
||||
sendToMain(OPEN_URL, 'https://github.com/PicGo/Awesome-PicGo')
|
||||
sendRPC(IRPCActionType.OPEN_URL, 'https://github.com/PicGo/Awesome-PicGo')
|
||||
}
|
||||
|
||||
function handleImportLocalPlugin () {
|
||||
sendToMain('importLocalPlugin')
|
||||
sendRPC(IRPCActionType.PLUGIN_IMPORT_LOCAL)
|
||||
loading.value = true
|
||||
}
|
||||
|
||||
function handleUpdateAllPlugin () {
|
||||
sendToMain('updateAllPlugin', toRaw(pluginNameList.value))
|
||||
sendRPC(IRPCActionType.PLUGIN_UPDATE_ALL, toRaw(pluginNameList.value))
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
@@ -118,16 +118,15 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ipcRenderer, IpcRendererEvent } from 'electron'
|
||||
import { onBeforeUnmount, onBeforeMount, ref, watch } from 'vue'
|
||||
|
||||
import { T as $T } from '@/i18n'
|
||||
import { sendToMain } from '@/utils/common'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
import { getConfig } from '@/utils/dataSender'
|
||||
import keyBinding from '@/utils/key-binding'
|
||||
|
||||
import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants'
|
||||
import { configPaths } from '#/utils/configPaths'
|
||||
import { IRPCActionType } from '#/types/enum'
|
||||
|
||||
const list = ref<IShortKeyConfig[]>([])
|
||||
const keyBindingVisible = ref(false)
|
||||
@@ -146,7 +145,7 @@ onBeforeMount(async () => {
|
||||
})
|
||||
|
||||
watch(keyBindingVisible, (val: boolean) => {
|
||||
sendToMain(TOGGLE_SHORTKEY_MODIFIED_MODE, val)
|
||||
sendRPC(IRPCActionType.SHORTKEY_TOGGLE_SHORTKEY_MODIFIED_MODE, val)
|
||||
})
|
||||
|
||||
function calcOrigin (item: string) {
|
||||
@@ -161,7 +160,7 @@ function calcOriginShowName (item: string) {
|
||||
function toggleEnable (item: IShortKeyConfig) {
|
||||
const status = !item.enable
|
||||
item.enable = status
|
||||
sendToMain('bindOrUnbindShortKey', item, item.from)
|
||||
sendRPC(IRPCActionType.SHORTKEY_BIND_OR_UNBIND, item, item.from)
|
||||
}
|
||||
|
||||
function keyDetect (event: KeyboardEvent) {
|
||||
@@ -184,24 +183,24 @@ async function confirmKeyBinding () {
|
||||
const oldKey = await getConfig<string>(`settings.shortKey.${command.value}.key`)
|
||||
const config = Object.assign({}, list.value[currentIndex.value])
|
||||
config.key = shortKey.value
|
||||
sendToMain('updateShortKey', config, oldKey, config.from)
|
||||
ipcRenderer.once('updateShortKeyResponse', (_: IpcRendererEvent, result) => {
|
||||
if (result) {
|
||||
keyBindingVisible.value = false
|
||||
list.value[currentIndex.value].key = shortKey.value
|
||||
}
|
||||
})
|
||||
const result = await triggerRPC<boolean>(IRPCActionType.SHORTKEY_UPDATE, config, oldKey, config.from)
|
||||
if (result) {
|
||||
keyBindingVisible.value = false
|
||||
list.value[currentIndex.value].key = shortKey.value
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
sendToMain(TOGGLE_SHORTKEY_MODIFIED_MODE, false)
|
||||
sendRPC(IRPCActionType.SHORTKEY_TOGGLE_SHORTKEY_MODIFIED_MODE, false)
|
||||
})
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'ShortkeyPage'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang='stylus'>
|
||||
#shortcut-page
|
||||
.shortcut-page-table-border
|
||||
|
||||
@@ -103,9 +103,9 @@ import ToolboxStatusIcon from '@/components/ToolboxStatusIcon.vue'
|
||||
import ToolboxHandler from '@/components/ToolboxHandler.vue'
|
||||
import { useIPC } from '@/hooks/useIPC'
|
||||
import { T as $T } from '@/i18n'
|
||||
import { sendRPC, triggerRPC } from '@/utils/dataSender'
|
||||
|
||||
import { IToolboxItemType, IToolboxItemCheckStatus, IRPCActionType } from '#/types/enum'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
|
||||
const $confirm = ElMessageBox.confirm
|
||||
const defaultLogo = ref(`file://${__static.replace(/\\/g, '/')}/roundLogo.png`)
|
||||
|
||||
@@ -67,13 +67,12 @@ import { reactive, ref, onBeforeUnmount, onBeforeMount } from 'vue'
|
||||
import { IResult } from '@picgo/store/dist/types'
|
||||
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import { sendToMain } from '@/utils/common'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
import { getConfig } from '@/utils/dataSender'
|
||||
|
||||
import $$db from '@/utils/db'
|
||||
|
||||
import { IPasteStyle, IWindowList } from '#/types/enum'
|
||||
import { OPEN_WINDOW } from '#/events/constants'
|
||||
import { IPasteStyle, IRPCActionType, IWindowList } from '#/types/enum'
|
||||
import { handleUrlEncode } from '#/utils/common'
|
||||
import { configPaths } from '#/utils/configPaths'
|
||||
|
||||
@@ -87,11 +86,11 @@ const clipboardFiles = ref<ImgInfo[]>([])
|
||||
const uploadFlag = ref(false)
|
||||
|
||||
function openSettingWindow () {
|
||||
sendToMain(OPEN_WINDOW, IWindowList.SETTING_WINDOW)
|
||||
sendRPC(IRPCActionType.OPEN_WINDOW, IWindowList.SETTING_WINDOW)
|
||||
}
|
||||
|
||||
async function getData () {
|
||||
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
|
||||
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 }))!.data
|
||||
}
|
||||
|
||||
const formatCustomLink = (customLink: string, item: ImgInfo) => {
|
||||
@@ -134,7 +133,7 @@ async function pasteTemplate (style: IPasteStyle, item: ImgInfo, customLink: str
|
||||
}
|
||||
const useShortUrl = await getConfig(configPaths.settings.useShortUrl) || false
|
||||
if (useShortUrl) {
|
||||
url = await ipcRenderer.invoke('getShortUrl', url)
|
||||
url = await triggerRPC<string>(IRPCActionType.TRAY_GET_SHORT_URL, url) || url
|
||||
}
|
||||
notification.body = url
|
||||
const _customLink = customLink || ''
|
||||
@@ -167,7 +166,7 @@ function uploadClipboardFiles () {
|
||||
return
|
||||
}
|
||||
uploadFlag.value = true
|
||||
sendToMain('uploadClipboardFiles')
|
||||
sendRPC(IRPCActionType.TRAY_UPLOAD_CLIPBOARD_FILES)
|
||||
}
|
||||
|
||||
onBeforeMount(() => {
|
||||
@@ -178,13 +177,13 @@ onBeforeMount(() => {
|
||||
const item = _files[i]
|
||||
await $$db.insert(item)
|
||||
}
|
||||
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
|
||||
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 }))!.data
|
||||
})
|
||||
ipcRenderer.on('clipboardFiles', (_: Event, files: ImgInfo[]) => {
|
||||
clipboardFiles.value = files
|
||||
})
|
||||
ipcRenderer.on('uploadFiles', async () => {
|
||||
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
|
||||
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 }))!.data
|
||||
uploadFlag.value = false
|
||||
})
|
||||
ipcRenderer.on('updateFiles', () => {
|
||||
|
||||
@@ -164,14 +164,13 @@ import ImageProcessSetting from '@/components/ImageProcessSetting.vue'
|
||||
import { T as $T } from '@/i18n'
|
||||
import { PICBEDS_PAGE } from '@/router/config'
|
||||
import $bus from '@/utils/bus'
|
||||
import { sendToMain } from '@/utils/common'
|
||||
import { getConfig, saveConfig, triggerRPC } from '@/utils/dataSender'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
import { getConfig, saveConfig } from '@/utils/dataSender'
|
||||
import { picBedGlobal, updatePicBedGlobal } from '@/utils/global'
|
||||
|
||||
import {
|
||||
SHOW_INPUT_BOX,
|
||||
SHOW_INPUT_BOX_RESPONSE,
|
||||
SHOW_UPLOAD_PAGE_MENU,
|
||||
GET_PICBEDS
|
||||
SHOW_INPUT_BOX_RESPONSE
|
||||
} from '#/events/constants'
|
||||
import { IPasteStyle, IRPCActionType } from '#/types/enum'
|
||||
import {
|
||||
@@ -188,7 +187,6 @@ const progress = ref(0)
|
||||
const showProgress = ref(false)
|
||||
const showError = ref(false)
|
||||
const pasteStyle = ref('')
|
||||
const picBed = ref<IPicBedType[]>([])
|
||||
const picBedName = ref('')
|
||||
const picBedConfigName = ref('')
|
||||
|
||||
@@ -200,7 +198,12 @@ const pasteFormatList = ref({
|
||||
[IPasteStyle.CUSTOM]: ''
|
||||
})
|
||||
|
||||
watch(picBedGlobal, () => {
|
||||
getDefaultPicBed()
|
||||
})
|
||||
|
||||
onBeforeMount(() => {
|
||||
updatePicBedGlobal()
|
||||
ipcRenderer.on('uploadProgress', (_event: IpcRendererEvent, _progress: number) => {
|
||||
if (_progress !== -1) {
|
||||
showProgress.value = true
|
||||
@@ -216,8 +219,6 @@ onBeforeMount(() => {
|
||||
ipcRenderer.on('syncPicBed', () => {
|
||||
getDefaultPicBed()
|
||||
})
|
||||
sendToMain(GET_PICBEDS)
|
||||
ipcRenderer.on(GET_PICBEDS, getPicBeds)
|
||||
$bus.on(SHOW_INPUT_BOX_RESPONSE, handleInputBoxValue)
|
||||
})
|
||||
|
||||
@@ -243,7 +244,7 @@ async function handlePicBedNameClick (_picBedName: string, picBedConfigName: str
|
||||
const formatedpicBedConfigName = picBedConfigName || 'Default'
|
||||
const currentPicBed = await getConfig<string>(configPaths.picBed.current)
|
||||
const currentPicBedConfig = await getConfig<any[]>(`uploader.${currentPicBed}`) as any || {}
|
||||
const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, currentPicBed)
|
||||
const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.PICBED_GET_CONFIG_LIST, currentPicBed)
|
||||
const currentConfigList = configList?.configList ?? []
|
||||
const config = currentConfigList.find((item: any) => item._configName === formatedpicBedConfigName)
|
||||
$router.push({
|
||||
@@ -262,7 +263,6 @@ onBeforeUnmount(() => {
|
||||
$bus.off(SHOW_INPUT_BOX_RESPONSE)
|
||||
ipcRenderer.removeAllListeners('uploadProgress')
|
||||
ipcRenderer.removeAllListeners('syncPicBed')
|
||||
ipcRenderer.removeListener(GET_PICBEDS, getPicBeds)
|
||||
})
|
||||
|
||||
function onDrop (e: DragEvent) {
|
||||
@@ -279,7 +279,7 @@ function onDrop (e: DragEvent) {
|
||||
} else if (items[0].type === 'text/plain') {
|
||||
const str = e.dataTransfer!.getData(items[0].type)
|
||||
if (isUrl(str)) {
|
||||
sendToMain('uploadChoosedFiles', [{ path: str }])
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, [{ path: str }])
|
||||
} else {
|
||||
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
|
||||
}
|
||||
@@ -293,7 +293,7 @@ function handleURLDrag (items: DataTransferItemList, dataTransfer: DataTransfer)
|
||||
const urlString = dataTransfer.getData(items[1].type)
|
||||
const urlMatch = urlString.match(/<img.*src="(.*?)"/)
|
||||
if (urlMatch) {
|
||||
sendToMain('uploadChoosedFiles', [
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, [
|
||||
{
|
||||
path: urlMatch[1]
|
||||
}
|
||||
@@ -321,7 +321,7 @@ function ipcSendFiles (files: FileList) {
|
||||
}
|
||||
sendFiles.push(obj)
|
||||
})
|
||||
sendToMain('uploadChoosedFiles', sendFiles)
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, sendFiles)
|
||||
}
|
||||
|
||||
async function getPasteStyle () {
|
||||
@@ -346,7 +346,7 @@ function handlePasteStyleChange (val: string | number | boolean | undefined) {
|
||||
}
|
||||
|
||||
function uploadClipboardFiles () {
|
||||
sendToMain('uploadClipboardFilesFromUploadPage')
|
||||
sendRPC(IRPCActionType.UPLOAD_CLIPBOARD_FILES_FROM_UPLOAD_PAGE)
|
||||
}
|
||||
|
||||
async function uploadURLFiles () {
|
||||
@@ -361,7 +361,7 @@ async function uploadURLFiles () {
|
||||
function handleInputBoxValue (val: string) {
|
||||
if (val === '') return
|
||||
if (isUrl(val)) {
|
||||
sendToMain('uploadChoosedFiles', [{
|
||||
sendRPC(IRPCActionType.UPLOAD_CHOOSED_FILES, [{
|
||||
path: val
|
||||
}])
|
||||
} else {
|
||||
@@ -371,7 +371,7 @@ function handleInputBoxValue (val: string) {
|
||||
|
||||
async function getDefaultPicBed () {
|
||||
const currentPicBed = await getConfig<string>(configPaths.picBed.current)
|
||||
picBed.value.forEach(item => {
|
||||
picBedGlobal.value.forEach(item => {
|
||||
if (item.type === currentPicBed) {
|
||||
picBedName.value = item.name
|
||||
}
|
||||
@@ -379,20 +379,17 @@ async function getDefaultPicBed () {
|
||||
picBedConfigName.value = await getConfig<string>(`picBed.${currentPicBed}._configName`) || ''
|
||||
}
|
||||
|
||||
function getPicBeds (_event: Event, picBeds: IPicBedType[]) {
|
||||
picBed.value = picBeds
|
||||
getDefaultPicBed()
|
||||
}
|
||||
|
||||
async function handleChangePicBed () {
|
||||
sendToMain(SHOW_UPLOAD_PAGE_MENU)
|
||||
sendRPC(IRPCActionType.SHOW_UPLOAD_PAGE_MENU)
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'UploadPage'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang='stylus'>
|
||||
.view-title
|
||||
display flex
|
||||
|
||||
@@ -94,11 +94,10 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import dayjs from 'dayjs'
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { Edit, Delete, Plus } from '@element-plus/icons-vue'
|
||||
import { onBeforeMount, ref } from 'vue'
|
||||
import { useRouter, useRoute, onBeforeRouteUpdate } from 'vue-router'
|
||||
import { saveConfig, triggerRPC } from '@/utils/dataSender'
|
||||
import { saveConfig } from '@/utils/dataSender'
|
||||
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import { useStore } from '@/hooks/useStore'
|
||||
@@ -106,6 +105,7 @@ import { PICBEDS_PAGE, UPLOADER_CONFIG_PAGE } from '@/router/config'
|
||||
|
||||
import { IRPCActionType } from '#/types/enum'
|
||||
import { configPaths } from '#/utils/configPaths'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
|
||||
const $router = useRouter()
|
||||
const $route = useRoute()
|
||||
@@ -116,8 +116,10 @@ const defaultConfigId = ref('')
|
||||
const store = useStore()
|
||||
|
||||
async function selectItem (id: string) {
|
||||
await triggerRPC<void>(IRPCActionType.SELECT_UPLOADER, type.value, id)
|
||||
ipcRenderer.send('setTrayToolTip', `${type.value} ${curConfigList.value.find(item => item._id === id)?._configName || ''}`)
|
||||
await triggerRPC<void>(IRPCActionType.UPLOADER_SELECT, type.value, id)
|
||||
if (store?.state.defaultPicBed === type.value) {
|
||||
sendRPC(IRPCActionType.TRAY_SET_TOOL_TIP, `${type.value} ${curConfigList.value.find(item => item._id === id)?._configName || ''}`)
|
||||
}
|
||||
defaultConfigId.value = id
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ onBeforeMount(() => {
|
||||
})
|
||||
|
||||
async function getCurrentConfigList () {
|
||||
const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, type.value)
|
||||
const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.PICBED_GET_CONFIG_LIST, type.value)
|
||||
curConfigList.value = configList?.configList ?? []
|
||||
defaultConfigId.value = configList?.defaultId ?? ''
|
||||
}
|
||||
@@ -158,7 +160,7 @@ function formatTime (time: number): string {
|
||||
}
|
||||
|
||||
async function deleteConfig (id: string) {
|
||||
const res = await triggerRPC<IUploaderConfigItem | undefined>(IRPCActionType.DELETE_PICBED_CONFIG, type.value, id)
|
||||
const res = await triggerRPC<IUploaderConfigItem>(IRPCActionType.PICBED_DELETE_CONFIG, type.value, id)
|
||||
if (!res) return
|
||||
curConfigList.value = res.configList
|
||||
defaultConfigId.value = res.defaultId
|
||||
@@ -182,7 +184,7 @@ function setDefaultPicBed (type: string) {
|
||||
|
||||
store?.setDefaultPicBed(type)
|
||||
const currentConfigName = curConfigList.value.find(item => item._id === defaultConfigId.value)?._configName
|
||||
ipcRenderer.send('setTrayToolTip', `${type} ${currentConfigName || ''}`)
|
||||
sendRPC(IRPCActionType.TRAY_SET_TOOL_TIP, `${type} ${currentConfigName || ''}`)
|
||||
const successNotification = new Notification($T('SETTINGS_DEFAULT_PICBED'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
})
|
||||
|
||||
@@ -99,21 +99,18 @@
|
||||
<script lang="ts" setup>
|
||||
import dayjs from 'dayjs'
|
||||
import {
|
||||
clipboard,
|
||||
ipcRenderer,
|
||||
IpcRendererEvent
|
||||
clipboard
|
||||
} from 'electron'
|
||||
import { ElDropdown, ElMessage } from 'element-plus'
|
||||
import { Link } from '@element-plus/icons-vue'
|
||||
import { ref, onBeforeUnmount, onBeforeMount } from 'vue'
|
||||
import { ref, onBeforeMount } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import ConfigForm from '@/components/ConfigForm.vue'
|
||||
import { T as $T } from '@/i18n/index'
|
||||
import { sendToMain } from '@/utils/common'
|
||||
import { getConfig, triggerRPC } from '@/utils/dataSender'
|
||||
import { sendRPC, triggerRPC } from '@/utils/common'
|
||||
import { getConfig } from '@/utils/dataSender'
|
||||
|
||||
import { OPEN_URL } from '#/events/constants'
|
||||
import { II18nLanguage, IRPCActionType } from '#/types/enum'
|
||||
import { configPaths } from '#/utils/configPaths'
|
||||
import { picBedManualUrlList } from '#/utils/static'
|
||||
@@ -129,15 +126,14 @@ const $dropdown = ref<InstanceType<typeof ElDropdown> | null>(null)
|
||||
type.value = $route.params.type as string
|
||||
|
||||
onBeforeMount(async () => {
|
||||
sendToMain('getPicBedConfig', $route.params.type)
|
||||
ipcRenderer.on('getPicBedConfig', getPicBeds)
|
||||
await getPicBeds()
|
||||
await getPicBedConfigList()
|
||||
})
|
||||
|
||||
const handleConfirm = async () => {
|
||||
const result = (await $configForm.value?.validate()) || false
|
||||
if (result !== false) {
|
||||
await triggerRPC<void>(IRPCActionType.UPDATE_UPLOADER_CONFIG, type.value, result?._id, result)
|
||||
await triggerRPC<void>(IRPCActionType.UPLOADER_UPDATE_CONFIG, type.value, result?._id, result)
|
||||
const successNotification = new Notification($T('SETTINGS_RESULT'), {
|
||||
body: $T('TIPS_SET_SUCCEED')
|
||||
})
|
||||
@@ -156,8 +152,14 @@ function handleMouseLeave () {
|
||||
$dropdown.value?.handleClose()
|
||||
}
|
||||
|
||||
async function getPicBeds () {
|
||||
const result = await triggerRPC<any>(IRPCActionType.PICBED_GET_PICBED_CONFIG, $route.params.type)
|
||||
config.value = result.config
|
||||
picBedName.value = result.name
|
||||
}
|
||||
|
||||
async function getPicBedConfigList () {
|
||||
const res = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, type.value) || undefined
|
||||
const res = await triggerRPC<IUploaderConfigItem>(IRPCActionType.PICBED_GET_CONFIG_LIST, type.value) || undefined
|
||||
const configList = res?.configList || []
|
||||
picBedConfigList.value = configList.filter((item) => item._id !== $route.params.configId)
|
||||
}
|
||||
@@ -174,7 +176,7 @@ async function handleConfigImport (configItem: IUploaderConfigListItem) {
|
||||
}
|
||||
|
||||
const handleReset = async () => {
|
||||
await triggerRPC<void>(IRPCActionType.RESET_UPLOADER_CONFIG, type.value, $route.params.configId)
|
||||
await triggerRPC<void>(IRPCActionType.UPLOADER_RESET_CONFIG, type.value, $route.params.configId)
|
||||
const successNotification = new Notification($T('SETTINGS_RESULT'), {
|
||||
body: $T('TIPS_RESET_SUCCEED')
|
||||
})
|
||||
@@ -188,7 +190,7 @@ async function handleNameClick () {
|
||||
const lang = await getConfig(configPaths.settings.language) || II18nLanguage.ZH_CN
|
||||
const url = picBedManualUrlList[lang === II18nLanguage.EN ? 'en' : 'zh_cn'][$route.params.type as string]
|
||||
if (url) {
|
||||
sendToMain(OPEN_URL, url)
|
||||
sendRPC(IRPCActionType.OPEN_URL, url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,22 +213,14 @@ async function handleCopyApi () {
|
||||
ElMessage.error('Copy failed')
|
||||
}
|
||||
}
|
||||
|
||||
function getPicBeds (_event: IpcRendererEvent, _config: IPicGoPluginConfig[], name: string) {
|
||||
config.value = _config
|
||||
picBedName.value = name
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
ipcRenderer.removeListener('getPicBedConfig', getPicBeds)
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'PicbedsPage'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang='stylus'>
|
||||
#picbeds-page
|
||||
height 100%
|
||||
|
||||
Reference in New Issue
Block a user