From 762dc9b2cc2b10ce8c02b1e57b00e68fdad7d943 Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Wed, 8 Jan 2020 19:26:25 +0800 Subject: [PATCH] :hammer: Refactor: move some utils to apis --- src/background.ts | 12 ++++++------ src/main/{utils/busApi => apis/bus}/constants.ts | 0 src/main/{utils/busApi => apis/bus}/index.ts | 2 +- src/main/{utils/guiApi.ts => apis/gui/index.ts} | 4 ++-- src/main/{utils/picgo.ts => apis/picgo/index.ts} | 0 src/main/{utils => apis/shortKey}/shortKeyHandler.ts | 8 ++++---- src/main/{utils => apis/shortKey}/shortKeyService.ts | 2 +- .../{utils/uploader.ts => apis/uploader/index.ts} | 2 +- src/main/apis/window/windowList.ts | 4 ++-- .../migrate/{shortKeyUpdateHelper.ts => index.ts} | 0 src/main/server/index.ts | 2 +- src/main/server/routerManager.ts | 2 +- src/main/utils/getPicBeds.ts | 6 ++---- src/main/utils/ipcList.ts | 0 src/main/utils/picgoCoreIPC.ts | 6 +++--- 15 files changed, 24 insertions(+), 26 deletions(-) rename src/main/{utils/busApi => apis/bus}/constants.ts (100%) rename src/main/{utils/busApi => apis/bus}/index.ts (97%) rename src/main/{utils/guiApi.ts => apis/gui/index.ts} (98%) rename src/main/{utils/picgo.ts => apis/picgo/index.ts} (100%) rename src/main/{utils => apis/shortKey}/shortKeyHandler.ts (97%) rename src/main/{utils => apis/shortKey}/shortKeyService.ts (93%) rename src/main/{utils/uploader.ts => apis/uploader/index.ts} (98%) rename src/main/migrate/{shortKeyUpdateHelper.ts => index.ts} (100%) create mode 100644 src/main/utils/ipcList.ts diff --git a/src/background.ts b/src/background.ts index 2c20a68..7f8ca3c 100644 --- a/src/background.ts +++ b/src/background.ts @@ -20,12 +20,12 @@ import { installVueDevtools } from 'vue-cli-plugin-electron-builder/lib' import db from '#/datastore' -import picgo from '~/main/utils/picgo' -import uploader from '~/main/utils/uploader' +import picgo from '~/main/apis/picgo' +import uploader from '~/main/apis/uploader' import beforeOpen from '~/main/utils/beforeOpen' import pasteTemplate from '#/utils/pasteTemplate' import updateChecker from '~/main/utils/updateChecker' -import { getPicBeds } from '~/main/utils/getPicBeds' +import getPicBeds from '~/main/utils/getPicBeds' import pkg from 'root/package.json' import picgoCoreIPC from '~/main/utils/picgoCoreIPC' import fixPath from 'fix-path' @@ -33,8 +33,8 @@ import { getUploadFiles } from '~/main/utils/handleArgv' import bus from '~/main/utils/eventBus' import { updateShortKeyFromVersion212 -} from '~/main/migrate/shortKeyUpdateHelper' -import shortKeyHandler from '~/main/utils/shortKeyHandler' +} from '~/main/migrate' +import shortKeyHandler from '~/main/apis/shortKey/shortKeyHandler' import logger from '~/main/utils/logger' import { UPLOAD_WITH_FILES, @@ -46,7 +46,7 @@ import { GET_SETTING_WINDOW_ID, GET_SETTING_WINDOW_ID_RESPONSE, CREATE_APP_MENU -} from '~/main/utils/busApi/constants' +} from '~/main/apis/bus/constants' import server from '~/main/server/index' import { IWindowList } from '~/main/apis/window/constants' import windowManager from '~/main/apis/window/windowManager' diff --git a/src/main/utils/busApi/constants.ts b/src/main/apis/bus/constants.ts similarity index 100% rename from src/main/utils/busApi/constants.ts rename to src/main/apis/bus/constants.ts diff --git a/src/main/utils/busApi/index.ts b/src/main/apis/bus/index.ts similarity index 97% rename from src/main/utils/busApi/index.ts rename to src/main/apis/bus/index.ts index f930398..95d5b09 100644 --- a/src/main/utils/busApi/index.ts +++ b/src/main/apis/bus/index.ts @@ -1,4 +1,4 @@ -import bus from '../eventBus' +import bus from '../../utils/eventBus' import { UPLOAD_WITH_FILES, UPLOAD_WITH_FILES_RESPONSE, diff --git a/src/main/utils/guiApi.ts b/src/main/apis/gui/index.ts similarity index 98% rename from src/main/utils/guiApi.ts rename to src/main/apis/gui/index.ts index 0269611..92eb9dc 100644 --- a/src/main/utils/guiApi.ts +++ b/src/main/apis/gui/index.ts @@ -8,12 +8,12 @@ import { webContents } from 'electron' import db from '#/datastore' -import uploader from './uploader' +import uploader from '../uploader' import pasteTemplate from '#/utils/pasteTemplate' import { getWindowId, getSettingWindowId -} from '~/main/utils/busApi' +} from '~/main/apis/bus' class GuiApi implements IGuiApi { private windowId: number = -1 diff --git a/src/main/utils/picgo.ts b/src/main/apis/picgo/index.ts similarity index 100% rename from src/main/utils/picgo.ts rename to src/main/apis/picgo/index.ts diff --git a/src/main/utils/shortKeyHandler.ts b/src/main/apis/shortKey/shortKeyHandler.ts similarity index 97% rename from src/main/utils/shortKeyHandler.ts rename to src/main/apis/shortKey/shortKeyHandler.ts index 7a7a4ef..5e895a2 100644 --- a/src/main/utils/shortKeyHandler.ts +++ b/src/main/apis/shortKey/shortKeyHandler.ts @@ -1,4 +1,4 @@ -import bus from './eventBus' +import bus from '../../utils/eventBus' import PicGoCore from '~/universal/types/picgo' import path from 'path' import { @@ -6,11 +6,11 @@ import { globalShortcut, BrowserWindow } from 'electron' -import logger from './logger' -import GuiApi from './guiApi' +import logger from '../../utils/logger' +import GuiApi from '../gui' import db from '#/datastore' import shortKeyService from './shortKeyService' -import picgo from './picgo' +import picgo from '../picgo' class ShortKeyHandler { private isInModifiedMode: boolean = false diff --git a/src/main/utils/shortKeyService.ts b/src/main/apis/shortKey/shortKeyService.ts similarity index 93% rename from src/main/utils/shortKeyService.ts rename to src/main/apis/shortKey/shortKeyService.ts index 4e1c66c..675b6a9 100644 --- a/src/main/utils/shortKeyService.ts +++ b/src/main/apis/shortKey/shortKeyService.ts @@ -1,4 +1,4 @@ -import logger from './logger' +import logger from '../../utils/logger' class ShortKeyService { private commandList: Map = new Map() registerCommand (command: string, handler: IShortKeyHandler) { diff --git a/src/main/utils/uploader.ts b/src/main/apis/uploader/index.ts similarity index 98% rename from src/main/utils/uploader.ts rename to src/main/apis/uploader/index.ts index 00c61b0..bff0222 100644 --- a/src/main/utils/uploader.ts +++ b/src/main/apis/uploader/index.ts @@ -6,7 +6,7 @@ import { WebContents } from 'electron' import dayjs from 'dayjs' -import picgo from '~/main/utils/picgo' +import picgo from '~/main/apis/picgo' import db from '#/datastore' import windowManager from '~/main/apis/window/windowManager' import { IWindowList } from '~/main/apis/window/constants' diff --git a/src/main/apis/window/windowList.ts b/src/main/apis/window/windowList.ts index 4b1d1d8..5c12e70 100644 --- a/src/main/apis/window/windowList.ts +++ b/src/main/apis/window/windowList.ts @@ -10,9 +10,9 @@ import { import { IWindowListItem } from '#/types/electron' import bus from '~/main/utils/eventBus' import db from '#/datastore' -import { getWindowId } from '~/main/utils/busApi' +import { getWindowId } from '~/main/apis/bus' import { BrowserWindow, app } from 'electron' -import { CREATE_APP_MENU } from '~/main/utils/busApi/constants' +import { CREATE_APP_MENU } from '~/main/apis/bus/constants' const windowList = new Map() diff --git a/src/main/migrate/shortKeyUpdateHelper.ts b/src/main/migrate/index.ts similarity index 100% rename from src/main/migrate/shortKeyUpdateHelper.ts rename to src/main/migrate/index.ts diff --git a/src/main/server/index.ts b/src/main/server/index.ts index 57a229a..0259aff 100644 --- a/src/main/server/index.ts +++ b/src/main/server/index.ts @@ -3,7 +3,7 @@ import routers from './routerManager' import { handleResponse } from './utils' -import picgo from '~/main/utils/picgo' +import picgo from '~/main/apis/picgo' import logger from '~/main/utils/logger' class Server { diff --git a/src/main/server/routerManager.ts b/src/main/server/routerManager.ts index af29ba5..98f7e58 100644 --- a/src/main/server/routerManager.ts +++ b/src/main/server/routerManager.ts @@ -2,7 +2,7 @@ import router from './router' import { uploadWithClipboardFiles, uploadWithFiles -} from '~/main/utils/busApi/index' +} from '~/main/apis/bus/index' import { handleResponse } from './utils' diff --git a/src/main/utils/getPicBeds.ts b/src/main/utils/getPicBeds.ts index 20889b2..e6f4ed1 100644 --- a/src/main/utils/getPicBeds.ts +++ b/src/main/utils/getPicBeds.ts @@ -1,4 +1,4 @@ -import picgo from './picgo' +import picgo from '../apis/picgo' const getPicBeds = () => { const picBedTypes = picgo.helper.uploader.getIdList() @@ -14,6 +14,4 @@ const getPicBeds = () => { return picBeds } -export { - getPicBeds -} +export default getPicBeds diff --git a/src/main/utils/ipcList.ts b/src/main/utils/ipcList.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/main/utils/picgoCoreIPC.ts b/src/main/utils/picgoCoreIPC.ts index 24dea9e..5029ace 100644 --- a/src/main/utils/picgoCoreIPC.ts +++ b/src/main/utils/picgoCoreIPC.ts @@ -1,5 +1,5 @@ import path from 'path' -import GuiApi from './guiApi' +import GuiApi from '../apis/gui' import { dialog, shell, @@ -11,8 +11,8 @@ import { } from 'electron' import PicGoCore from '~/universal/types/picgo' import { IPicGoHelperType } from '#/types/enum' -import shortKeyHandler from './shortKeyHandler' -import picgo from '~/main/utils/picgo' +import shortKeyHandler from '../apis/shortKey/shortKeyHandler' +import picgo from '~/main/apis/picgo' // eslint-disable-next-line const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require