Skip to content

Commit

Permalink
feat: ✨ Add Affiliated Web Services
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Nov 17, 2023
1 parent c967cb5 commit 009e9d9
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -101,6 +103,8 @@ function createWindow() {
}

events(mainWindow)

server(mainWindow)
}

app.whenReady().then(() => {
Expand Down
Binary file added electron/resources/extra/common/tray/icon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions electron/server/index.js
Original file line number Diff line number Diff line change
@@ -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 })
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions server/index.html
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions server/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createApp } from 'vue'

console.log('createApp', createApp)
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ app.mount('#app').$nextTick(() => {
postMessage({ payload: 'removeLoading' }, '*')
})

console.log('electron.configs', window.electron.configs)
console.log('electron', window.electron)
8 changes: 8 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 009e9d9

Please sign in to comment.