feat: Add Affiliated Web Services

This commit is contained in:
viarotel 2023-11-17 18:42:50 +08:00
parent c967cb5a1a
commit 009e9d9071
8 changed files with 74 additions and 1 deletions

View File

@ -14,6 +14,8 @@ import { icnsLogoPath, icoLogoPath, logoPath } from './configs/index.js'
import events from './events/index.js'
import server from './server/index.js'
log.initialize({ preload: true })
const debug = !!appStore.get('common.debug')
@ -101,6 +103,8 @@ function createWindow() {
}
events(mainWindow)
server(mainWindow)
}
app.whenReady().then(() => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

43
electron/server/index.js Normal file
View File

@ -0,0 +1,43 @@
import { relative } from 'node:path'
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
import { serveStatic } from '@hono/node-server/serve-static'
export default async (mainWindow) => {
const app = new Hono()
app.notFound((c) => {
return c.text('Escrcpy server 404', 404)
})
const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL
if (VITE_DEV_SERVER_URL) {
app.get('/', ctx =>
ctx.redirect(`${VITE_DEV_SERVER_URL}server/index.html`),
)
}
else {
app.use(
'/*',
serveStatic({
root: relative('./', process.env.DIST),
rewriteRequestPath: (path) => {
return path.replace(/^\//, '/server')
},
}),
)
app.use(
'/assets/*',
serveStatic({
root: relative('./', `${process.env.DIST}/assets/`),
rewriteRequestPath: (path) => {
console.log('path', path)
return path.replace(/^\/assets/, '/')
},
}),
)
}
serve({ fetch: app.fetch, port: 1996 })
}

View File

@ -25,6 +25,7 @@
"@devicefarmer/adbkit": "^3.2.5",
"@electron-toolkit/preload": "^2.0.0",
"@electron-toolkit/utils": "^2.0.1",
"@hono/node-server": "^1.2.3",
"@intlify/unplugin-vue-i18n": "^1.4.0",
"@viarotel-org/design": "^0.7.0",
"@viarotel-org/eslint-config": "^0.7.0",
@ -41,6 +42,7 @@
"element-plus": "^2.4.2",
"fix-path": "^4.0.0",
"fs-extra": "^11.1.1",
"hono": "^3.10.1",
"husky": "^8.0.0",
"lodash-es": "^4.17.21",
"pinia": "^2.1.7",

13
server/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/logo.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Escrcpy-Server</title>
</head>
<body class="">
<div id="app"></div>
<script type="module" src="main.js"></script>
</body>
</html>

3
server/main.js Normal file
View File

@ -0,0 +1,3 @@
import { createApp } from 'vue'
console.log('createApp', createApp)

View File

@ -45,4 +45,4 @@ app.mount('#app').$nextTick(() => {
postMessage({ payload: 'removeLoading' }, '*')
})
console.log('electron.configs', window.electron.configs)
console.log('electron', window.electron)

View File

@ -31,6 +31,14 @@ const merge = (config, { command = '' } = {}) =>
export default params =>
merge(
defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
server: resolve(__dirname, 'server/index.html'),
},
},
},
resolve: {
alias: {
'@': resolve('src'),