'init'
This commit is contained in:
14
lib/main/ipcs/ipcDatabase.ts
Normal file
14
lib/main/ipcs/ipcDatabase.ts
Normal 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);
|
||||
});
|
||||
36
lib/main/ipcs/ipcDevice.ts
Normal file
36
lib/main/ipcs/ipcDevice.ts
Normal 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();
|
||||
});
|
||||
22
lib/main/ipcs/ipcFilestorage.ts
Normal file
22
lib/main/ipcs/ipcFilestorage.ts
Normal 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;
|
||||
}
|
||||
});
|
||||
10
lib/main/ipcs/ipcLogger.ts
Normal file
10
lib/main/ipcs/ipcLogger.ts
Normal 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');
|
||||
});
|
||||
16
lib/main/ipcs/ipcNotification.ts
Normal file
16
lib/main/ipcs/ipcNotification.ts
Normal 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;
|
||||
});
|
||||
14
lib/main/ipcs/ipcUpdate.ts
Normal file
14
lib/main/ipcs/ipcUpdate.ts
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user