mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-07 05:32:52 +08:00
⚡ Perf(custom): improve init perf of several pages
This commit is contained in:
@@ -310,30 +310,27 @@ export function createTray(tooltip: string) {
|
|||||||
// so the tray window must be available
|
// so the tray window must be available
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
;(tray as any).on('drop-files', async (_: Event, files: string[]) => {
|
;(tray as any).on('drop-files', async (_: Event, files: string[]) => {
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
const rawInput = cloneDeep(files)
|
const rawInput = cloneDeep(files)
|
||||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||||
const res = await uploader.setWebContents(trayWindow.webContents).uploadReturnCtx(files)
|
const res = await uploader.setWebContents(trayWindow.webContents).uploadReturnCtx(files)
|
||||||
const imgs = res[0] ? res[0] : false
|
const imgs = res[0] ? res[0] : false
|
||||||
const backImgs = res[1] ? res[1] : false
|
const backImgs = res[1] ? res[1] : false
|
||||||
const deleteLocalFile = picgo.getConfig<boolean | undefined>(configPaths.settings.deleteLocalFile) || false
|
const deleteLocalFile = allConfig.settings?.deleteLocalFile || false
|
||||||
if (imgs !== false) {
|
if (imgs !== false) {
|
||||||
const pasteText: string[] = []
|
const pasteText: string[] = []
|
||||||
for (let i = 0; i < imgs.length; i++) {
|
for (let i = 0; i < imgs.length; i++) {
|
||||||
if (deleteLocalFile) {
|
if (deleteLocalFile) {
|
||||||
await fs.remove(rawInput[i])
|
await fs.remove(rawInput[i])
|
||||||
}
|
}
|
||||||
const [pasteTextItem, shortUrl] = await pasteTemplate(
|
const [pasteTextItem, shortUrl] = await pasteTemplate(pasteStyle, imgs[i], allConfig.settings?.customLink)
|
||||||
pasteStyle,
|
|
||||||
imgs[i],
|
|
||||||
picgo.getConfig<string | undefined>(configPaths.settings.customLink),
|
|
||||||
)
|
|
||||||
imgs[i].shortUrl = shortUrl
|
imgs[i].shortUrl = shortUrl
|
||||||
pasteText.push(pasteTextItem)
|
pasteText.push(pasteTextItem)
|
||||||
const isShowResultNotification =
|
const isShowResultNotification =
|
||||||
picgo.getConfig<boolean | undefined>(configPaths.settings.uploadResultNotification) === undefined
|
allConfig.settings?.uploadResultNotification === undefined
|
||||||
? true
|
? true
|
||||||
: !!picgo.getConfig<boolean | undefined>(configPaths.settings.uploadResultNotification)
|
: !!allConfig.settings?.uploadResultNotification
|
||||||
if (isShowResultNotification) {
|
if (isShowResultNotification) {
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: $t('UPLOAD_SUCCEED'),
|
title: $t('UPLOAD_SUCCEED'),
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ import { IPasteStyle, IWindowList } from '~/utils/enum'
|
|||||||
import pasteTemplate from '~/utils/pasteTemplate'
|
import pasteTemplate from '~/utils/pasteTemplate'
|
||||||
|
|
||||||
const handleClipboardUploadingReturnCtx = async (img?: IUploadOption): Promise<(ImgInfo[] | false)[]> => {
|
const handleClipboardUploadingReturnCtx = async (img?: IUploadOption): Promise<(ImgInfo[] | false)[]> => {
|
||||||
const useBuiltinClipboard =
|
const useBuiltinClipboardConfig = picgo.getConfig<boolean | undefined>(configPaths.settings.useBuiltinClipboard)
|
||||||
picgo.getConfig<boolean | undefined>(configPaths.settings.useBuiltinClipboard) === undefined
|
const useBuiltinClipboard = useBuiltinClipboardConfig === undefined ? true : !!useBuiltinClipboardConfig
|
||||||
? true
|
|
||||||
: !!picgo.getConfig<boolean | undefined>(configPaths.settings.useBuiltinClipboard)
|
|
||||||
const win = windowManager.getAvailableWindow()
|
const win = windowManager.getAvailableWindow()
|
||||||
if (useBuiltinClipboard) {
|
if (useBuiltinClipboard) {
|
||||||
return await uploader.setWebContents(win!.webContents).uploadWithBuildInClipboardReturnCtx(img)
|
return await uploader.setWebContents(win!.webContents).uploadWithBuildInClipboardReturnCtx(img)
|
||||||
@@ -30,21 +28,18 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
|||||||
const res = await handleClipboardUploadingReturnCtx()
|
const res = await handleClipboardUploadingReturnCtx()
|
||||||
img = res[0] ? res[0] : false
|
img = res[0] ? res[0] : false
|
||||||
backImg = res[1] ? res[1] : false
|
backImg = res[1] ? res[1] : false
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
if (img !== false) {
|
if (img !== false) {
|
||||||
if (img.length > 0) {
|
if (img.length > 0) {
|
||||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
const [pastedText, shortUrl] = await pasteTemplate(
|
const [pastedText, shortUrl] = await pasteTemplate(pasteStyle, img[0], allConfig.settings?.customLink)
|
||||||
pasteStyle,
|
|
||||||
img[0],
|
|
||||||
picgo.getConfig<string | undefined>(configPaths.settings.customLink),
|
|
||||||
)
|
|
||||||
img[0].shortUrl = shortUrl
|
img[0].shortUrl = shortUrl
|
||||||
handleCopyUrl(pastedText)
|
handleCopyUrl(pastedText)
|
||||||
const isShowResultNotification =
|
const isShowResultNotification =
|
||||||
picgo.getConfig<boolean | undefined>(configPaths.settings.uploadResultNotification) === undefined
|
allConfig.settings?.uploadResultNotification === undefined
|
||||||
? true
|
? true
|
||||||
: !!picgo.getConfig<boolean | undefined>(configPaths.settings.uploadResultNotification)
|
: !!allConfig.settings?.uploadResultNotification
|
||||||
if (isShowResultNotification) {
|
if (isShowResultNotification) {
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: $t('UPLOAD_SUCCEED'),
|
title: $t('UPLOAD_SUCCEED'),
|
||||||
@@ -104,9 +99,10 @@ export const uploadChoosedFiles = async (
|
|||||||
imgs = res[0] ? res[0] : false
|
imgs = res[0] ? res[0] : false
|
||||||
backImgs = res[1] ? res[1] : false
|
backImgs = res[1] ? res[1] : false
|
||||||
const result = []
|
const result = []
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
if (imgs !== false) {
|
if (imgs !== false) {
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
const deleteLocalFile = picgo.getConfig<boolean>(configPaths.settings.deleteLocalFile) || false
|
const deleteLocalFile = allConfig.settings?.deleteLocalFile || false
|
||||||
const pasteText: string[] = []
|
const pasteText: string[] = []
|
||||||
const imgLength = imgs.length
|
const imgLength = imgs.length
|
||||||
for (let i = 0; i < imgLength; i++) {
|
for (let i = 0; i < imgLength; i++) {
|
||||||
@@ -119,17 +115,13 @@ export const uploadChoosedFiles = async (
|
|||||||
picgo.log.error(err)
|
picgo.log.error(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const [pasteTextItem, shortUrl] = await pasteTemplate(
|
const [pasteTextItem, shortUrl] = await pasteTemplate(pasteStyle, imgs[i], allConfig.settings?.customLink)
|
||||||
pasteStyle,
|
|
||||||
imgs[i],
|
|
||||||
picgo.getConfig<string | undefined>(configPaths.settings.customLink),
|
|
||||||
)
|
|
||||||
imgs[i].shortUrl = shortUrl
|
imgs[i].shortUrl = shortUrl
|
||||||
pasteText.push(pasteTextItem)
|
pasteText.push(pasteTextItem)
|
||||||
const isShowResultNotification =
|
const isShowResultNotification =
|
||||||
picgo.getConfig<boolean | undefined>(configPaths.settings.uploadResultNotification) === undefined
|
allConfig.settings?.uploadResultNotification === undefined
|
||||||
? true
|
? true
|
||||||
: !!picgo.getConfig<boolean | undefined>(configPaths.settings.uploadResultNotification)
|
: !!allConfig.settings?.uploadResultNotification
|
||||||
if (isShowResultNotification) {
|
if (isShowResultNotification) {
|
||||||
if (imgLength <= 3) {
|
if (imgLength <= 3) {
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
|
|||||||
@@ -60,10 +60,11 @@ class Uploader {
|
|||||||
picgo.helper.beforeUploadPlugins.register('renameFn', {
|
picgo.helper.beforeUploadPlugins.register('renameFn', {
|
||||||
handle: async (ctx: IPicGo) => {
|
handle: async (ctx: IPicGo) => {
|
||||||
const uploaderType = getUploaderType(ctx)
|
const uploaderType = getUploaderType(ctx)
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
|
|
||||||
const globalRename = picgo.getConfig<boolean | undefined>(configPaths.settings.rename)
|
const globalRename = allConfig.settings?.rename
|
||||||
const globalAutoRename = picgo.getConfig<boolean | undefined>(configPaths.settings.autoRename)
|
const globalAutoRename = allConfig.settings?.autoRename
|
||||||
const buildInList = picgo.getConfig<any[]>(configPaths.buildIn.list._name) || []
|
const buildInList = allConfig.buildIn?.list || []
|
||||||
const idSpecificRename = buildInList.find((item: any) => item.id === uploaderType.id)?.manualRename
|
const idSpecificRename = buildInList.find((item: any) => item.id === uploaderType.id)?.manualRename
|
||||||
const idSpecificAutoRename = buildInList.find((item: any) => item.id === uploaderType.id)?.autoRename
|
const idSpecificAutoRename = buildInList.find((item: any) => item.id === uploaderType.id)?.autoRename
|
||||||
const rename = idSpecificRename !== undefined ? !!idSpecificRename : !!globalRename
|
const rename = idSpecificRename !== undefined ? !!idSpecificRename : !!globalRename
|
||||||
@@ -137,17 +138,18 @@ class Uploader {
|
|||||||
try {
|
try {
|
||||||
const result = [false, false] as (ImgInfo[] | false)[]
|
const result = [false, false] as (ImgInfo[] | false)[]
|
||||||
const res = await picgo.uploadReturnCtx(img)
|
const res = await picgo.uploadReturnCtx(img)
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
|
|
||||||
if (Array.isArray(res.output) && res.output.some((item: ImgInfo) => item.imgUrl)) {
|
if (Array.isArray(res.output) && res.output.some((item: ImgInfo) => item.imgUrl)) {
|
||||||
res.output.forEach((item: ImgInfo) => {
|
res.output.forEach((item: ImgInfo) => {
|
||||||
item.config = JSON.parse(JSON.stringify(picgo.getConfig<any>(`picBed.${item.type}`)))
|
item.config = JSON.parse(JSON.stringify(allConfig.picBed?.[item.type!]))
|
||||||
})
|
})
|
||||||
result[0] = res.output
|
result[0] = res.output
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(res.backupOutput) && res.backupOutput.some((item: ImgInfo) => item.imgUrl)) {
|
if (Array.isArray(res.backupOutput) && res.backupOutput.some((item: ImgInfo) => item.imgUrl)) {
|
||||||
res.backupOutput.forEach((item: ImgInfo) => {
|
res.backupOutput.forEach((item: ImgInfo) => {
|
||||||
item.config = JSON.parse(JSON.stringify(picgo.getConfig<any>(`picBed.${item.type}`)))
|
item.config = JSON.parse(JSON.stringify(allConfig.picBed?.[item.type!]))
|
||||||
})
|
})
|
||||||
result[1] = res.backupOutput
|
result[1] = res.backupOutput
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ import { applyTheme } from '../theme'
|
|||||||
const windowList = new Map<string, IWindowListItem>()
|
const windowList = new Map<string, IWindowListItem>()
|
||||||
|
|
||||||
const getDefaultWindowSizes = (): { width: number; height: number } => {
|
const getDefaultWindowSizes = (): { width: number; height: number } => {
|
||||||
const mainWindowWidth = picgo.getConfig<number>(configPaths.settings.mainWindowWidth)
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
const mainWindowHeight = picgo.getConfig<number>(configPaths.settings.mainWindowHeight)
|
const mainWindowWidth = allConfig.settings?.mainWindowWidth
|
||||||
|
const mainWindowHeight = allConfig.settings?.mainWindowHeight
|
||||||
return {
|
return {
|
||||||
width: mainWindowWidth || 1200,
|
width: mainWindowWidth || 1200,
|
||||||
height: mainWindowHeight || 800,
|
height: mainWindowHeight || 800,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { cloneDeep } from 'lodash-es'
|
|||||||
import { SHOW_INPUT_BOX } from '~/events/constant'
|
import { SHOW_INPUT_BOX } from '~/events/constant'
|
||||||
import { T as $t } from '~/i18n'
|
import { T as $t } from '~/i18n'
|
||||||
import { handleCopyUrl } from '~/utils/common'
|
import { handleCopyUrl } from '~/utils/common'
|
||||||
import { configPaths } from '~/utils/configPaths'
|
|
||||||
import { IPasteStyle } from '~/utils/enum'
|
import { IPasteStyle } from '~/utils/enum'
|
||||||
import pasteTemplate from '~/utils/pasteTemplate'
|
import pasteTemplate from '~/utils/pasteTemplate'
|
||||||
|
|
||||||
@@ -78,25 +77,22 @@ class GuiApi implements IGuiApi {
|
|||||||
const imgs = res[0] ? res[0] : false
|
const imgs = res[0] ? res[0] : false
|
||||||
const backImgs = res[1] ? res[1] : false
|
const backImgs = res[1] ? res[1] : false
|
||||||
let result: ImgInfo[] = []
|
let result: ImgInfo[] = []
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
if (imgs !== false) {
|
if (imgs !== false) {
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
const deleteLocalFile = picgo.getConfig<boolean>(configPaths.settings.deleteLocalFile) || false
|
const deleteLocalFile = allConfig.settings?.deleteLocalFile || false
|
||||||
const pasteText: string[] = []
|
const pasteText: string[] = []
|
||||||
for (let i = 0; i < imgs.length; i++) {
|
for (let i = 0; i < imgs.length; i++) {
|
||||||
if (deleteLocalFile) {
|
if (deleteLocalFile) {
|
||||||
await fs.remove(rawInput[i])
|
await fs.remove(rawInput[i])
|
||||||
}
|
}
|
||||||
const [pasteTextItem, shortUrl] = await pasteTemplate(
|
const [pasteTextItem, shortUrl] = await pasteTemplate(pasteStyle, imgs[i], allConfig.settings?.customLink)
|
||||||
pasteStyle,
|
|
||||||
imgs[i],
|
|
||||||
picgo.getConfig<string>(configPaths.settings.customLink),
|
|
||||||
)
|
|
||||||
imgs[i].shortUrl = shortUrl
|
imgs[i].shortUrl = shortUrl
|
||||||
pasteText.push(pasteTextItem)
|
pasteText.push(pasteTextItem)
|
||||||
const isShowResultNotification =
|
const isShowResultNotification =
|
||||||
picgo.getConfig<boolean>(configPaths.settings.uploadResultNotification) === undefined
|
allConfig.settings?.uploadResultNotification === undefined
|
||||||
? true
|
? true
|
||||||
: !!picgo.getConfig<boolean>(configPaths.settings.uploadResultNotification)
|
: !!allConfig.settings?.uploadResultNotification
|
||||||
if (isShowResultNotification) {
|
if (isShowResultNotification) {
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: $t('UPLOAD_SUCCEED'),
|
title: $t('UPLOAD_SUCCEED'),
|
||||||
|
|||||||
@@ -144,14 +144,13 @@ const buildMainPageMenu = (win: BrowserWindow) => {
|
|||||||
|
|
||||||
const buildSecondPicBedMenu = () => {
|
const buildSecondPicBedMenu = () => {
|
||||||
const picBeds = getPicBeds().picBeds
|
const picBeds = getPicBeds().picBeds
|
||||||
const secondUploader = picgo.getConfig(configPaths.picBed.secondUploader)
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
const defaultSecondUploaderConfig = picgo.getConfig(configPaths.picBed.secondUploaderConfig) as
|
const secondUploader = allConfig.picBed?.secondUploader
|
||||||
| IUploaderConfig
|
const defaultSecondUploaderConfig = allConfig.picBed?.secondUploaderConfig as IUploaderConfig | undefined
|
||||||
| undefined
|
|
||||||
const defaultSecondUploaderId = defaultSecondUploaderConfig?._id || ''
|
const defaultSecondUploaderId = defaultSecondUploaderConfig?._id || ''
|
||||||
const defaultSecondUploaderName = defaultSecondUploaderConfig?._configName || 'Default'
|
const defaultSecondUploaderName = defaultSecondUploaderConfig?._configName || 'Default'
|
||||||
const currentPicBedName = picBeds.find(item => item.type === secondUploader)?.name
|
const currentPicBedName = picBeds.find(item => item.type === secondUploader)?.name
|
||||||
const picBedConfigList = picgo.getConfig<IUploaderConfig>('uploader')
|
const picBedConfigList = allConfig.uploader
|
||||||
const currentPicBedMenuItem = [
|
const currentPicBedMenuItem = [
|
||||||
{
|
{
|
||||||
label: `${$t('CURRENT_SECOND_PICBED')} - ${currentPicBedName || 'None'} - ${defaultSecondUploaderName}`,
|
label: `${$t('CURRENT_SECOND_PICBED')} - ${currentPicBedName || 'None'} - ${defaultSecondUploaderName}`,
|
||||||
@@ -171,7 +170,7 @@ const buildSecondPicBedMenu = () => {
|
|||||||
type: !hasSubmenu ? 'checkbox' : undefined,
|
type: !hasSubmenu ? 'checkbox' : undefined,
|
||||||
checked: !hasSubmenu ? secondUploader === item.type : undefined,
|
checked: !hasSubmenu ? secondUploader === item.type : undefined,
|
||||||
submenu: hasSubmenu
|
submenu: hasSubmenu
|
||||||
? configList.map(config => {
|
? configList.map((config: any) => {
|
||||||
return {
|
return {
|
||||||
label: config._configName || 'Default',
|
label: config._configName || 'Default',
|
||||||
// if only one config, use checkbox, or radio will checked as default
|
// if only one config, use checkbox, or radio will checked as default
|
||||||
@@ -202,9 +201,10 @@ const buildSecondPicBedMenu = () => {
|
|||||||
|
|
||||||
const buildPicBedListMenu = () => {
|
const buildPicBedListMenu = () => {
|
||||||
const picBeds = getPicBeds().picBeds
|
const picBeds = getPicBeds().picBeds
|
||||||
const currentPicBed = picgo.getConfig(configPaths.picBed.uploader)
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
|
const currentPicBed = allConfig.picBed?.uploader
|
||||||
const currentPicBedName = picBeds.find(item => item.type === currentPicBed)?.name
|
const currentPicBedName = picBeds.find(item => item.type === currentPicBed)?.name
|
||||||
const picBedConfigList = picgo.getConfig<IUploaderConfig>('uploader')
|
const picBedConfigList = allConfig.uploader
|
||||||
const currentPicBedMenuItem = [
|
const currentPicBedMenuItem = [
|
||||||
{
|
{
|
||||||
label: `${$t('CURRENT_PICBED')} - ${currentPicBedName}`,
|
label: `${$t('CURRENT_PICBED')} - ${currentPicBedName}`,
|
||||||
@@ -225,7 +225,7 @@ const buildPicBedListMenu = () => {
|
|||||||
type: !hasSubmenu ? 'checkbox' : undefined,
|
type: !hasSubmenu ? 'checkbox' : undefined,
|
||||||
checked: !hasSubmenu ? currentPicBed === item.type : undefined,
|
checked: !hasSubmenu ? currentPicBed === item.type : undefined,
|
||||||
submenu: hasSubmenu
|
submenu: hasSubmenu
|
||||||
? configList.map(config => {
|
? configList.map((config: any) => {
|
||||||
return {
|
return {
|
||||||
label: config._configName || 'Default',
|
label: config._configName || 'Default',
|
||||||
// if only one config, use checkbox, or radio will checked as default
|
// if only one config, use checkbox, or radio will checked as default
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import GuiApi from 'apis/gui'
|
|||||||
import { clipboard } from 'electron'
|
import { clipboard } from 'electron'
|
||||||
|
|
||||||
import { RPCRouter } from '~/events/rpc/router'
|
import { RPCRouter } from '~/events/rpc/router'
|
||||||
import { configPaths } from '~/utils/configPaths'
|
|
||||||
import { ICOREBuildInEvent, IPasteStyle, IRPCActionType, IRPCType } from '~/utils/enum'
|
import { ICOREBuildInEvent, IPasteStyle, IRPCActionType, IRPCType } from '~/utils/enum'
|
||||||
import pasteTemplate from '~/utils/pasteTemplate'
|
import pasteTemplate from '~/utils/pasteTemplate'
|
||||||
interface IFilter {
|
interface IFilter {
|
||||||
@@ -24,8 +23,9 @@ const galleryRoutes = [
|
|||||||
action: IRPCActionType.GALLERY_PASTE_TEXT,
|
action: IRPCActionType.GALLERY_PASTE_TEXT,
|
||||||
handler: async (_: IIPCEvent, args: [item: ImgInfo, copy?: boolean]) => {
|
handler: async (_: IIPCEvent, args: [item: ImgInfo, copy?: boolean]) => {
|
||||||
const [item, copy = true] = args
|
const [item, copy = true] = args
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
const customLink = picgo.getConfig<string>(configPaths.settings.customLink)
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
|
const customLink = allConfig.settings?.customLink
|
||||||
const [txt, shortUrl] = await pasteTemplate(pasteStyle, item, customLink)
|
const [txt, shortUrl] = await pasteTemplate(pasteStyle, item, customLink)
|
||||||
if (copy) {
|
if (copy) {
|
||||||
clipboard.writeText(txt)
|
clipboard.writeText(txt)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { Notification } from 'electron'
|
|||||||
import { RPCRouter } from '~/events/rpc/router'
|
import { RPCRouter } from '~/events/rpc/router'
|
||||||
import { T as $t } from '~/i18n'
|
import { T as $t } from '~/i18n'
|
||||||
import { generateShortUrl, handleCopyUrl, setTrayToolTip } from '~/utils/common'
|
import { generateShortUrl, handleCopyUrl, setTrayToolTip } from '~/utils/common'
|
||||||
import { configPaths } from '~/utils/configPaths'
|
|
||||||
import { IPasteStyle, IRPCActionType, IRPCType, IWindowList } from '~/utils/enum'
|
import { IPasteStyle, IRPCActionType, IRPCType, IWindowList } from '~/utils/enum'
|
||||||
import pasteTemplate from '~/utils/pasteTemplate'
|
import pasteTemplate from '~/utils/pasteTemplate'
|
||||||
|
|
||||||
@@ -35,19 +34,16 @@ const trayRoutes = [
|
|||||||
const res = await uploader.setWebContents(trayWindow.webContents).uploadWithBuildInClipboardReturnCtx()
|
const res = await uploader.setWebContents(trayWindow.webContents).uploadWithBuildInClipboardReturnCtx()
|
||||||
const img = res[0] ? res[0] : false
|
const img = res[0] ? res[0] : false
|
||||||
const backupImgs = res[1] ? res[1] : false
|
const backupImgs = res[1] ? res[1] : false
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
if (img !== false) {
|
if (img !== false) {
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
const [pasteText, shortUrl] = await pasteTemplate(
|
const [pasteText, shortUrl] = await pasteTemplate(pasteStyle, img[0], allConfig.settings?.customLink)
|
||||||
pasteStyle,
|
|
||||||
img[0],
|
|
||||||
picgo.getConfig<string>(configPaths.settings.customLink),
|
|
||||||
)
|
|
||||||
img[0].shortUrl = shortUrl
|
img[0].shortUrl = shortUrl
|
||||||
handleCopyUrl(pasteText)
|
handleCopyUrl(pasteText)
|
||||||
const isShowResultNotification =
|
const isShowResultNotification =
|
||||||
picgo.getConfig<boolean>(configPaths.settings.uploadResultNotification) === undefined
|
allConfig.settings?.uploadResultNotification === undefined
|
||||||
? true
|
? true
|
||||||
: !!picgo.getConfig<boolean>(configPaths.settings.uploadResultNotification)
|
: !!allConfig.settings?.uploadResultNotification
|
||||||
if (isShowResultNotification) {
|
if (isShowResultNotification) {
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: $t('UPLOAD_SUCCEED'),
|
title: $t('UPLOAD_SUCCEED'),
|
||||||
|
|||||||
@@ -81,9 +81,10 @@ class LifeCycle {
|
|||||||
|
|
||||||
#onReady() {
|
#onReady() {
|
||||||
const readyFunction = async () => {
|
const readyFunction = async () => {
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
windowManager.create(IWindowList.TRAY_WINDOW)
|
windowManager.create(IWindowList.TRAY_WINDOW)
|
||||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||||
const isAutoListenClipboard = picgo.getConfig<boolean>(configPaths.settings.isAutoListenClipboard) || false
|
const isAutoListenClipboard = allConfig.settings?.isAutoListenClipboard || false
|
||||||
const ClipboardWatcher = clipboardPoll
|
const ClipboardWatcher = clipboardPoll
|
||||||
if (isAutoListenClipboard) {
|
if (isAutoListenClipboard) {
|
||||||
picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: true })
|
picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: true })
|
||||||
@@ -95,16 +96,13 @@ class LifeCycle {
|
|||||||
} else {
|
} else {
|
||||||
picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: false })
|
picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: false })
|
||||||
}
|
}
|
||||||
const isHideDock = picgo.getConfig<boolean>(configPaths.settings.isHideDock) || false
|
const isHideDock = allConfig.settings?.isHideDock || false
|
||||||
let startMode = picgo.getConfig<string>(configPaths.settings.startMode) || ISartMode.QUIET
|
let startMode = allConfig.settings?.startMode || ISartMode.QUIET
|
||||||
if (process.platform === 'darwin' && startMode === ISartMode.MINI) {
|
if (process.platform === 'darwin' && startMode === ISartMode.MINI) {
|
||||||
startMode = ISartMode.QUIET
|
startMode = ISartMode.QUIET
|
||||||
}
|
}
|
||||||
const currentPicBed =
|
const currentPicBed = allConfig.picBed?.uploader || allConfig.picBed?.current || 'smms'
|
||||||
picgo.getConfig<string>(configPaths.picBed.uploader) ||
|
const currentPicBedConfig = allConfig.picBed?.[currentPicBed]?._configName || 'Default'
|
||||||
picgo.getConfig<string>(configPaths.picBed.current) ||
|
|
||||||
'smms'
|
|
||||||
const currentPicBedConfig = picgo.getConfig<any>(`picBed.${currentPicBed}`)?._configName || 'Default'
|
|
||||||
const tooltip = `${currentPicBed} ${currentPicBedConfig}`
|
const tooltip = `${currentPicBed} ${currentPicBedConfig}`
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
isHideDock ? app.dock?.hide() : setDockMenu()
|
isHideDock ? app.dock?.hide() : setDockMenu()
|
||||||
@@ -138,11 +136,11 @@ class LifeCycle {
|
|||||||
windowManager.create(IWindowList.MINI_WINDOW)
|
windowManager.create(IWindowList.MINI_WINDOW)
|
||||||
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)!
|
||||||
miniWindow.removeAllListeners()
|
miniWindow.removeAllListeners()
|
||||||
if (picgo.getConfig<boolean>(configPaths.settings.miniWindowOntop)) {
|
if (allConfig.settings?.miniWindowOntop) {
|
||||||
miniWindow.setAlwaysOnTop(true)
|
miniWindow.setAlwaysOnTop(true)
|
||||||
}
|
}
|
||||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
||||||
const lastPosition = picgo.getConfig<number[]>(configPaths.settings.miniWindowPosition)
|
const lastPosition = allConfig.settings?.miniWindowPosition
|
||||||
if (lastPosition) {
|
if (lastPosition) {
|
||||||
if (lastPosition[0] < 0 || lastPosition[0] > width || lastPosition[1] < 0 || lastPosition[1] > height) {
|
if (lastPosition[0] < 0 || lastPosition[0] > width || lastPosition[1] < 0 || lastPosition[1] > height) {
|
||||||
miniWindow.setPosition(width - 100, height - 100)
|
miniWindow.setPosition(width - 100, height - 100)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { markdownContent } from '~/server/apiDoc'
|
|||||||
import router from '~/server/router'
|
import router from '~/server/router'
|
||||||
import { deleteChoosedFiles, handleResponse } from '~/server/utils'
|
import { deleteChoosedFiles, handleResponse } from '~/server/utils'
|
||||||
import { AESHelper } from '~/utils/aesHelper'
|
import { AESHelper } from '~/utils/aesHelper'
|
||||||
import { configPaths } from '~/utils/configPaths'
|
|
||||||
import { changeCurrentUploader } from '~/utils/handleUploaderConfig'
|
import { changeCurrentUploader } from '~/utils/handleUploaderConfig'
|
||||||
|
|
||||||
const appPath = dataDir()
|
const appPath = dataDir()
|
||||||
@@ -45,10 +44,11 @@ router.post(
|
|||||||
urlparams?: URLSearchParams
|
urlparams?: URLSearchParams
|
||||||
}): Promise<void> => {
|
}): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
const picbed = urlparams?.get('picbed')
|
const picbed = urlparams?.get('picbed')
|
||||||
const passedKey = urlparams?.get('key')
|
const passedKey = urlparams?.get('key')
|
||||||
const serverKey = picgo.getConfig<string>(configPaths.settings.serverKey) || ''
|
const serverKey = allConfig.settings?.serverKey || ''
|
||||||
const useShortUrl = picgo.getConfig<boolean>(configPaths.settings.useShortUrl)
|
const useShortUrl = allConfig.settings?.useShortUrl
|
||||||
if (serverKey && passedKey !== serverKey) {
|
if (serverKey && passedKey !== serverKey) {
|
||||||
handleResponse({
|
handleResponse({
|
||||||
response,
|
response,
|
||||||
@@ -64,7 +64,7 @@ router.post(
|
|||||||
let currentPicBedConfigId = ''
|
let currentPicBedConfigId = ''
|
||||||
let needRestore = false
|
let needRestore = false
|
||||||
if (picbed) {
|
if (picbed) {
|
||||||
const currentPicBed = picgo.getConfig<IStringKeyMap>('picBed') || ({} as IStringKeyMap)
|
const currentPicBed = allConfig.picBed || ({} as IStringKeyMap)
|
||||||
currentPicBedType = currentPicBed.uploader || currentPicBed.current || 'smms'
|
currentPicBedType = currentPicBed.uploader || currentPicBed.current || 'smms'
|
||||||
currentPicBedConfig = currentPicBed[currentPicBedType] || ({} as IStringKeyMap)
|
currentPicBedConfig = currentPicBed[currentPicBedType] || ({} as IStringKeyMap)
|
||||||
currentPicBedConfigId = currentPicBedConfig._id
|
currentPicBedConfigId = currentPicBedConfig._id
|
||||||
@@ -73,7 +73,7 @@ router.post(
|
|||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
needRestore = true
|
needRestore = true
|
||||||
const picBeds = picgo.getConfig<IStringKeyMap>('uploader')
|
const picBeds = allConfig.uploader
|
||||||
const currentPicBedList = picBeds?.[picbed]?.configList
|
const currentPicBedList = picBeds?.[picbed]?.configList
|
||||||
if (currentPicBedList) {
|
if (currentPicBedList) {
|
||||||
const currentConfig = currentPicBedList?.find((item: any) => item._configName === configName)
|
const currentConfig = currentPicBedList?.find((item: any) => item._configName === configName)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import logger from '@core/picgo/logger'
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
|
||||||
import { encodeFilePath } from '~/utils/common'
|
import { encodeFilePath } from '~/utils/common'
|
||||||
import { configPaths } from '~/utils/configPaths'
|
|
||||||
|
|
||||||
const defaultPath = process.platform === 'win32' ? 'C:\\Users' : '/'
|
const defaultPath = process.platform === 'win32' ? 'C:\\Users' : '/'
|
||||||
|
|
||||||
@@ -656,11 +655,12 @@ class WebServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadConfig(): void {
|
loadConfig(): void {
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
this.#config = {
|
this.#config = {
|
||||||
enableWebServer: picgo.getConfig<boolean>(configPaths.settings.enableWebServer) || false,
|
enableWebServer: allConfig.settings?.enableWebServer || false,
|
||||||
webServerHost: picgo.getConfig<string>(configPaths.settings.webServerHost) || '0.0.0.0',
|
webServerHost: allConfig.settings?.webServerHost || '0.0.0.0',
|
||||||
webServerPort: picgo.getConfig<number>(configPaths.settings.webServerPort) || 37777,
|
webServerPort: allConfig.settings?.webServerPort || 37777,
|
||||||
webServerPath: picgo.getConfig<string>(configPaths.settings.webServerPath) || defaultPath,
|
webServerPath: allConfig.settings?.webServerPath || defaultPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -347,11 +347,9 @@ export function getUploaderType(ctx: IPicGo): {
|
|||||||
picBed: string
|
picBed: string
|
||||||
id?: string
|
id?: string
|
||||||
} {
|
} {
|
||||||
const picBed =
|
const allConfig = ctx.getConfig<any>() || {}
|
||||||
ctx.getConfig<Undefinable<string>>('picBed.uploader') ||
|
const picBed = allConfig.picBed?.uploader || allConfig.picBed?.current || 'smms'
|
||||||
ctx.getConfig<Undefinable<string>>('picBed.current') ||
|
const picBedConfig = allConfig.picBed?.[picBed] || {}
|
||||||
'smms'
|
|
||||||
const picBedConfig = ctx.getConfig<Undefinable<IStringKeyMap>>(`picBed.${picBed}`) || {}
|
|
||||||
const id = picBedConfig._id || ''
|
const id = picBedConfig._id || ''
|
||||||
return { picBed, id }
|
return { picBed, id }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
import picgo from '@core/picgo'
|
import picgo from '@core/picgo'
|
||||||
|
|
||||||
import { configPaths } from '~/utils/configPaths'
|
|
||||||
|
|
||||||
const getPicBeds = () => {
|
const getPicBeds = () => {
|
||||||
const picBedTypes = picgo.helper.uploader.getIdList()
|
const picBedTypes = picgo.helper.uploader.getIdList()
|
||||||
const defaultPicBed =
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
picgo.getConfig<string>(configPaths.picBed.uploader) ||
|
const defaultPicBed = allConfig.picBed?.uploader || allConfig.picBed?.current || 'smms'
|
||||||
picgo.getConfig<string>(configPaths.picBed.current) ||
|
const defaultConfig = allConfig.picBed?.[defaultPicBed] || {}
|
||||||
'smms'
|
|
||||||
const defaultConfig = picgo.getConfig<IStringKeyMap>(`picBed.${defaultPicBed}`) || {}
|
|
||||||
const defaultId = defaultConfig._id || ''
|
const defaultId = defaultConfig._id || ''
|
||||||
const defaultConfigName = defaultConfig._configName || ''
|
const defaultConfigName = defaultConfig._configName || ''
|
||||||
const picBedFromDB = picgo.getConfig<IPicBedType[]>(configPaths.picBed.list) || []
|
const picBedFromDB = allConfig.picBed?.list || []
|
||||||
const picBeds = picBedTypes
|
const picBeds = picBedTypes
|
||||||
.map((item: string) => {
|
.map((item: string) => {
|
||||||
const visible = picBedFromDB.find((i: IPicBedType) => i.type === item) // object or undefined
|
const visible = picBedFromDB.find((i: IPicBedType) => i.type === item) // object or undefined
|
||||||
|
|||||||
@@ -240,10 +240,11 @@ class UploadTaskQueueManager {
|
|||||||
const res = await uploader.setWebContents(webContents).uploadReturnCtx(input)
|
const res = await uploader.setWebContents(webContents).uploadReturnCtx(input)
|
||||||
const imgs = res[0] ? res[0] : false
|
const imgs = res[0] ? res[0] : false
|
||||||
const backupImgs = res[1] ? res[1] : false
|
const backupImgs = res[1] ? res[1] : false
|
||||||
|
const allConfig = picgo.getConfig<any>() || {}
|
||||||
|
|
||||||
if (imgs !== false && imgs.length > 0) {
|
if (imgs !== false && imgs.length > 0) {
|
||||||
const pasteStyle = picgo.getConfig<string>(configPaths.settings.pasteStyle) || IPasteStyle.MARKDOWN
|
const pasteStyle = allConfig.settings?.pasteStyle || IPasteStyle.MARKDOWN
|
||||||
const deleteLocalFile = picgo.getConfig<boolean>(configPaths.settings.deleteLocalFile) || false
|
const deleteLocalFile = allConfig.settings?.deleteLocalFile || false
|
||||||
|
|
||||||
const img = imgs[0]
|
const img = imgs[0]
|
||||||
|
|
||||||
@@ -257,11 +258,7 @@ class UploadTaskQueueManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const [pasteText, shortUrl] = await pasteTemplate(
|
const [pasteText, shortUrl] = await pasteTemplate(pasteStyle, img, allConfig.settings?.customLink)
|
||||||
pasteStyle,
|
|
||||||
img,
|
|
||||||
picgo.getConfig<string>(configPaths.settings.customLink),
|
|
||||||
)
|
|
||||||
img.shortUrl = shortUrl
|
img.shortUrl = shortUrl
|
||||||
|
|
||||||
const inserted = await GalleryDB.getInstance().insert(img)
|
const inserted = await GalleryDB.getInstance().insert(img)
|
||||||
|
|||||||
@@ -1337,18 +1337,16 @@ let compressInFile = {} as IBuildInCompressOptions
|
|||||||
|
|
||||||
async function initData() {
|
async function initData() {
|
||||||
// global settings
|
// global settings
|
||||||
compressInFile = (await getConfig<IBuildInCompressOptions>(configPaths.buildIn.compress)) || {}
|
const allConfig = await getConfig<any>()
|
||||||
const watermark = (await getConfig<IBuildInWaterMarkOptions>(configPaths.buildIn.watermark)) || {}
|
compressInFile = allConfig.buildIn?.compress || {}
|
||||||
const skipProcess = (await getConfig<IBuildInSkipProcessOptions>(configPaths.buildIn.skipProcess)) || {}
|
const watermark = allConfig.buildIn?.watermark || {}
|
||||||
globalRenameSettings.value = (await getConfig<{
|
const skipProcess = allConfig.buildIn?.skipProcess || {}
|
||||||
enable?: boolean
|
globalRenameSettings.value = allConfig.buildIn?.rename || {
|
||||||
format?: string
|
|
||||||
}>(configPaths.buildIn.rename)) || {
|
|
||||||
enable: false,
|
enable: false,
|
||||||
format: '{filename}',
|
format: '{filename}',
|
||||||
}
|
}
|
||||||
globalAutoRename.value = (await getConfig<boolean>(configPaths.settings.autoRename)) ?? false
|
globalAutoRename.value = allConfig.settings?.autoRename ?? false
|
||||||
globalManualRename.value = (await getConfig<boolean>(configPaths.settings.rename)) ?? false
|
globalManualRename.value = allConfig.settings?.rename ?? false
|
||||||
if (compressInFile) {
|
if (compressInFile) {
|
||||||
let cleanedObj = {}
|
let cleanedObj = {}
|
||||||
try {
|
try {
|
||||||
@@ -1405,11 +1403,8 @@ async function initData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (configId) {
|
if (configId) {
|
||||||
let buildInList = await getConfig<Undefinable<IBuildInListItem[]>>(configPaths.buildIn.list)
|
let buildInList = allConfig.buildIn?.list
|
||||||
const globalRenameSettings = (await getConfig<{
|
const globalRenameSettings = allConfig.buildIn?.rename || {
|
||||||
enable: boolean
|
|
||||||
format: string
|
|
||||||
}>(configPaths.buildIn.rename)) || {
|
|
||||||
enable: false,
|
enable: false,
|
||||||
format: '{filename}',
|
format: '{filename}',
|
||||||
}
|
}
|
||||||
@@ -1417,7 +1412,7 @@ async function initData() {
|
|||||||
saveConfig(configPaths.buildIn.list, [])
|
saveConfig(configPaths.buildIn.list, [])
|
||||||
buildInList = []
|
buildInList = []
|
||||||
}
|
}
|
||||||
singleConfigInFile = buildInList?.find(item => item.id === configId) || ({} as IBuildInListItem)
|
singleConfigInFile = buildInList?.find((item: { id: string }) => item.id === configId) || ({} as IBuildInListItem)
|
||||||
const mergedCompress = {
|
const mergedCompress = {
|
||||||
...compressForm.value,
|
...compressForm.value,
|
||||||
...(singleConfigInFile.compress || {}),
|
...(singleConfigInFile.compress || {}),
|
||||||
|
|||||||
Reference in New Issue
Block a user