From 6ca7612c0244b7a7d92d96c723cc7faa2462928b Mon Sep 17 00:00:00 2001 From: viarotel Date: Sun, 8 Sep 2024 01:18:44 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=9E=96=20Remove=20copilot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- copilot/App.vue | 63 ------- .../Transmission/Message/Preset.vue | 55 ------ .../components/Transmission/Message/index.vue | 81 -------- copilot/components/Transmission/index.vue | 177 ------------------ copilot/index.html | 13 -- copilot/main.js | 32 ---- copilot/utils/index.js | 11 -- copilot/utils/ws.js | 19 -- electron/copilot/index.js | 45 ----- electron/copilot/wss/index.js | 34 ---- electron/main.js | 4 - jsconfig.json | 3 +- package.json | 5 +- vite.config.js | 2 - 14 files changed, 2 insertions(+), 542 deletions(-) delete mode 100644 copilot/App.vue delete mode 100644 copilot/components/Transmission/Message/Preset.vue delete mode 100644 copilot/components/Transmission/Message/index.vue delete mode 100644 copilot/components/Transmission/index.vue delete mode 100644 copilot/index.html delete mode 100644 copilot/main.js delete mode 100644 copilot/utils/index.js delete mode 100644 copilot/utils/ws.js delete mode 100644 electron/copilot/index.js delete mode 100644 electron/copilot/wss/index.js diff --git a/copilot/App.vue b/copilot/App.vue deleted file mode 100644 index ba631db1..00000000 --- a/copilot/App.vue +++ /dev/null @@ -1,63 +0,0 @@ - - - - - diff --git a/copilot/components/Transmission/Message/Preset.vue b/copilot/components/Transmission/Message/Preset.vue deleted file mode 100644 index 2391f35f..00000000 --- a/copilot/components/Transmission/Message/Preset.vue +++ /dev/null @@ -1,55 +0,0 @@ - - - - - diff --git a/copilot/components/Transmission/Message/index.vue b/copilot/components/Transmission/Message/index.vue deleted file mode 100644 index 70718842..00000000 --- a/copilot/components/Transmission/Message/index.vue +++ /dev/null @@ -1,81 +0,0 @@ - - - - - diff --git a/copilot/components/Transmission/index.vue b/copilot/components/Transmission/index.vue deleted file mode 100644 index abf5c475..00000000 --- a/copilot/components/Transmission/index.vue +++ /dev/null @@ -1,177 +0,0 @@ - - - - - diff --git a/copilot/index.html b/copilot/index.html deleted file mode 100644 index 40ea09f0..00000000 --- a/copilot/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - Escrcpy Copilot - - -
- - - diff --git a/copilot/main.js b/copilot/main.js deleted file mode 100644 index 978060d9..00000000 --- a/copilot/main.js +++ /dev/null @@ -1,32 +0,0 @@ -import { createApp, toRaw } from 'vue' -import App from './App.vue' -import { mockAPI } from './utils/index.js' -import ws from './utils/ws.js' -import { i18n, t } from '$/locales/index.js' -import plugins from '$/plugins/index.js' -import icons from '$/icons/index.js' - -import { replaceIP, restoreIP } from '$/utils/index.js' - -import 'virtual:uno.css' -import '$/styles/index.js' - -const app = createApp(App) - -app.use(plugins) - -app.use(icons) - -app.use(i18n) -window.t = t - -app.config.globalProperties.$replaceIP = replaceIP -app.config.globalProperties.$restoreIP = restoreIP - -app.config.globalProperties.$toRaw = toRaw - -app.config.globalProperties.$mockAPI = mockAPI - -app.config.globalProperties.$ws = ws - -app.mount('#app') diff --git a/copilot/utils/index.js b/copilot/utils/index.js deleted file mode 100644 index 3fcd4ab1..00000000 --- a/copilot/utils/index.js +++ /dev/null @@ -1,11 +0,0 @@ -export function mockAPI({ imitate = {}, delay = 500 } = {}) { - return new Promise((resolve) => { - setTimeout(() => { - resolve({ - code: '0000', - data: imitate, - success: true, - }) - }, delay) - }) -} diff --git a/copilot/utils/ws.js b/copilot/utils/ws.js deleted file mode 100644 index 9adf375b..00000000 --- a/copilot/utils/ws.js +++ /dev/null @@ -1,19 +0,0 @@ -const ws = new WebSocket('wss://websocket-echo.com/') - -let timeout = null -function heartbeat() { - clearTimeout(timeout) - - timeout = setTimeout(() => { - ws.close() - }, 30000 + 1000) -} - -ws.addEventListener('error', console.error) -ws.addEventListener('open', heartbeat) -ws.addEventListener('ping', heartbeat) -ws.addEventListener('close', () => { - clearTimeout(timeout) -}) - -export default ws diff --git a/electron/copilot/index.js b/electron/copilot/index.js deleted file mode 100644 index 18b2e187..00000000 --- a/electron/copilot/index.js +++ /dev/null @@ -1,45 +0,0 @@ -import { relative } from 'node:path' -import { Hono } from 'hono' -import { serve } from '@hono/node-server' -import { serveStatic } from '@hono/node-server/serve-static' -import createWebSocketServer from './wss/index' - -export default async (mainWindow) => { - const app = new Hono() - - app.notFound((c) => { - return c.text('Escrcpy copilot 404', 404) - }) - - const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL - - if (VITE_DEV_SERVER_URL) { - app.get('/', (ctx) => { - return ctx.redirect(`${VITE_DEV_SERVER_URL}copilot/index.html`) - }) - } - else { - app.use( - '/*', - serveStatic({ - root: relative('./', process.env.DIST), - rewriteRequestPath: (path) => { - return path.replace(/^\//, '/copilot') - }, - }), - ) - app.use( - '/assets/*', - serveStatic({ - root: relative('./', `${process.env.DIST}/assets/`), - rewriteRequestPath: (path) => { - return path.replace(/^\/assets/, '/') - }, - }), - ) - } - - createWebSocketServer() - - serve({ fetch: app.fetch, port: 1996 }) -} diff --git a/electron/copilot/wss/index.js b/electron/copilot/wss/index.js deleted file mode 100644 index 0690bcf8..00000000 --- a/electron/copilot/wss/index.js +++ /dev/null @@ -1,34 +0,0 @@ -import { WebSocketServer } from 'ws' - -function createWebSocketServer() { - const wss = new WebSocketServer({ port: 8080 }) - - function heartbeat(value = true) { - this.isAlive = value - } - - wss.on('connection', (ws) => { - heartbeat.call(ws) - ws.on('error', console.error) - ws.on('pong', heartbeat) - }) - - const interval = setInterval(() => { - wss.clients.forEach((ws) => { - if (ws.isAlive === false) { - return ws.terminate() - } - - heartbeat.call(ws, false) - ws.ping() - }) - }, 30000) - - wss.on('close', () => { - clearInterval(interval) - }) - - return wss -} - -export default createWebSocketServer diff --git a/electron/main.js b/electron/main.js index f037f6d6..9c1c74d6 100644 --- a/electron/main.js +++ b/electron/main.js @@ -18,8 +18,6 @@ import { icnsLogoPath, icoLogoPath, logoPath } from './configs/index.js' import events from './events/index.js' -// import copilot from './copilot/index.js' - const require = createRequire(import.meta.url) const __dirname = path.dirname(fileURLToPath(import.meta.url)) @@ -109,8 +107,6 @@ function createWindow() { } events(mainWindow) - - // copilot(mainWindow) } app.whenReady().then(() => { diff --git a/jsconfig.json b/jsconfig.json index cf6f6fc8..142b7809 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -3,12 +3,11 @@ "baseUrl": ".", "paths": { "$/*": ["src/*"], - "$copilot/*": ["copilot/*"], "$root/*": ["*"], "$electron/*": ["electron/*"], "$renderer/*": ["src/*"] } }, "exclude": ["node_modules", "dist", "dist-electron", "dist-release"], - "include": ["src", "electron", "copilot"] + "include": ["src", "electron"] } diff --git a/package.json b/package.json index 6ce52d3c..41e28c5a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "@electron-toolkit/preload": "^3.0.1", "@electron-toolkit/utils": "^3.0.0", "@electron/remote": "^2.1.2", - "@hono/node-server": "^1.11.1", "@intlify/unplugin-vue-i18n": "^4.0.0", "@unocss/reset": "^0.59.4", "@unocss/transformer-directives": "^0.59.4", @@ -52,7 +51,6 @@ "eslint": "^8.57.0", "fix-path": "^4.0.0", "fs-extra": "^11.2.0", - "hono": "^4.3.2", "husky": "^9.0.11", "lodash-es": "^4.17.21", "pinia": "^2.1.7", @@ -68,7 +66,6 @@ "vite-svg-loader": "^5.1.0", "vue-command": "^35.2.1", "vue-i18n": "^9.13.1", - "which": "^4.0.0", - "ws": "^8.17.0" + "which": "^4.0.0" } } diff --git a/vite.config.js b/vite.config.js index b878c7ef..8f06b17e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -35,14 +35,12 @@ export default args => rollupOptions: { input: { main: resolve('index.html'), - copilot: resolve('copilot/index.html'), }, }, }, resolve: { alias: { $: resolve('src'), - $copilot: resolve('copilot'), $electron: resolve('electron'), }, },