Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLC-37] Make app production ready with builds #19

Merged
merged 5 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/mac/entitlements.mac.inherit.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
40 changes: 29 additions & 11 deletions app/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Main File for Electron

import {
execFile,
} from 'child_process';
import {
app,
BrowserWindow,
Expand Down Expand Up @@ -45,13 +48,15 @@ class ServerManager {
});
}

private runPythonServer(model: string, port: number): any {
const args = [`--model ${model}`, '--host 127.0.0.1', `--port ${port}`];
private runPythonServer(port: number): any {
const args = ['--host 127.0.0.1', `--port ${port}`];
const modifiedArgs = args.flatMap(arg => arg.split(/\s+/));

const pythonProcess = spawn('python', ['-m', 'server.server', ...modifiedArgs], {
cwd: '../',
});
const pythonProcess = isProd
? execFile(path.join(process.resourcesPath, 'server', 'runner'), modifiedArgs)
: spawn('python', ['-m', 'server.server', ...modifiedArgs], {
cwd: '../',
});
pythonProcess.stdout.on(
'data',
(data: Buffer) => console.log('Server output:', data.toString('utf8')),
Expand All @@ -69,16 +74,29 @@ class ServerManager {
this.stop();

this.findOpenPort(8080).then((port) => {
console.log(`Starting server for model: ${model} on port: ${port}`);
this.serverProcess = this.runPythonServer(model, port);
console.log(`APP: Starting server for model: ${model} on port: ${port}`);
this.serverProcess = this.runPythonServer(port);

this.serverProcess.stdout.on('data', (data: Buffer) => {
this.serverProcess.stdout.on('data', async (data: Buffer) => {
const output = data.toString('utf8');
console.log('Server output:', output);

await new Promise((resolve) => setTimeout(resolve, 1000));

// Check if the server is ready
if (output.includes('starting server on')) {
resolve(); // Resolve the promise when the server is ready
if (output.includes('Starting httpd')) {
fetch(`http://127.0.0.1:${port}/api/init`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ model }),
}).then(() => {
resolve(); // Resolve the promise when the server is ready
}).catch((err) => {
console.error('Error initializing the server:', err);
reject(err);
});
}
});

Expand Down Expand Up @@ -280,7 +298,7 @@ const createWindow = () => {
});

if (isProd) {
settingsModal.loadURL('app://./home.html');
settingsModal.loadURL('app://./settings.html');
} else {
// const port = process.argv[2];
settingsModal.loadURL('http://localhost:3000/settings');
Expand Down
18 changes: 18 additions & 0 deletions app/notarize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require('dotenv').config();
const { notarize } = require('electron-notarize');

exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin') {
return;
}

const appName = context.packager.appInfo.productFilename;

return await notarize({
appBundleId: 'com.parkersmith.mlx-chat',
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLEID,
appleIdPassword: process.env.APPLEIDPASS,
});
};
Loading
Loading