Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed Aug 12, 2024
1 parent 9dea19b commit 9ba9c90
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
11 changes: 10 additions & 1 deletion seeder/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default defineConfig({
$constants: resolve(__dirname, "./src/main/constants"),
$interfaces: resolve(__dirname, "./src/main/interfaces"),
$backend: resolve(__dirname, "./src/main/backend"),
$worker: resolve(__dirname, "./src/main/workers"),
$workers: resolve(__dirname, "./src/main/workers"),
$utils: resolve(__dirname, "./src/main/utils")
}
}
Expand All @@ -39,6 +39,15 @@ export default defineConfig({
},
chunkSizeWarningLimit: undefined,
minify: "terser"
},
resolve: {
alias: {
$constants: resolve(__dirname, "./src/main/constants"),
$interfaces: resolve(__dirname, "./src/main/interfaces"),
$backend: resolve(__dirname, "./src/main/backend"),
$workers: resolve(__dirname, "./src/main/workers"),
$utils: resolve(__dirname, "./src/main/utils")
}
}
},

Expand Down
16 changes: 8 additions & 8 deletions seeder/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import { app, shell, BrowserWindow, ipcMain } from "electron";
import { join } from "path";
import { electronApp, optimizer, is } from "@electron-toolkit/utils";
import icon from "../../resources/icon.png?asset";
import { Shiinobi as _Shiinobi } from "$interfaces/shiinobi";
import { get_free_port } from "$utils/port";
import ExpressWorder from "$worker/express_worker?nodeWorker";
import { Shiinobi as _Shiinobi, COMMANDS as SHIINOBI_COMMANDS } from "./interfaces/shiinobi";

const Shiinobi = new _Shiinobi();
import ExpressWorder from "$workers/express_worker?nodeWorker";

const IPC_MAPPING = {
"get-staff-urls": Shiinobi.get_myanimelist_staff_urls
};
const Shiinobi = new _Shiinobi();

async function createWindow(): Promise<void> {
// Create the browser window.
Expand Down Expand Up @@ -63,8 +60,11 @@ app.whenReady().then(async () => {
// IPC handlers
ipcMain.handle("get-app-version", () => app.getVersion());
// Shiinobi
Object.entries(IPC_MAPPING).forEach((item) => {
ipcMain.handle(item[0], async () => await item[1]());
SHIINOBI_COMMANDS.forEach((item) => {
const function_name = item.replaceAll("-", "_");
ipcMain.handle(function_name, async () => {
return Shiinobi[function_name]();
});
});

const express_port = await get_free_port();
Expand Down
31 changes: 16 additions & 15 deletions seeder/src/main/interfaces/shiinobi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import { spawn } from "child_process";
import { IS_LINUX, IS_MAC, IS_WINDOWS } from "$constants/os";
import { join } from "path";

type _COMMANDS =
| "get-myanimelist-anime-explicit-genres"
| "get-myanimelist-anime-genres"
| "get-myanimelist-anime-themes"
| "get-myanimelist-anime-urls"
| "get-myanimelist-character-urls"
| "get-myanimelist-demographics"
| "get-myanimelist-specific-anime-character-and-staff-list-information"
| "get-myanimelist-specific-anime-genre-information"
| "get-myanimelist-specific-anime-information"
| "get-myanimelist-specific-character-information"
| "get-myanimelist-specific-producer-information"
| "get-myanimelist-specific-staff-information"
| "get-myanimelist-staff-urls";
export const COMMANDS = [
"get-myanimelist-anime-explicit-genres",
"get-myanimelist-anime-genres",
"get-myanimelist-anime-themes",
"get-myanimelist-anime-urls",
"get-myanimelist-character-urls",
"get-myanimelist-demographics",
"get-myanimelist-specific-anime-character-and-staff-list-information",
"get-myanimelist-specific-anime-genre-information",
"get-myanimelist-specific-anime-information",
"get-myanimelist-specific-character-information",
"get-myanimelist-specific-producer-information",
"get-myanimelist-specific-staff-information",
"get-myanimelist-staff-urls"
];

class Shiinobi {
get #shiinobi() {
Expand All @@ -30,7 +31,7 @@ class Shiinobi {
}
}

#spawn({ command, id }: { command: _COMMANDS; id?: number }) {
#spawn({ command, id }: { command: (typeof COMMANDS)[0]; id?: number }) {
const _command: string[] = [command];
if (id) _command.push(String(id));

Expand Down
3 changes: 2 additions & 1 deletion seeder/src/preload/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ElectronAPI } from "@electron-toolkit/preload";
import { COMMANDS as SHIINOBI_COMMANDS } from "$interfaces/shiinobi";

declare global {
interface Window {
electron: ElectronAPI;
api: {
get_app_version: () => Promise<string>;
// Shiinobi
get_staff_urls: () => Promise<object>;
[key in typeof SHIINOBI_COMMANDS[number]]: () => Promise<object>;
};
}
}
10 changes: 7 additions & 3 deletions seeder/src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { contextBridge, ipcRenderer } from "electron";
import { electronAPI } from "@electron-toolkit/preload";
import { COMMANDS as SHIINOBI_COMMANDS } from "$interfaces/shiinobi";

// Custom APIs for renderer
const api = {
get_app_version: () => ipcRenderer.invoke("get-app-version"),
// Shiinobi
get_staff_urls: () => ipcRenderer.invoke("get-staff-urls")
get_app_version: () => ipcRenderer.invoke("get-app-version")
};

SHIINOBI_COMMANDS.forEach((item) => {
const function_name = item.replaceAll("-", "_");
api[function_name] = () => ipcRenderer.invoke(function_name);
});

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
Expand Down
1 change: 0 additions & 1 deletion seeder/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"composite": true,
"types": ["electron-vite/node"],
"paths": {
"$main/*": ["./src/main/*"],
"$constants/*": ["./src/main/constants/*"],
"$interfaces/*": ["./src/main/interfaces/*"],
"$workers/*":["./src/main/workers/*"],
Expand Down

0 comments on commit 9ba9c90

Please sign in to comment.