technically builds and runs now

This commit is contained in:
kvan7
2026-07-08 06:54:58 -05:00
parent fffec3ead7
commit 972215ca8b
7 changed files with 38 additions and 26 deletions
+8 -7
View File
@@ -18,22 +18,23 @@ const electronRunner = (() => {
}
})()
const visionBuild = await esbuild.build({
entryPoints: ['src/vision/link-worker.ts'],
bundle: true,
platform: 'node',
outfile: 'dist/vision.js'
})
// const visionBuild = await esbuild.build({
// entryPoints: ['src/vision/link-worker.ts'],
// bundle: true,
// platform: 'node',
// outfile: 'dist/vision.js'
// })
const mainContext = await esbuild.context({
entryPoints: ['src/main.ts'],
bundle: true,
minify: !isDev,
platform: 'node',
external: ['electron', 'uiohook-napi', 'electron-overlay-window', 'canvas', "@u4/opencv-build", "@u4/opencv4nodejs",],
external: ['electron', 'uiohook-napi', 'electron-overlay-window', 'canvas', '@u4/opencv-build', '@u4/opencv4nodejs'],
outfile: 'dist/main.js',
define: {
'process.env.STATIC': (isDev) ? '"../build/icons"' : '"."',
'process.env.GENERATED': (isDev) ? '"../build/generated"' : '"."',
'process.env.VITE_DEV_SERVER_URL': (isDev) ? '"http://localhost:5173"' : 'null'
},
plugins: (isDev) ? [{
+2 -1
View File
@@ -25,7 +25,8 @@ if (process.platform !== "darwin") {
}
app.enableSandbox();
let tray: AppTray;
process.on("uncaughtException", console.error);
process.on("unhandledRejection", console.error);
(async () => {
if (process.platform === "darwin") {
async function ensureAccessibilityPermission(): Promise<boolean> {
+2
View File
@@ -23,6 +23,7 @@ export class RuneRecipeFinder {
}
async calibrate(screenshot: ImageData): Promise<CalibrationResult> {
console.log("calibrate");
return await this.cv.calibrate(screenshot);
}
@@ -30,6 +31,7 @@ export class RuneRecipeFinder {
screenshot: ImageData,
calibration: CalibrationResult,
): Promise<RecipeResult> {
console.log("findRecipeId");
const start = performance.now();
const res = await this.cv.findRecipeId(screenshot, calibration);
const elapsed = performance.now() - start;
+2
View File
@@ -17,6 +17,7 @@ export class CppCvAdapter implements ICvAdapter {
//#region Interface Methods
async calibrate(screenshot: ImageData): Promise<CalibrationResult> {
console.log("calibrate cpp");
const img = await this.loadImage(Buffer.from(screenshot.data));
const { scale, recipeBBox } = calibrateBBox(img);
return {
@@ -32,6 +33,7 @@ export class CppCvAdapter implements ICvAdapter {
highlightedSlot: number;
tomeCount: number;
}> {
console.log("findRecipeId cpp");
const img = await this.loadImage(Buffer.from(screenshot.data));
const { bbox, scale } = calibration;
const tomeSize = getTomePxSize(scale, img.rows);
+2
View File
@@ -17,6 +17,7 @@ export class JsCvAdapter implements ICvAdapter {
//#region Interface Methods
async calibrate(screenshot: ImageData): Promise<CalibrationResult> {
// REVIEW: ALL ALLOCATIONS MUST BE DELETED AFTER USE
console.log("calibrate js");
const img = await getImage(Buffer.from(screenshot.data));
try {
const { scale, recipeBBox } = await calibrateBBox(img);
@@ -37,6 +38,7 @@ export class JsCvAdapter implements ICvAdapter {
tomeCount: number;
}> {
// REVIEW: ALL ALLOCATIONS MUST BE DELETED AFTER USE
console.log("findRecipeId js");
const img = await getImage(Buffer.from(screenshot.data));
const { bbox, scale } = calibration;
const firstRecipe = img.roi(
+3 -3
View File
@@ -48,19 +48,19 @@ export const GENERATED_DIR = "./generated/";
export const PREPROCESSED_TOME_BG = path.join(
__dirname,
process.env.STATIC!,
process.env.GENERATED!,
GENERATED_DIR,
"bg.png",
);
export const PREPROCESSED_ACTIVE_TOME_BG = path.join(
__dirname,
process.env.STATIC!,
process.env.GENERATED!,
GENERATED_DIR,
"active_bg.png",
);
export const PREPROCESSED_MATCH_LIST = path.join(
__dirname,
process.env.STATIC!,
process.env.GENERATED!,
GENERATED_DIR,
"match_list.png",
);
+19 -15
View File
@@ -21,7 +21,8 @@ export class CvWrapper {
}
constructor() {
this._ready = this.reload();
this._cv = undefined;
this._ready = this._load();
}
async reload(): Promise<void> {
@@ -36,7 +37,7 @@ export class CvWrapper {
this._cv = new CppCvAdapter(cpp);
return;
}
this._cv = new JsCvAdapter(await this._loadJs());
this._cv = new JsCvAdapter((await this._loadJs()).cv);
}
private async _tryCpp(): Promise<typeof openCv | undefined> {
@@ -53,21 +54,24 @@ export class CvWrapper {
}
}
private async _loadJs(): Promise<typeof cvModule> {
private async _loadJs(): Promise<{ cv: typeof cvModule }> {
let cv: typeof cvModule;
if (cvModule instanceof Promise) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- should be fine
return await cvModule;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- is of correct type
cv = await cvModule;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- actually not always true
} else if (cvModule.Mat) {
cv = cvModule;
} else {
await new Promise<void>((resolve) => {
cvModule.onRuntimeInitialized = () => {
resolve();
};
});
cv = cvModule;
}
if (cvModule.Mat) {
return cvModule;
}
await new Promise<void>((resolve) => {
cvModule.onRuntimeInitialized = () => {
console.log("OpenCV JS is ready");
resolve();
};
});
return cvModule;
return { cv };
}
}