Skip to content
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
13 changes: 6 additions & 7 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { zipFolder } from './utils/log'
import axios from 'axios';
import FormData from 'form-data';
import { checkAndInstallDepsOnUpdate, PromiseReturnType, getInstallationStatus } from './install-deps'
import e from 'express'

const userData = app.getPath('userData');

Expand Down Expand Up @@ -841,7 +840,7 @@ function registerIpcHandlers() {
ipcMain.handle('check-tool-installed', async () => {
try {
const isInstalled = await checkToolInstalled();
return { success: true, isInstalled };
return { success: true, isInstalled: isInstalled.success };
} catch (error) {
return { success: false, error: (error as Error).message };
}
Expand Down Expand Up @@ -987,21 +986,21 @@ const checkAndStartBackend = async () => {
log.info('Checking and starting backend service...');
try {
const isToolInstalled = await checkToolInstalled();
if (isToolInstalled) {
if (isToolInstalled.success) {
log.info('Tool installed, starting backend service...');

// Notify frontend installation success
if (win && !win.isDestroyed()) {
win.webContents.send('install-dependencies-complete', { success: true, code: 0 });
}

python_process = await startBackend((port) => {
backendPort = port;
log.info('Backend service started successfully', { port });
});

python_process?.on('exit', (code, signal) => {

log.info('Python process exited', { code, signal });
});
} else {
Expand Down
2 changes: 2 additions & 0 deletions electron/main/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ export async function checkToolInstalled() {
return new Promise<PromiseReturnType>(async (resolve, reject) => {
if (!(await isBinaryExists('uv'))) {
resolve({success: false, message: "uv doesn't exist"})
return
}

if (!(await isBinaryExists('bun'))) {
resolve({success: false, message: "Bun doesn't exist"})
return
}

resolve({success: true, message: "Tools exist already"})
Expand Down
18 changes: 10 additions & 8 deletions electron/main/install-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Promise<PromiseReturnType> => {
* Check if command line tools are installed, install if not
*/
export async function installCommandTool(): Promise<PromiseReturnType> {
return new Promise(async (resolve, reject) => {
try {
const ensureInstalled = async (toolName: 'uv' | 'bun', scriptName: string): Promise<PromiseReturnType> => {
Comment on lines 102 to 104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Catch. Looked into it & you are right, new Promise is unnecessary here & in many others. Its just a js way to create manual low-level async for non awaitable functions.

These days TypeScript automatically wraps the return value in a Promise for async funcs.

// Even though you return a string, the function returns Promise<string>
async function getName(): Promise<string> {
  return "John"; // TypeScript wraps this in Promise.resolve("John")
}

// This is equivalent to:
function getNameManual(): Promise<string> {
  return Promise.resolve("John"); //& ya, static function, no need to create class
}

Thanks @Wendong-Fan , LGTM.

if (await isBinaryExists(toolName)) {
return { message: `${toolName} already installed`, success: true };
Expand All @@ -123,24 +123,26 @@ export async function installCommandTool(): Promise<PromiseReturnType> {
});
}

return {
return {
message: installed ? `${toolName} installed successfully` : `${toolName} installation failed`,
success: installed
success: installed
};
};

const uvResult = await ensureInstalled('uv', 'install-uv.js');
if (!uvResult.success) {
return reject({ message: uvResult.message, success: false });
return { message: uvResult.message, success: false };
}

const bunResult = await ensureInstalled('bun', 'install-bun.js');
if (!bunResult.success) {
return reject({ message: bunResult.message, success: false });
return { message: bunResult.message, success: false };
}

return resolve({ message: "Command tools installed successfully", success: true });
})
return { message: "Command tools installed successfully", success: true };
} catch (error) {
return { message: `Command tool installation failed: ${error}`, success: false };
}
}

let uv_path:string;
Expand Down