This commit is contained in:
rosetta
2026-01-30 05:01:05 +02:00
commit 83f38dc63f
327 changed files with 18725 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import { ipcMain } from 'electron';
import { runQuery, getQuery, allQuery } from '../database';
ipcMain.handle('db:run', async (_, query: string, params: any[]) => {
return await runQuery(query, params);
});
ipcMain.handle('db:get', async (_, query: string, params: any[]) => {
return await getQuery(query, params);
});
ipcMain.handle('db:all', async (_, query: string, params: any[]) => {
return await allQuery(query, params);
});

View File

@@ -0,0 +1,36 @@
import { ipcMain } from "electron";
import os from "os";
import {machineId} from 'node-machine-id';
/**
* Consturct device name.
* Ex: Macbook Pro M3
*/
ipcMain.handle('device:name', () => {
const type = os.type(); // 'Darwin', 'Windows_NT', 'Linux'
let deviceName = "";
if (type === "Darwin") {
deviceName += "Mac";
} else if (type === "Windows_NT") {
deviceName += "Windows";
} else if (type === "Linux") {
deviceName += "Linux";
} else {
deviceName += type + " ";
}
const cpus = os.cpus();
if (cpus && cpus.length > 0) {
const cpuModel = cpus[0].model;
deviceName += cpuModel.replace("Apple", "").replace("Processor", "");
}
return deviceName.trim();
});
ipcMain.handle('device:id', async () => {
return await machineId();
});

View File

@@ -0,0 +1,22 @@
import { ipcMain } from "electron";
import { WORKING_DIR } from "../constants";
import fs from 'fs/promises'
import path from 'path'
ipcMain.handle('fileStorage:writeFile', async (_, file: string, data: string | Buffer, inWorkingDir : boolean = true) => {
const fullPath = path.join(inWorkingDir ? WORKING_DIR : '', file);
await fs.mkdir(path.dirname(fullPath), { recursive: true });
await fs.writeFile(fullPath, data);
console.info("File written to " + fullPath);
return true;
});
ipcMain.handle('fileStorage:readFile', async (_, file: string, inWorkingDir : boolean = true) => {
try{
const fullPath = path.join(inWorkingDir ? WORKING_DIR : '', file);
const data = await fs.readFile(fullPath);
return data;
}catch(e){
return null;
}
});

View File

@@ -0,0 +1,10 @@
import { ipcMain } from 'electron';
import { promises as fs } from 'fs';
import { LOGFILE_PATH } from '../constants';
ipcMain.handle('logger:log', async (_, logString) => {
console.log(logString);
await fs.appendFile(LOGFILE_PATH, logString + '\n');
});

View File

@@ -0,0 +1,16 @@
import { ipcMain, Notification } from "electron";
import { restoreApplicationAfterClickOnTrayOrDock } from "../main";
ipcMain.handle('notification:show', async (_, title: string, body: string) => {
let id = Math.random().toString(36).substring(2, 15);
let note = new Notification({
title: title,
body: body
});
note.on('click', () => {
restoreApplicationAfterClickOnTrayOrDock();
ipcMain.emit('notification:clicked', id);
});
note.show();
return id;
});

View File

@@ -0,0 +1,14 @@
import { app, ipcMain } from "electron";
import { installServiceUpdate } from "../boot/updater";
import path from "path";
import { WORKING_DIR } from "../constants";
ipcMain.handle('update:installServiceUpdate', async (_, bundleName: string) => {
await installServiceUpdate(path.join(WORKING_DIR, bundleName));
});
ipcMain.handle('update:restartApp', async () => {
app.relaunch();
app.exit(0);
});