Compare commits

...

4 Commits

Author SHA1 Message Date
Timothy Jaeryang Baek d991908205 refac 2025-07-29 13:34:49 +04:00
Timothy Jaeryang Baek 2528096e07 fix: windows utf-8 issue 2025-07-29 13:32:38 +04:00
Timothy Jaeryang Baek aeba0e7c22 refac: logging 2025-07-29 13:23:30 +04:00
Timothy Jaeryang Baek ffbbb8f5b2 refac 2025-07-29 13:14:06 +04:00
4 changed files with 52 additions and 34 deletions
+7 -4
View File
@@ -16,12 +16,9 @@ import {
} from "electron";
import path, { join } from "path";
import { electronApp, optimizer, is } from "@electron-toolkit/utils";
import log from "electron-log";
import icon from "../../resources/icon.png?asset";
import trayIconImage from "../../resources/assets/tray.png?asset";
import {
getLogFilePath,
checkUrlAndOpen,
getConfig,
getServerLog,
@@ -38,6 +35,12 @@ import {
uninstallPython,
} from "./utils";
import log from "electron-log";
log.transports.file.resolvePathFn = () => getLogFilePath("main");
import icon from "../../resources/icon.png?asset";
import trayIconImage from "../../resources/assets/tray.png?asset";
// Main application logic
let mainWindow: BrowserWindow | null = null;
let tray: Tray | null = null;
+43 -12
View File
@@ -12,6 +12,18 @@ import { app, shell, Notification } from "electron";
import { execFileSync, exec, spawn, execSync, execFile } from "child_process";
import log from "electron-log";
log.transports.file.resolvePathFn = () => getLogFilePath("main");
const serverLogger = log.create({ logId: "server" });
serverLogger.transports.file.resolvePath = () => getLogFilePath(`server`);
export const getLogFilePath = (name: string = "main"): string => {
const logDir = path.join(getUserDataPath(), "logs");
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
}
return path.join(logDir, `${name}.log`);
};
export const getAppPath = (): string => {
let appPath = app.getAppPath();
@@ -346,6 +358,9 @@ export const installPython = async (
encoding: "utf-8",
env: {
...process.env,
...(process.platform === "win32"
? { PYTHONIOENCODING: "utf-8" }
: {}),
},
});
log.info("Successfully installed uv package");
@@ -387,6 +402,9 @@ export const isPythonInstalled = (installationPath?: string) => {
encoding: "utf-8",
env: {
...process.env,
...(process.platform === "win32"
? { PYTHONIOENCODING: "utf-8" }
: {}),
},
});
log.info("Installed Python Version:", pythonVersion.trim());
@@ -406,6 +424,9 @@ export const isUvInstalled = (installationPath?: string) => {
encoding: "utf-8",
env: {
...process.env,
...(process.platform === "win32"
? { PYTHONIOENCODING: "utf-8" }
: {}),
},
});
@@ -551,6 +572,9 @@ export const installPackage = (
{
env: {
...process.env,
...(process.platform === "win32"
? { PYTHONIOENCODING: "utf-8" }
: {}),
},
}
);
@@ -601,6 +625,9 @@ export const isPackageInstalled = (packageName: string): boolean => {
encoding: "utf-8",
env: {
...process.env,
...(process.platform === "win32"
? { PYTHONIOENCODING: "utf-8" }
: {}),
},
}
);
@@ -678,7 +705,12 @@ export const startServer = async (
const childProcess = spawn(pythonPath, commandArgs, {
detached: process.platform !== "win32",
stdio: ["ignore", "pipe", "pipe"],
env: { ...process.env },
env: {
...process.env,
...(process.platform === "win32"
? { PYTHONIOENCODING: "utf-8" }
: {}),
},
});
if (!childProcess.pid) {
@@ -691,24 +723,23 @@ export const startServer = async (
const appendLog = (source: string) => (data: Buffer) => {
const logLine = data.toString().trim();
const tag = `[${source}][PID:${childProcess.pid}]:`;
logLines.push(`${tag} ${logLine}`);
// (Optional) also log to main process console
// log.info(`${tag} ${logLine}`);
const line = `[${source}][PID:${childProcess.pid}]: ${logLine}`;
logLines.push(line);
serverLogger.info(line); // Log to console
};
childProcess.stdout?.on("data", appendLog("stdout"));
childProcess.stderr?.on("data", appendLog("stderr"));
childProcess.on("close", (code, signal) => {
logLines.push(
`[process][PID:${childProcess.pid}] Exited with code ${code} signal ${signal}`
);
const line = `[process][PID:${childProcess.pid}] Exited with code ${code} signal ${signal}`;
serverLogger.info(line);
logLines.push(line);
serverPIDs.delete(childProcess.pid);
// Note: we keep the logs available until manually cleared
});
childProcess.on("error", (err) => {
logLines.push(
`[process][PID:${childProcess.pid}] Error: ${err.message}`
);
const line = `[process][PID:${childProcess.pid}] Error: ${err.message}`;
serverLogger.error(line);
logLines.push(line);
});
// Compute URL directly, do not try to parse logs
@@ -779,7 +810,7 @@ export const checkUrlAndOpen = async (
url: string,
callback: Function = async () => {}
) => {
const maxAttempts = 150; // 5 minutes with 2-second intervals
const maxAttempts = 1800; // 60 minutes with 2-second intervals
const interval = 2000; // 2 seconds
let attempts = 0;
@@ -11,20 +11,12 @@
import galaxyImage from "../assets/images/galaxy.jpg";
import greenImage from "../assets/images/green.jpg";
import adamImage from "../assets/images/adam.jpg";
import earthImage from "../assets/images/earth.jpg";
import nasaImage from "../assets/images/nasa.jpg";
import neomImage from "../assets/images/neom.jpg";
let { installed = $bindable() } = $props();
let images = [
galaxyImage,
greenImage,
adamImage,
earthImage,
nasaImage,
neomImage,
];
let images = [galaxyImage, greenImage, adamImage, nasaImage, neomImage];
let mounted = $state(false);
let currentTime = Date.now();
@@ -7,19 +7,11 @@
import galaxyImage from "../assets/images/galaxy.jpg";
import greenImage from "../assets/images/green.jpg";
import adamImage from "../assets/images/adam.jpg";
import earthImage from "../assets/images/earth.jpg";
import nasaImage from "../assets/images/nasa.jpg";
import neomImage from "../assets/images/neom.jpg";
import { fly } from "svelte/transition";
let images = [
galaxyImage,
greenImage,
adamImage,
earthImage,
nasaImage,
neomImage,
];
let images = [galaxyImage, greenImage, adamImage, nasaImage, neomImage];
let startTime = $state(null);
let currentTime = $state(null);