build server into desktop app
This commit is contained in:
parent
369108e1ad
commit
d3709f85b5
10 changed files with 31 additions and 55 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,6 +1,2 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.vscode
|
.vscode
|
||||||
*.spec
|
|
||||||
*/build
|
|
||||||
*/dist
|
|
||||||
client/resources/server
|
|
|
@ -13,6 +13,7 @@ const config: ForgeConfig = {
|
||||||
packagerConfig: {
|
packagerConfig: {
|
||||||
asar: true,
|
asar: true,
|
||||||
icon: './images/icon',
|
icon: './images/icon',
|
||||||
|
extraResource: ['../server/dist/server'],
|
||||||
},
|
},
|
||||||
rebuildConfig: {},
|
rebuildConfig: {},
|
||||||
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
|
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
|
||||||
|
|
|
@ -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
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
const API_URL = 'http://127.0.0.1:5000'
|
const API_URL = 'http://127.0.0.1:5001'
|
||||||
|
|
||||||
type Message = {
|
type Message = {
|
||||||
sender: string
|
sender: string
|
||||||
|
|
|
@ -21,26 +21,34 @@ const createWindow = (): void => {
|
||||||
minWidth: 400,
|
minWidth: 400,
|
||||||
minHeight: 300,
|
minHeight: 300,
|
||||||
titleBarStyle: 'hiddenInset',
|
titleBarStyle: 'hiddenInset',
|
||||||
// trafficLightPosition: { x: 20, y: 18 },
|
|
||||||
// vibrancy: 'titlebar',
|
|
||||||
transparent: true,
|
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.
|
// and load the index.html of the app.
|
||||||
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
|
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
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
|
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
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
|
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
||||||
|
|
||||||
export const plugins = [
|
export const plugins = [
|
||||||
new ForkTsCheckerWebpackPlugin({
|
new ForkTsCheckerWebpackPlugin({
|
||||||
logger: 'webpack-infrastructure',
|
logger: 'webpack-infrastructure',
|
||||||
}),
|
}),
|
||||||
new CopyWebpackPlugin({
|
|
||||||
patterns: [{ from: 'resources', to: 'resources' }],
|
|
||||||
}),
|
|
||||||
new PermissionsPlugin({
|
|
||||||
resourcePath: '.webpack/renderer/resources/server',
|
|
||||||
}),
|
|
||||||
]
|
]
|
||||||
|
|
1
models/.gitignore
vendored
Normal file
1
models/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*.bin
|
5
server/.gitignore
vendored
Normal file
5
server/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
*.spec
|
||||||
|
build
|
||||||
|
dist
|
|
@ -1,6 +1,5 @@
|
||||||
import site
|
import site
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
from PyInstaller.__main__ import run as pyi_run
|
from PyInstaller.__main__ import run as pyi_run
|
||||||
|
|
||||||
# the llama_cpp directory is not included if not explicitly added
|
# the llama_cpp directory is not included if not explicitly added
|
||||||
|
@ -13,10 +12,9 @@ args = [
|
||||||
site_packages_dir,
|
site_packages_dir,
|
||||||
"--add-data",
|
"--add-data",
|
||||||
f"{llama_cpp_dir}{os.pathsep}llama_cpp",
|
f"{llama_cpp_dir}{os.pathsep}llama_cpp",
|
||||||
"--onefile",
|
"--onefile"
|
||||||
]
|
]
|
||||||
|
|
||||||
# generate the .spec file and run PyInstaller
|
# generate the .spec file and run PyInstaller
|
||||||
pyi_run(args)
|
pyi_run(args)
|
||||||
|
|
||||||
shutil.copy2("dist/server", "../client/resources/server")
|
|
||||||
|
|
|
@ -76,4 +76,4 @@ def generate():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True, threaded=True, port=5000)
|
app.run(debug=True, threaded=True, port=5001)
|
||||||
|
|
Loading…
Reference in a new issue