build server into desktop app

This commit is contained in:
Jeffrey Morgan 2023-06-25 00:30:02 -04:00
parent 369108e1ad
commit d3709f85b5
10 changed files with 31 additions and 55 deletions

4
.gitignore vendored
View file

@ -1,6 +1,2 @@
.DS_Store
.vscode
*.spec
*/build
*/dist
client/resources/server

View file

@ -13,6 +13,7 @@ const config: ForgeConfig = {
packagerConfig: {
asar: true,
icon: './images/icon',
extraResource: ['../server/dist/server'],
},
rebuildConfig: {},
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],

View file

@ -1,24 +0,0 @@
import chmodr from 'chmodr'
import * as path from 'path'
interface PluginOptions {
resourcePath: string
}
class PermissionsPlugin {
options: PluginOptions
constructor(options: PluginOptions) {
this.options = options
}
apply(compiler: any) {
compiler.hooks.afterEmit.tap('PermissionsPlugin', () => {
chmodr(path.join(this.options.resourcePath), 0o755, err => {
// this fails on the first call to suppress the error
})
})
}
}
export default PermissionsPlugin

View file

@ -1,6 +1,6 @@
import { useState } from 'react'
const API_URL = 'http://127.0.0.1:5000'
const API_URL = 'http://127.0.0.1:5001'
type Message = {
sender: string

View file

@ -21,26 +21,34 @@ const createWindow = (): void => {
minWidth: 400,
minHeight: 300,
titleBarStyle: 'hiddenInset',
// trafficLightPosition: { x: 20, y: 18 },
// vibrancy: 'titlebar',
transparent: true,
})
// Start the executable
let pyExecutable = path.join(__dirname, '../renderer/resources/server')
console.log(`Starting ${pyExecutable}`)
let pyProcess = spawn(pyExecutable)
pyProcess.stdout.on('data', data => {
console.log(`server: ${data}`)
})
pyProcess.stderr.on('data', data => {
console.error(`server: ${data}`)
})
// and load the index.html of the app.
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
}
// if the app is packaged then run the server
if (app.isPackaged) {
const resources = process.resourcesPath
console.log(resources)
// Start the executable
const exec = path.join(resources, 'server')
console.log(`Starting ${exec}`)
const proc = spawn(exec)
proc.stdout.on('data', data => {
console.log(`server: ${data}`)
})
proc.stderr.on('data', data => {
console.error(`server: ${data}`)
})
process.on('exit', () => {
proc.kill()
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.

View file

@ -1,19 +1,10 @@
import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import * as path from 'path'
import PermissionsPlugin from './permissions-plugin'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
export const plugins = [
new ForkTsCheckerWebpackPlugin({
logger: 'webpack-infrastructure',
}),
new CopyWebpackPlugin({
patterns: [{ from: 'resources', to: 'resources' }],
}),
new PermissionsPlugin({
resourcePath: '.webpack/renderer/resources/server',
}),
]

1
models/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.bin

5
server/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.env
.venv
*.spec
build
dist

View file

@ -1,6 +1,5 @@
import site
import os
import shutil
from PyInstaller.__main__ import run as pyi_run
# the llama_cpp directory is not included if not explicitly added
@ -13,10 +12,9 @@ args = [
site_packages_dir,
"--add-data",
f"{llama_cpp_dir}{os.pathsep}llama_cpp",
"--onefile",
"--onefile"
]
# generate the .spec file and run PyInstaller
pyi_run(args)
shutil.copy2("dist/server", "../client/resources/server")

View file

@ -76,4 +76,4 @@ def generate():
if __name__ == "__main__":
app.run(debug=True, threaded=True, port=5000)
app.run(debug=True, threaded=True, port=5001)