From aaec99f4665376daa0551aeba66d12ae0be5c12f Mon Sep 17 00:00:00 2001 From: PiEgg Date: Wed, 28 Feb 2024 15:59:20 +0800 Subject: [PATCH] :sparkles: Feature: add startup mode ISSUES CLOSED: #915 --- public/i18n/en.yml | 16 ++++++---- public/i18n/zh-CN.yml | 6 +++- public/i18n/zh-TW.yml | 18 ++++++----- src/main/apis/app/system/index.ts | 5 ++-- src/main/apis/app/window/windowList.ts | 20 +++++++++++-- src/main/lifeCycle/index.ts | 14 ++++++++- src/renderer/pages/PicGoSetting.vue | 7 +++-- .../selectArea/SelectAreaSettings.vue | 30 +++++++++++++++++++ src/universal/types/enum.ts | 6 ++++ src/universal/types/i18n.d.ts | 4 +++ src/universal/types/view.d.ts | 1 + src/universal/utils/common.ts | 4 +++ 12 files changed, 110 insertions(+), 21 deletions(-) diff --git a/public/i18n/en.yml b/public/i18n/en.yml index 9e2610b51..4df4b1de9 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -1,4 +1,4 @@ -LANG_DISPLAY_LABEL: 'English' +LANG_DISPLAY_LABEL: "English" ABOUT: About OPEN_MAIN_WINDOW: Open Main Window CHOOSE_DEFAULT_PICBED: Choose Default Picbed @@ -28,7 +28,7 @@ OPEN_TOOLBOX: Open Toolbox # ---renderer i18n begin--- -CHOOSE_YOUR_DEFAULT_PICBED: 'Choose ${d} as your default picbed:' +CHOOSE_YOUR_DEFAULT_PICBED: "Choose ${d} as your default picbed:" UPLOAD_AREA: Upload Area GALLERY: Gallery PICBEDS_SETTINGS: Picbeds Settings @@ -85,7 +85,7 @@ SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD: Auto Copy URL After Upload SETTINGS_TIPS_PLACEHOLDER_URL: Use $url to represent url position SETTINGS_TIPS_PLACEHOLDER_FILENAME: Use $fileName to represent file name position SETTINGS_TIPS_PLACEHOLDER_EXTNAME: Use $extName to represent file's ext position -SETTINGS_TIPS_SUCH_AS: 'Such as: $url/$fileName' +SETTINGS_TIPS_SUCH_AS: "Such as: $url/$fileName" SETTINGS_UPLOAD_PROXY: Upload Proxy SETTINGS_PLUGIN_INSTALL_PROXY: Proxy for Plugin Install SETTINGS_PLUGIN_INSTALL_MIRROR: Mirror for Plugin Install @@ -121,6 +121,10 @@ UPLOADER_CONFIG_PLACEHOLDER: Please Enter Configuration Name SELECTED_SETTING_HINT: Selected SETTINGS_ENCODE_OUTPUT_URL: Encode Output(or Copyed) URL SETTINGS_SHOW_DOCK_ICON: Show Dock icon +SETTINGS_STARTUP_MODE: Startup Mode +SETTINGS_STARTUP_MODE_MAIN_WINDOW: Open Main Window +SETTINGS_STARTUP_MODE_MINI_WINDOW: Open Mini Window +SETTINGS_STARTUP_MODE_HIDE: Silent Startup # shortcut-page @@ -202,10 +206,10 @@ UPDATE_PLUGIN: Update Plugin # toolbox TOOLBOX: Toolbox -TOOLBOX_TITLE: Troubleshoot PicGo runtime issues +TOOLBOX_TITLE: Troubleshoot PicGo runtime issues TOOLBOX_SUB_TITLE: Scan the following items immediately to fix usage issues TOOLBOX_CHECK_CONFIG_FILE_BROKEN: Check if the configuration file is damaged -TOOLBOX_CHECK_GALLERY_FILE_BROKEN: Check if the album file is damaged +TOOLBOX_CHECK_GALLERY_FILE_BROKEN: Check if the album file is damaged TOOLBOX_CHECK_PROBLEM_WITH_CLIPBOARD_PIC_UPLOAD: Check if there is a problem with clipboard picture upload TOOLBOX_CHECK_PROBLEM_WITH_PROXY: Check if the proxy settings are normal TOOLBOX_FIX_DONE_NEED_RELOAD: Repair completed, need to restart to take effect, restart or not @@ -236,7 +240,7 @@ TIPS_PLUGIN_OVERWRITE_GALLERY: Plugin is trying to overwrite the album gallery, TIPS_UPLOAD_NOT_PICTURES: The latest clipboard item is not a picture TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicGo config file broken, has been restored to default TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicGo config file broken, has been restored to backup -TIPS_PICGO_BACKUP_FILE_VERSION: 'Backup file version: ${v}' +TIPS_PICGO_BACKUP_FILE_VERSION: "Backup file version: ${v}" TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: Custom config file parse error, please check the path content TIPS_SHORTCUT_MODIFIED_SUCCEED: Shortcut modified successfully TIPS_SHORTCUT_MODIFIED_CONFLICT: Shortcut conflict, please reset diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index 8eed5fa58..a93e2f86e 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -121,6 +121,10 @@ UPLOADER_CONFIG_PLACEHOLDER: 请输入配置名称 SELECTED_SETTING_HINT: 已选中 SETTINGS_ENCODE_OUTPUT_URL: 输出(复制) URL 时进行转义 SETTINGS_SHOW_DOCK_ICON: 显示 Dock 栏图标 +SETTINGS_STARTUP_MODE: 启动模式 +SETTINGS_STARTUP_MODE_MAIN_WINDOW: 打开主窗口 +SETTINGS_STARTUP_MODE_MINI_WINDOW: 打开 Mini 窗口 +SETTINGS_STARTUP_MODE_HIDE: 静默启动 # shortcut-page @@ -236,7 +240,7 @@ TIPS_PLUGIN_OVERWRITE_GALLERY: 有插件正在试图覆盖相册列表,是否 TIPS_UPLOAD_NOT_PICTURES: 剪贴板最新的一条记录不是图片 TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicGo 配置文件损坏,已经恢复为默认配置 TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicGo 配置文件损坏,已经恢复为备份配置 -TIPS_PICGO_BACKUP_FILE_VERSION: '备份文件版本: ${v}' +TIPS_PICGO_BACKUP_FILE_VERSION: "备份文件版本: ${v}" TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: 自定义文件解析出错,请检查路径内容是否正确 TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷键已经修改成功 TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷键冲突,请重新设置 diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index 53b0faa6b..727b06d91 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -121,6 +121,10 @@ UPLOADER_CONFIG_PLACEHOLDER: 請輸入配置名稱 SELECTED_SETTING_HINT: 已選中 SETTINGS_ENCODE_OUTPUT_URL: 輸出(複製) URL 時進行轉義 SETTINGS_SHOW_DOCK_ICON: 顯示 Dock 欄圖示 +SETTINGS_STARTUP_MODE: 啟動模式 +SETTINGS_STARTUP_MODE_MAIN_WINDOW: 打開主視窗 +SETTINGS_STARTUP_MODE_MINI_WINDOW: 打開 Mini 視窗 +SETTINGS_STARTUP_MODE_HIDE: 靜默啟動 # shortcut-page @@ -202,27 +206,27 @@ UPDATE_PLUGIN: 更新插件 # toolbox TOOLBOX: 工具箱 -TOOLBOX_TITLE: 排查 PicGo 執行時問題 +TOOLBOX_TITLE: 排查 PicGo 執行時問題 TOOLBOX_SUB_TITLE: 立即掃描以下項目,修復使用問題 TOOLBOX_CHECK_CONFIG_FILE_BROKEN: 檢查配置文件是否損壞 TOOLBOX_CHECK_GALLERY_FILE_BROKEN: 檢查相冊文件是否損壞 TOOLBOX_CHECK_PROBLEM_WITH_CLIPBOARD_PIC_UPLOAD: 檢查剪貼板圖片上傳是否存在問題 TOOLBOX_CHECK_PROBLEM_WITH_PROXY: 檢查代理設置是否正常 TOOLBOX_FIX_DONE_NEED_RELOAD: 修復完成,需要重啓生效,是否重啓 -TOOLBOX_CANT_AUTO_FIX: 無法自動修復,請自行修復以下問題 +TOOLBOX_CANT_AUTO_FIX: 無法自動修復,請自行修復以下問題 TOOLBOX_START_SCAN: 開始掃描 TOOLBOX_RE_SCAN: 重新掃描 TOOLBOX_START_FIX: 開始修復 TOOLBOX_SUCCESS_TIPS: 恭喜你,沒有檢查出問題 TOOLBOX_CHECK_CONFIG_FILE_PATH_TIPS: 配置文件路徑是:${path} -TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS: 配置文件已損壞 -TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS: 相冊文件路徑是:${path} +TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS: 配置文件已損壞 +TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS: 相冊文件路徑是:${path} TOOLBOX_CHECK_GALLERY_FILE_BROKEN_TIPS: 相冊文件已損壞 -TOOLBOX_CHECK_PROXY_SUCCESS_TIPS: 代理設置正常 +TOOLBOX_CHECK_PROXY_SUCCESS_TIPS: 代理設置正常 TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS: 無代理設置 TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_CORRECT: 代理設置不正確 TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_WORKING: 代理設置不可用 -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS: 剪貼板圖片臨時文件夾路徑是:${path} +TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS: 剪貼板圖片臨時文件夾路徑是:${path} TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS: 剪貼板圖片臨時文件夾不存在:${path} TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_ERROR_TIPS: 請自行創建文件夾:${path} @@ -236,7 +240,7 @@ TIPS_PLUGIN_OVERWRITE_GALLERY: 有插件正在試圖覆蓋相簿列表,是否 TIPS_UPLOAD_NOT_PICTURES: 剪貼簿最新的一條記錄不是圖片 TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicGo 設定檔案已損壞,已經恢復為預設設定 TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicGo 設定檔案已損壞,已經恢復為備份設定 -TIPS_PICGO_BACKUP_FILE_VERSION: '備份檔案版本: ${v}' +TIPS_PICGO_BACKUP_FILE_VERSION: "備份檔案版本: ${v}" TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: 自訂設定檔案解析出錯,請檢查路徑內容是否正確 TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷鍵已經修改成功 TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷鍵衝突,請重新設定 diff --git a/src/main/apis/app/system/index.ts b/src/main/apis/app/system/index.ts index 349bb7d41..51728238f 100644 --- a/src/main/apis/app/system/index.ts +++ b/src/main/apis/app/system/index.ts @@ -19,6 +19,7 @@ import { privacyManager } from '~/main/utils/privacyManager' import { T } from '~/main/i18n' import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion' import { buildPicBedListMenu } from '~/main/events/remotes/menu' +import { isLinux, isMacOS } from '~/universal/utils/common' let contextMenu: Menu | null let menu: Menu | null let tray: Tray | null @@ -256,7 +257,7 @@ export function createTray () { } }) // toggleWindow() - } else if (process.platform === 'linux') { + } else if (isLinux) { // click事件在Ubuntu上无法触发,Unity不支持(在Mac和Windows上可以触发) // 需要使用 setContextMenu 设置菜单 createContextMenu() @@ -265,7 +266,7 @@ export function createTray () { } export function handleDockIcon () { - if (process.platform === 'darwin') { + if (isMacOS) { if (db.get('settings.showDockIcon') !== false) { app.dock.show() app.dock.setMenu(createContextMenu()) diff --git a/src/main/apis/app/window/windowList.ts b/src/main/apis/app/window/windowList.ts index a6e2eccff..4cf00c9ba 100644 --- a/src/main/apis/app/window/windowList.ts +++ b/src/main/apis/app/window/windowList.ts @@ -5,13 +5,14 @@ import { RENAME_WINDOW_URL, TOOLBOX_WINDOW_URL } from './constants' -import { IWindowList } from '#/types/enum' +import { IStartupMode, IWindowList } from '#/types/enum' import bus from '@core/bus' import { CREATE_APP_MENU } from '@core/bus/constants' import db from '~/main/apis/core/datastore' import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants' import { app } from 'electron' import { T } from '~/main/i18n' +import { isLinux } from '~/universal/utils/common' // import { URLSearchParams } from 'url' const windowList = new Map() @@ -25,6 +26,21 @@ const handleWindowParams = (windowURL: string) => { return windowURL } +export const isWindowShouldShowOnStartup = (currentWindow: IWindowList) => { + const startupMode = db.get('settings.startupMode') || (isLinux ? IStartupMode.SHOW_MINI_WINDOW : IStartupMode.HIDE) + switch (currentWindow) { + case IWindowList.MINI_WINDOW: { + return startupMode === IStartupMode.SHOW_MINI_WINDOW + } + case IWindowList.SETTING_WINDOW: { + return startupMode === IStartupMode.SHOW_MAIN_WINDOW + } + default: { + return false + } + } +} + windowList.set(IWindowList.TRAY_WINDOW, { isValid: process.platform !== 'linux', multiple: false, @@ -113,7 +129,7 @@ windowList.set(IWindowList.MINI_WINDOW, { const obj: IBrowserWindowOptions = { height: 64, width: 64, - show: process.platform === 'linux', + show: isLinux, frame: false, fullscreenable: false, skipTaskbar: true, diff --git a/src/main/lifeCycle/index.ts b/src/main/lifeCycle/index.ts index d8727a1df..d42c2456a 100644 --- a/src/main/lifeCycle/index.ts +++ b/src/main/lifeCycle/index.ts @@ -37,6 +37,7 @@ import fixPath from './fixPath' import { initI18n } from '~/main/utils/handleI18n' import { remoteNoticeHandler } from 'apis/app/remoteNotice' import { isMacOS } from '../utils/getMacOSVersion' +import { isWindowShouldShowOnStartup } from '../apis/app/window/windowList' const isDevelopment = process.env.NODE_ENV !== 'production' @@ -79,7 +80,7 @@ class LifeCycle { try { await installExtension(VUEJS_DEVTOOLS) } catch (e: any) { - console.error('Vue Devtools failed to install:', e.toString()) + console.error('Vue Devtools failed to install:', e?.toString()) } } windowManager.create(IWindowList.TRAY_WINDOW) @@ -87,6 +88,17 @@ class LifeCycle { settingWindow?.once('show', () => { remoteNoticeHandler.triggerHook(IRemoteNoticeTriggerHook.SETTING_WINDOW_OPEN) }) + if (isWindowShouldShowOnStartup(IWindowList.SETTING_WINDOW)) { + settingWindow?.show() + settingWindow?.focus() + } + if (!isMacOS) { + if (isWindowShouldShowOnStartup(IWindowList.MINI_WINDOW)) { + const miniWindow = windowManager.create(IWindowList.MINI_WINDOW) + miniWindow?.show() + miniWindow?.focus() + } + } createTray() handleDockIcon() db.set('needReload', false) diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index 86981fbfe..f6646b6ca 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -48,7 +48,7 @@ import { ElForm } from 'element-plus' import { Reading } from '@element-plus/icons-vue' import { IConfig } from 'picgo' import { T as $T } from '@/i18n/index' -import { enforceNumber } from '~/universal/utils/common' +import { enforceNumber, isLinux } from '~/universal/utils/common' import { onBeforeMount, reactive, ref } from 'vue' import { getConfig } from '@/utils/dataSender' import ButtonAreaSettings from './components/settings/buttonArea/ButtonAreaSettings.vue' @@ -56,6 +56,7 @@ import SwitchAreaSettings from './components/settings/switchArea/SwitchAreaSetti import CustomAreaSettings from './components/settings/customArea/CustomAreaSettings.vue' import SelectAreaSettings from './components/settings/selectArea/SelectAreaSettings.vue' import { openURL } from '@/utils/common' +import { IStartupMode } from '#/types/enum' const form = reactive({ showUpdateTip: false, @@ -80,7 +81,8 @@ const form = reactive({ port: 36677, host: '127.0.0.1', enable: true - } + }, + startupMode: IStartupMode.HIDE }) const proxy = ref('') @@ -113,6 +115,7 @@ async function initData () { form.server = settings.server form.logFileSizeLimit = enforceNumber(settings.logFileSizeLimit) || 10 form.showDockIcon = settings.showDockIcon === undefined ? true : settings.showDockIcon + form.startupMode = settings.startupMode || (isLinux ? IStartupMode.SHOW_MINI_WINDOW : IStartupMode.HIDE) } } diff --git a/src/renderer/pages/components/settings/selectArea/SelectAreaSettings.vue b/src/renderer/pages/components/settings/selectArea/SelectAreaSettings.vue index 31a8e1ab7..3d822b722 100644 --- a/src/renderer/pages/components/settings/selectArea/SelectAreaSettings.vue +++ b/src/renderer/pages/components/settings/selectArea/SelectAreaSettings.vue @@ -6,6 +6,12 @@ :placeholder="$T('SETTINGS_CHOOSE_LANGUAGE')" @change="handleLanguageChange" /> +