mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 06:27:09 +01:00
Add preliminary prisma support
This commit is contained in:
parent
95c52d8a11
commit
06914b3af4
82
.eslintrc.json
Normal file
82
.eslintrc.json
Normal file
@ -0,0 +1,82 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"node_modules/*",
|
||||
"dist/*",
|
||||
"electron/preload/*",
|
||||
"vite.config.ts",
|
||||
"post-install.js"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:react/recommended",
|
||||
"plugin:react-hooks/recommended",
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:typescript-sort-keys/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"react",
|
||||
"@typescript-eslint",
|
||||
"import",
|
||||
"sort-keys-fix",
|
||||
"promise"
|
||||
],
|
||||
"rules": {
|
||||
"react-hooks/exhaustive-deps": [
|
||||
"warn",
|
||||
{ "enableDangerousAutofixThisMayCauseInfiniteLoops": true }
|
||||
],
|
||||
"react/jsx-sort-props": [
|
||||
"error",
|
||||
{
|
||||
"callbacksLast": true,
|
||||
"ignoreCase": false,
|
||||
"noSortAlphabetically": false,
|
||||
"reservedFirst": true,
|
||||
"shorthandFirst": true,
|
||||
"shorthandLast": false
|
||||
}
|
||||
],
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
"groups": ["builtin", "external", "internal", ["parent", "sibling"]],
|
||||
"pathGroups": [
|
||||
{
|
||||
"pattern": "react",
|
||||
"group": "external",
|
||||
"position": "before"
|
||||
}
|
||||
],
|
||||
"pathGroupsExcludedImportTypes": ["react"],
|
||||
"newlines-between": "never",
|
||||
"alphabetize": {
|
||||
"order": "asc",
|
||||
"caseInsensitive": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"sort-keys-fix/sort-keys-fix": "warn",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"consistent-return": "off",
|
||||
"object-curly-newline": "off",
|
||||
"indent": "off",
|
||||
"no-tabs": "off",
|
||||
"react/jsx-indent": "off",
|
||||
"react/jsx-indent-props": "off",
|
||||
"react/react-in-jsx-scope": "off"
|
||||
}
|
||||
}
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -21,9 +21,9 @@ dist-ssr
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
release
|
||||
release/app/dist
|
||||
release/build
|
||||
.vscode/.debug.env
|
||||
package-lock.json
|
||||
./package-lock.json
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
dist-electron
|
||||
|
12
.prettierrc
Normal file
12
.prettierrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"bracketSpacing": true,
|
||||
"jsxBracketSameLine": false,
|
||||
"arrowParens": "always",
|
||||
"proseWrap": "preserve"
|
||||
}
|
8
electron/electron-env.d.ts
vendored
8
electron/electron-env.d.ts
vendored
@ -2,10 +2,10 @@
|
||||
|
||||
declare namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
VSCODE_DEBUG?: 'true'
|
||||
DIST_ELECTRON: string
|
||||
DIST: string
|
||||
DIST: string;
|
||||
DIST_ELECTRON: string;
|
||||
/** /dist/ or /public/ */
|
||||
PUBLIC: string
|
||||
PUBLIC: string;
|
||||
VSCODE_DEBUG?: 'true';
|
||||
}
|
||||
}
|
||||
|
126
electron/main/features/core/api/index.ts
Normal file
126
electron/main/features/core/api/index.ts
Normal file
@ -0,0 +1,126 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { app, ipcMain } from 'electron';
|
||||
import isDev from 'electron-is-dev';
|
||||
import './server';
|
||||
|
||||
const dbPath = isDev
|
||||
? path.join(__dirname, '../../../../prisma/dev.db')
|
||||
: path.join(app.getPath('userData'), 'database.db');
|
||||
|
||||
if (!isDev) {
|
||||
try {
|
||||
// database file does not exist, need to create
|
||||
fs.copyFileSync(path.join(process.resourcesPath, 'prisma/dev.db'), dbPath, fs.constants.COPYFILE_EXCL);
|
||||
console.log(`DB does not exist. Create new DB from ${path.join(process.resourcesPath, 'prisma/dev.db')}`);
|
||||
} catch (err) {
|
||||
if (err && 'code' in (err as { code: string }) && (err as { code: string }).code !== 'EEXIST') {
|
||||
console.error(`DB creation faild. Reason:`, err);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPlatformName(): string {
|
||||
const isDarwin = process.platform === 'darwin';
|
||||
if (isDarwin && process.arch === 'arm64') {
|
||||
return `${process.platform}Arm64`;
|
||||
}
|
||||
|
||||
return process.platform;
|
||||
}
|
||||
|
||||
const platformToExecutables: Record<string, any> = {
|
||||
darwin: {
|
||||
migrationEngine: 'node_modules/@prisma/engines/migration-engine-darwin',
|
||||
queryEngine: 'node_modules/@prisma/engines/libquery_engine-darwin.dylib.node',
|
||||
},
|
||||
darwinArm64: {
|
||||
migrationEngine: 'node_modules/@prisma/engines/migration-engine-darwin-arm64',
|
||||
queryEngine: 'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
||||
},
|
||||
linux: {
|
||||
migrationEngine: 'node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x',
|
||||
queryEngine: 'node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node',
|
||||
},
|
||||
win32: {
|
||||
migrationEngine: 'node_modules/@prisma/engines/migration-engine-windows.exe',
|
||||
queryEngine: 'node_modules/@prisma/engines/query_engine-windows.dll.node',
|
||||
},
|
||||
};
|
||||
|
||||
const extraResourcesPath = app.getAppPath().replace('app.asar', ''); // impacted by extraResources setting in electron-builder.yml
|
||||
const platformName = getPlatformName();
|
||||
|
||||
const mePath = path.join(extraResourcesPath, platformToExecutables[platformName].migrationEngine);
|
||||
const qePath = path.join(extraResourcesPath, platformToExecutables[platformName].queryEngine);
|
||||
|
||||
ipcMain.on('config:get-app-path', (event) => {
|
||||
event.returnValue = app.getAppPath();
|
||||
});
|
||||
|
||||
ipcMain.on('config:get-platform-name', (event) => {
|
||||
const isDarwin = process.platform === 'darwin';
|
||||
event.returnValue =
|
||||
isDarwin && process.arch === 'arm64' ? `${process.platform}Arm64` : (event.returnValue = process.platform);
|
||||
});
|
||||
|
||||
ipcMain.on('config:get-prisma-db-path', (event) => {
|
||||
event.returnValue = dbPath;
|
||||
});
|
||||
|
||||
ipcMain.on('config:get-prisma-me-path', (event) => {
|
||||
event.returnValue = mePath;
|
||||
});
|
||||
|
||||
ipcMain.on('config:get-prisma-qe-path', (event) => {
|
||||
event.returnValue = qePath;
|
||||
});
|
||||
|
||||
export const prisma = new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: `file:${dbPath}`,
|
||||
},
|
||||
},
|
||||
errorFormat: 'minimal',
|
||||
// see https://github.com/prisma/prisma/discussions/5200
|
||||
// __internal: {
|
||||
// engine: {
|
||||
// binaryPath: qePath,
|
||||
// },
|
||||
// },
|
||||
});
|
||||
|
||||
prisma.server.findMany({
|
||||
where: {},
|
||||
});
|
||||
|
||||
export const exclude = <T, Key extends keyof T>(resultSet: T, ...keys: Key[]): Omit<T, Key> => {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key of keys) {
|
||||
delete resultSet[key];
|
||||
}
|
||||
return resultSet;
|
||||
};
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
prisma.$use(async (params, next) => {
|
||||
const maxRetries = 5;
|
||||
let retries = 0;
|
||||
|
||||
do {
|
||||
try {
|
||||
const result = await next(params);
|
||||
return result;
|
||||
} catch (err) {
|
||||
retries += 1;
|
||||
return sleep(500);
|
||||
}
|
||||
} while (retries < maxRetries);
|
||||
});
|
12
electron/main/features/core/api/server/index.ts
Normal file
12
electron/main/features/core/api/server/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import { prisma } from '..';
|
||||
|
||||
export enum ServerApi {
|
||||
GET_SERVER = 'api:server:get-server',
|
||||
GET_SERVERS = 'api:server:get-servers',
|
||||
}
|
||||
|
||||
ipcMain.handle(ServerApi.GET_SERVERS, async () => {
|
||||
const result = await prisma.server.findMany();
|
||||
return result;
|
||||
});
|
2
electron/main/features/core/index.ts
Normal file
2
electron/main/features/core/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
import './mpv-player';
|
||||
import './api';
|
134
electron/main/features/core/mpv-player/index.ts
Normal file
134
electron/main/features/core/mpv-player/index.ts
Normal file
@ -0,0 +1,134 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import MpvAPI from 'node-mpv';
|
||||
import { getWindow } from '../../..';
|
||||
|
||||
const mpv = new MpvAPI(
|
||||
{
|
||||
audio_only: true,
|
||||
auto_restart: true,
|
||||
binary: 'C:/ProgramData/chocolatey/lib/mpv.install/tools/mpv.exe',
|
||||
time_update: 1,
|
||||
},
|
||||
['--gapless-audio=yes', '--prefetch-playlist']
|
||||
);
|
||||
|
||||
mpv.start().catch((error: any) => {
|
||||
console.log('error', error);
|
||||
});
|
||||
|
||||
mpv.on('status', (status: any) => {
|
||||
if (status.property === 'playlist-pos') {
|
||||
if (status.value !== 0) {
|
||||
getWindow()?.webContents.send('renderer-player-auto-next');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Automatically updates the play button when the player is playing
|
||||
mpv.on('started', () => {
|
||||
getWindow()?.webContents.send('renderer-player-play');
|
||||
});
|
||||
|
||||
// Automatically updates the play button when the player is stopped
|
||||
mpv.on('stopped', () => {
|
||||
getWindow()?.webContents.send('renderer-player-stop');
|
||||
});
|
||||
|
||||
// Automatically updates the play button when the player is paused
|
||||
mpv.on('paused', () => {
|
||||
getWindow()?.webContents.send('renderer-player-pause');
|
||||
});
|
||||
|
||||
mpv.on('quit', () => {
|
||||
console.log('mpv quit');
|
||||
});
|
||||
|
||||
// Event output every interval set by time_update, used to update the current time
|
||||
mpv.on('timeposition', (time: number) => {
|
||||
getWindow()?.webContents.send('renderer-player-current-time', time);
|
||||
});
|
||||
|
||||
mpv.on('seek', () => {
|
||||
console.log('mpv seek');
|
||||
});
|
||||
|
||||
// Starts the player
|
||||
ipcMain.on('player-play', async () => {
|
||||
await mpv.play();
|
||||
});
|
||||
|
||||
// Pauses the player
|
||||
ipcMain.on('player-pause', async () => {
|
||||
await mpv.pause();
|
||||
});
|
||||
|
||||
// Stops the player
|
||||
ipcMain.on('player-stop', async () => {
|
||||
await mpv.stop();
|
||||
});
|
||||
|
||||
// Stops the player
|
||||
ipcMain.on('player-next', async () => {
|
||||
await mpv.next();
|
||||
});
|
||||
|
||||
// Stops the player
|
||||
ipcMain.on('player-previous', async () => {
|
||||
await mpv.prev();
|
||||
});
|
||||
|
||||
// Seeks forward or backward by the given amount of seconds
|
||||
ipcMain.on('player-seek', async (_event, time: number) => {
|
||||
await mpv.seek(time);
|
||||
});
|
||||
|
||||
// Seeks to the given time in seconds
|
||||
ipcMain.on('player-seek-to', async (_event, time: number) => {
|
||||
await mpv.goToPosition(time);
|
||||
});
|
||||
|
||||
// Sets the queue in position 0 and 1 to the given data. Used when manually starting a song or using the next/prev buttons
|
||||
ipcMain.on('player-set-queue', async (_event, data: any) => {
|
||||
if (data.queue.current) {
|
||||
await mpv.load(data.queue.current.streamUrl, 'replace');
|
||||
}
|
||||
|
||||
if (data.queue.next) {
|
||||
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||
}
|
||||
});
|
||||
|
||||
// Replaces the queue in position 1 to the given data
|
||||
ipcMain.on('player-set-queue-next', async (_event, data: any) => {
|
||||
const size = await mpv.getPlaylistSize();
|
||||
|
||||
if (size > 1) {
|
||||
await mpv.playlistRemove(1);
|
||||
}
|
||||
|
||||
if (data.queue.next) {
|
||||
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||
}
|
||||
});
|
||||
|
||||
// Sets the next song in the queue when reaching the end of the queue
|
||||
ipcMain.on('player-auto-next', async (_event, data: any) => {
|
||||
// Always keep the current song as position 0 in the mpv queue
|
||||
// This allows us to easily set update the next song in the queue without
|
||||
// disturbing the currently playing song
|
||||
await mpv.playlistRemove(0);
|
||||
|
||||
if (data.queue.next) {
|
||||
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||
}
|
||||
});
|
||||
|
||||
// Sets the volume to the given value (0-100)
|
||||
ipcMain.on('player-volume', async (_event, value: number) => {
|
||||
mpv.volume(value);
|
||||
});
|
||||
|
||||
// Toggles the mute status
|
||||
ipcMain.on('player-mute', async () => {
|
||||
mpv.mute();
|
||||
});
|
0
electron/main/features/darwin/index.ts
Normal file
0
electron/main/features/darwin/index.ts
Normal file
3
electron/main/features/index.ts
Normal file
3
electron/main/features/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import './core';
|
||||
|
||||
require(`./${process.platform}`);
|
0
electron/main/features/linux/index.ts
Normal file
0
electron/main/features/linux/index.ts
Normal file
0
electron/main/features/win32/index.ts
Normal file
0
electron/main/features/win32/index.ts
Normal file
@ -8,21 +8,20 @@
|
||||
// ├─┬ dist
|
||||
// │ └── index.html > Electron-Renderer
|
||||
//
|
||||
process.env.DIST_ELECTRON = join(__dirname, "..");
|
||||
process.env.DIST = join(process.env.DIST_ELECTRON, "../dist");
|
||||
process.env.PUBLIC = app.isPackaged
|
||||
? process.env.DIST
|
||||
: join(process.env.DIST_ELECTRON, "../public");
|
||||
process.env.DIST_ELECTRON = join(__dirname, '..');
|
||||
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist');
|
||||
process.env.PUBLIC = app.isPackaged ? process.env.DIST : join(process.env.DIST_ELECTRON, '../public');
|
||||
|
||||
import { app, BrowserWindow, shell, ipcMain } from "electron";
|
||||
import { release } from "os";
|
||||
import { join } from "path";
|
||||
import { release } from 'os';
|
||||
import { join } from 'path';
|
||||
import { app, BrowserWindow, shell, ipcMain } from 'electron';
|
||||
import './features';
|
||||
|
||||
// Disable GPU Acceleration for Windows 7
|
||||
if (release().startsWith("6.1")) app.disableHardwareAcceleration();
|
||||
if (release().startsWith('6.1')) app.disableHardwareAcceleration();
|
||||
|
||||
// Set application name for Windows 10+ notifications
|
||||
if (process.platform === "win32") app.setAppUserModelId(app.getName());
|
||||
if (process.platform === 'win32') app.setAppUserModelId(app.getName());
|
||||
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
app.quit();
|
||||
@ -31,18 +30,18 @@ if (!app.requestSingleInstanceLock()) {
|
||||
|
||||
let win: BrowserWindow | null = null;
|
||||
// Here, you can also use other preload
|
||||
const preload = join(__dirname, "../preload/index.js");
|
||||
const preload = join(__dirname, '../preload/index.js');
|
||||
const url = process.env.VITE_DEV_SERVER_URL;
|
||||
const indexHtml = join(process.env.DIST, "index.html");
|
||||
const indexHtml = join(process.env.DIST, 'index.html');
|
||||
|
||||
async function createWindow() {
|
||||
win = new BrowserWindow({
|
||||
title: "Main window",
|
||||
icon: join(process.env.PUBLIC, "favicon.svg"),
|
||||
icon: join(process.env.PUBLIC, 'favicon.svg'),
|
||||
title: 'Main window',
|
||||
webPreferences: {
|
||||
preload,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
preload,
|
||||
},
|
||||
});
|
||||
|
||||
@ -54,25 +53,25 @@ async function createWindow() {
|
||||
}
|
||||
|
||||
// Test actively push message to the Electron-Renderer
|
||||
win.webContents.on("did-finish-load", () => {
|
||||
win?.webContents.send("main-process-message", new Date().toLocaleString());
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
win?.webContents.send('main-process-message', new Date().toLocaleString());
|
||||
});
|
||||
|
||||
// Make all links open with the browser, not with the application
|
||||
win.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith("https:")) shell.openExternal(url);
|
||||
return { action: "deny" };
|
||||
if (url.startsWith('https:')) shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
});
|
||||
}
|
||||
|
||||
app.whenReady().then(createWindow);
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
app.on('window-all-closed', () => {
|
||||
win = null;
|
||||
if (process.platform !== "darwin") app.quit();
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
});
|
||||
|
||||
app.on("second-instance", () => {
|
||||
app.on('second-instance', () => {
|
||||
if (win) {
|
||||
// Focus on the main window if the user tried to open another
|
||||
if (win.isMinimized()) win.restore();
|
||||
@ -80,7 +79,7 @@ app.on("second-instance", () => {
|
||||
}
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
app.on('activate', () => {
|
||||
const allWindows = BrowserWindow.getAllWindows();
|
||||
if (allWindows.length) {
|
||||
allWindows[0].focus();
|
||||
@ -90,7 +89,7 @@ app.on("activate", () => {
|
||||
});
|
||||
|
||||
// new window example arg: new windows url
|
||||
ipcMain.handle("open-win", (event, arg) => {
|
||||
ipcMain.handle('open-win', (event, arg) => {
|
||||
const childWindow = new BrowserWindow({
|
||||
webPreferences: {
|
||||
preload,
|
||||
@ -104,3 +103,7 @@ ipcMain.handle("open-win", (event, arg) => {
|
||||
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
|
||||
}
|
||||
});
|
||||
|
||||
export const getWindow = () => {
|
||||
return win;
|
||||
};
|
||||
|
@ -1,31 +1,31 @@
|
||||
import { contextBridge } from "electron"
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
if (condition.includes(document.readyState)) {
|
||||
resolve(true)
|
||||
resolve(true);
|
||||
} else {
|
||||
document.addEventListener('readystatechange', () => {
|
||||
if (condition.includes(document.readyState)) {
|
||||
resolve(true)
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
const safeDOM = {
|
||||
append(parent: HTMLElement, child: HTMLElement) {
|
||||
if (!Array.from(parent.children).find(e => e === child)) {
|
||||
return parent.appendChild(child)
|
||||
if (!Array.from(parent.children).find((e) => e === child)) {
|
||||
return parent.appendChild(child);
|
||||
}
|
||||
},
|
||||
remove(parent: HTMLElement, child: HTMLElement) {
|
||||
if (Array.from(parent.children).find(e => e === child)) {
|
||||
return parent.removeChild(child)
|
||||
if (Array.from(parent.children).find((e) => e === child)) {
|
||||
return parent.removeChild(child);
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* https://tobiasahlin.com/spinkit
|
||||
@ -34,7 +34,7 @@ const safeDOM = {
|
||||
* https://matejkustec.github.io/SpinThatShit
|
||||
*/
|
||||
function useLoading() {
|
||||
const className = `loaders-css__square-spin`
|
||||
const className = `loaders-css__square-spin`;
|
||||
const styleContent = `
|
||||
@keyframes square-spin {
|
||||
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
|
||||
@ -61,39 +61,47 @@ function useLoading() {
|
||||
background: #282c34;
|
||||
z-index: 9;
|
||||
}
|
||||
`
|
||||
const oStyle = document.createElement('style')
|
||||
const oDiv = document.createElement('div')
|
||||
`;
|
||||
const oStyle = document.createElement('style');
|
||||
const oDiv = document.createElement('div');
|
||||
|
||||
oStyle.id = 'app-loading-style'
|
||||
oStyle.innerHTML = styleContent
|
||||
oDiv.className = 'app-loading-wrap'
|
||||
oDiv.innerHTML = `<div class="${className}"><div></div></div>`
|
||||
oStyle.id = 'app-loading-style';
|
||||
oStyle.innerHTML = styleContent;
|
||||
oDiv.className = 'app-loading-wrap';
|
||||
oDiv.innerHTML = `<div class="${className}"><div></div></div>`;
|
||||
|
||||
return {
|
||||
appendLoading() {
|
||||
safeDOM.append(document.head, oStyle)
|
||||
safeDOM.append(document.body, oDiv)
|
||||
safeDOM.append(document.head, oStyle);
|
||||
safeDOM.append(document.body, oDiv);
|
||||
},
|
||||
removeLoading() {
|
||||
safeDOM.remove(document.head, oStyle)
|
||||
safeDOM.remove(document.body, oDiv)
|
||||
safeDOM.remove(document.head, oStyle);
|
||||
safeDOM.remove(document.body, oDiv);
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
const { appendLoading, removeLoading } = useLoading()
|
||||
domReady().then(appendLoading)
|
||||
const { appendLoading, removeLoading } = useLoading();
|
||||
domReady().then(appendLoading);
|
||||
|
||||
window.onmessage = ev => {
|
||||
ev.data.payload === 'removeLoading' && removeLoading()
|
||||
}
|
||||
window.onmessage = (ev) => {
|
||||
ev.data.payload === 'removeLoading' && removeLoading();
|
||||
};
|
||||
|
||||
setTimeout(removeLoading, 4999)
|
||||
setTimeout(removeLoading, 4999);
|
||||
|
||||
const serverApi = {
|
||||
getServer: () => ipcRenderer.invoke('api:server:get-server'), // ServerApi.GET_SERVER
|
||||
getServers: () => ipcRenderer.invoke('api:server:get-servers'), // ServerApi.GET_SERVERS
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld('electron', {
|
||||
doThing: () => console.log('hello'),
|
||||
});
|
||||
const api = {
|
||||
prisma: {
|
||||
server: serverApi,
|
||||
},
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld('electron', api);
|
||||
|
18234
package-lock.json
generated
Normal file
18234
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,12 +6,13 @@
|
||||
"description": "",
|
||||
"author": "jeffvli",
|
||||
"license": "GPL-3.0",
|
||||
"main": "dist-electron/main/index.js",
|
||||
"main": "release/app/dist/main/index.js",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build && electron-builder",
|
||||
"postinstall": "node post-install.js && electron-builder install-app-deps",
|
||||
"prisma:init": "npx prisma migrate dev",
|
||||
"prisma:dev": "npx prisma db push",
|
||||
"prisma:migrate": ""
|
||||
},
|
||||
"engines": {
|
||||
|
272
prisma/schema.prisma
Normal file
272
prisma/schema.prisma
Normal file
@ -0,0 +1,272 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
engineType = "library"
|
||||
binaryTargets = ["native", "windows"]
|
||||
// output = "../release/app/node_modules/.prisma/client"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = "file:../release/app/prisma/dev.db"
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
favorites Favorite[]
|
||||
albumArtistRatings AlbumArtistRating[]
|
||||
artistRatings ArtistRating[]
|
||||
albumRatings AlbumRating[]
|
||||
songRatings SongRating[]
|
||||
}
|
||||
|
||||
model Server {
|
||||
id Int @id @default(autoincrement())
|
||||
nickname String @unique
|
||||
url String @unique
|
||||
remoteId String @map("remote_id")
|
||||
authUsername String @map("auth_username")
|
||||
authCredential String @map("auth_credential")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
serverType ServerType @relation(fields: [serverTypeId], references: [id])
|
||||
serverTypeId Int
|
||||
|
||||
serverFolders ServerFolder[]
|
||||
songs Song[]
|
||||
albums Album[]
|
||||
artists Artist[]
|
||||
albumArtists AlbumArtist[]
|
||||
|
||||
// @@map("server")
|
||||
}
|
||||
|
||||
model ServerType {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
Server Server[]
|
||||
|
||||
// @@map("server_type")
|
||||
}
|
||||
|
||||
model ServerFolder {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
remoteId String @map("remote_id")
|
||||
enabled Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
server Server @relation(fields: [serverId], references: [id])
|
||||
serverId Int
|
||||
|
||||
// @@map("server_folder")
|
||||
}
|
||||
|
||||
model Genre {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
artists Artist[]
|
||||
albumArtists AlbumArtist[]
|
||||
albums Album[]
|
||||
songs Song[]
|
||||
|
||||
// @@map("genre")
|
||||
}
|
||||
|
||||
model Favorite {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
albumArtists AlbumArtist[]
|
||||
artists Artist[]
|
||||
albums Album[]
|
||||
songs Song[]
|
||||
|
||||
User User? @relation(fields: [userId], references: [id])
|
||||
userId Int?
|
||||
|
||||
// @@map("favorite")
|
||||
}
|
||||
|
||||
model AlbumArtistRating {
|
||||
id Int @id @default(autoincrement())
|
||||
value Float
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId Int
|
||||
|
||||
albumArtist AlbumArtist? @relation(fields: [albumArtistId], references: [id])
|
||||
albumArtistId Int
|
||||
// @@map("album_artist_rating")
|
||||
|
||||
@@unique(fields: [albumArtistId, userId], name: "uniqueAlbumArtistRating", map: "unique_album_artist_rating")
|
||||
}
|
||||
|
||||
model ArtistRating {
|
||||
id Int @id @default(autoincrement())
|
||||
value Float
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId Int
|
||||
|
||||
artist Artist? @relation(fields: [artistId], references: [id])
|
||||
artistId Int
|
||||
// @@map("artist_rating")
|
||||
|
||||
@@unique(fields: [artistId, userId], name: "uniqueArtistRating", map: "unique_artist_rating")
|
||||
}
|
||||
|
||||
model AlbumRating {
|
||||
id Int @id @default(autoincrement())
|
||||
value Float
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId Int
|
||||
|
||||
album Album? @relation(fields: [albumId], references: [id])
|
||||
albumId Int
|
||||
// @@map("album_rating")
|
||||
|
||||
@@unique(fields: [albumId, userId], name: "uniqueAlbumRating", map: "unique_album_rating")
|
||||
}
|
||||
|
||||
model SongRating {
|
||||
id Int @id @default(autoincrement())
|
||||
value Float
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId Int
|
||||
|
||||
song Song? @relation(fields: [songId], references: [id])
|
||||
songId Int
|
||||
// @@map("song_rating")
|
||||
|
||||
@@unique(fields: [songId, userId], name: "uniqueSongRating", map: "unique_song_rating")
|
||||
}
|
||||
|
||||
model AlbumArtist {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
image String?
|
||||
image_remote String? @map("image_remote")
|
||||
sortName String @map("sort_name")
|
||||
biography String?
|
||||
remoteId String @map("remote_id")
|
||||
remoteCreatedAt DateTime? @map("remote_created_at")
|
||||
deleted Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
genres Genre[]
|
||||
albums Album[]
|
||||
songs Song[]
|
||||
favorites Favorite[]
|
||||
ratings AlbumArtistRating[]
|
||||
|
||||
server Server @relation(fields: [serverId], references: [id])
|
||||
serverId Int
|
||||
// @@map("album_artist")
|
||||
|
||||
@@unique(fields: [serverId, remoteId], name: "uniqueAlbumArtistId", map: "unique_album_artist_id")
|
||||
}
|
||||
|
||||
model Artist {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
image String?
|
||||
image_remote String? @map("image_remote")
|
||||
biography String?
|
||||
remoteId String @map("remote_id")
|
||||
remoteCreatedAt DateTime? @map("remote_created_at")
|
||||
deleted Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
genres Genre[]
|
||||
favorites Favorite[]
|
||||
ratings ArtistRating[]
|
||||
|
||||
server Server @relation(fields: [serverId], references: [id])
|
||||
serverId Int
|
||||
// @@map("artist")
|
||||
|
||||
@@unique(fields: [serverId, remoteId], name: "uniqueArtistId", map: "unique_artist_id")
|
||||
}
|
||||
|
||||
model Album {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
image String?
|
||||
image_remote String? @map("image_remote")
|
||||
releaseDate DateTime? @map("release_date")
|
||||
releaseYear Int? @map("release_year")
|
||||
remoteId String
|
||||
remoteCreatedAt DateTime?
|
||||
deleted Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
genres Genre[]
|
||||
albumArtists AlbumArtist[]
|
||||
favorites Favorite[]
|
||||
ratings AlbumRating[]
|
||||
|
||||
server Server @relation(fields: [serverId], references: [id])
|
||||
serverId Int @map("server_id")
|
||||
// @@map("album")
|
||||
|
||||
@@unique(fields: [serverId, remoteId], name: "uniqueAlbumId", map: "unique_album_id")
|
||||
}
|
||||
|
||||
model Song {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
image String?
|
||||
remote_image String? @map("remote_image")
|
||||
releaseDate DateTime? @map("release_date")
|
||||
releaseYear Int? @map("release_year")
|
||||
duration Float?
|
||||
lyric String?
|
||||
bitRate Int @map("bit_rate")
|
||||
container String
|
||||
size String?
|
||||
channels Int?
|
||||
discIndex Int @default(1) @map("disc_index")
|
||||
trackIndex Int? @map("track_index")
|
||||
artistName String? @map("artist_name")
|
||||
remoteId String @map("remote_id")
|
||||
remoteCreatedAt DateTime? @map("remote_created_at")
|
||||
deleted Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
genres Genre[]
|
||||
albumArtists AlbumArtist[]
|
||||
favorites Favorite[]
|
||||
ratings SongRating[]
|
||||
|
||||
server Server @relation(fields: [serverId], references: [id])
|
||||
serverId Int @map("server_id")
|
||||
// @@map("song")
|
||||
|
||||
@@unique(fields: [serverId, remoteId], name: "uniqueSongId", map: "unique_song_id")
|
||||
}
|
98
release/app/package-lock.json
generated
Normal file
98
release/app/package-lock.json
generated
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"name": "electron-react-boilerplate",
|
||||
"version": "4.5.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "electron-react-boilerplate",
|
||||
"version": "4.5.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@prisma/client": "4.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prisma": "4.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/client": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.4.0.tgz",
|
||||
"integrity": "sha512-ciKOP246x1xwr04G9ajHlJ4pkmtu9Q6esVyqVBO0QJihaKQIUvbPjClp17IsRJyxqNpFm4ScbOc/s9DUzKHINQ==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/engines-version": "4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"prisma": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"prisma": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/engines": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.4.0.tgz",
|
||||
"integrity": "sha512-Fpykccxlt9MHrAs/QpPGpI2nOiRxuLA+LiApgA59ibbf24YICZIMWd3SI2YD+q0IAIso0jCGiHhirAIbxK3RyQ==",
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true
|
||||
},
|
||||
"node_modules/@prisma/engines-version": {
|
||||
"version": "4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6.tgz",
|
||||
"integrity": "sha512-P5v/PuEIJLYXZUZBvOLPqoyCW+m6StNqHdiR6te++gYVODpPdLakks5HVx3JaZIY+LwR02juJWFlwpc9Eog/ug=="
|
||||
},
|
||||
"node_modules/prisma": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-4.4.0.tgz",
|
||||
"integrity": "sha512-l/QKLmLcKJQFuc+X02LyICo0NWTUVaNNZ00jKJBqwDyhwMAhboD1FWwYV50rkH4Wls0RviAJSFzkC2ZrfawpfA==",
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/engines": "4.4.0"
|
||||
},
|
||||
"bin": {
|
||||
"prisma": "build/index.js",
|
||||
"prisma2": "build/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.4.0.tgz",
|
||||
"integrity": "sha512-ciKOP246x1xwr04G9ajHlJ4pkmtu9Q6esVyqVBO0QJihaKQIUvbPjClp17IsRJyxqNpFm4ScbOc/s9DUzKHINQ==",
|
||||
"requires": {
|
||||
"@prisma/engines-version": "4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6"
|
||||
}
|
||||
},
|
||||
"@prisma/engines": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.4.0.tgz",
|
||||
"integrity": "sha512-Fpykccxlt9MHrAs/QpPGpI2nOiRxuLA+LiApgA59ibbf24YICZIMWd3SI2YD+q0IAIso0jCGiHhirAIbxK3RyQ==",
|
||||
"devOptional": true
|
||||
},
|
||||
"@prisma/engines-version": {
|
||||
"version": "4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6.tgz",
|
||||
"integrity": "sha512-P5v/PuEIJLYXZUZBvOLPqoyCW+m6StNqHdiR6te++gYVODpPdLakks5HVx3JaZIY+LwR02juJWFlwpc9Eog/ug=="
|
||||
},
|
||||
"prisma": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-4.4.0.tgz",
|
||||
"integrity": "sha512-l/QKLmLcKJQFuc+X02LyICo0NWTUVaNNZ00jKJBqwDyhwMAhboD1FWwYV50rkH4Wls0RviAJSFzkC2ZrfawpfA==",
|
||||
"devOptional": true,
|
||||
"requires": {
|
||||
"@prisma/engines": "4.4.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
release/app/package.json
Normal file
19
release/app/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "electron-react-boilerplate",
|
||||
"version": "4.5.0",
|
||||
"description": "A foundation for scalable desktop apps",
|
||||
"main": "./dist/main/main.js",
|
||||
"author": {
|
||||
"name": "Electron React Boilerplate Maintainers",
|
||||
"email": "electronreactboilerplate@gmail.com",
|
||||
"url": "https://github.com/electron-react-boilerplate"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {
|
||||
"@prisma/client": "4.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prisma": "4.4.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
BIN
release/app/prisma/dev.db
Normal file
BIN
release/app/prisma/dev.db
Normal file
Binary file not shown.
15
src/global.d.ts
vendored
Normal file
15
src/global.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
type ApiSurface = {
|
||||
prisma: {
|
||||
server: {
|
||||
getServer: () => Promise<Prisma.ServerSelect>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electron: ApiSurface;
|
||||
}
|
||||
}
|
2
src/os-api.ts
Normal file
2
src/os-api.ts
Normal file
@ -0,0 +1,2 @@
|
||||
const OSApi = window.electron;
|
||||
export default OSApi;
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"baseUrl": ".",
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"paths": {
|
||||
"@/*": ["src/*"],
|
||||
"paths": {
|
||||
"@/*": ["src/*"],
|
||||
"styles/*": ["src/assets/styles/*"]
|
||||
},
|
||||
},
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": false,
|
||||
@ -21,7 +21,6 @@
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src"],
|
||||
"include": ["src", "global.d.ts"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
|
||||
|
@ -1,51 +1,51 @@
|
||||
import { rmSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import electron from 'vite-electron-plugin'
|
||||
import { customStart } from 'vite-electron-plugin/plugin'
|
||||
import pkg from './package.json'
|
||||
import { rmSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import electron from 'vite-electron-plugin';
|
||||
import { customStart } from 'vite-electron-plugin/plugin';
|
||||
import pkg from './package.json';
|
||||
|
||||
rmSync(path.join(__dirname, 'dist-electron'), { recursive: true, force: true })
|
||||
rmSync(path.join(__dirname, 'dist-electron'), { recursive: true, force: true });
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.join(__dirname, 'src'),
|
||||
'styles': path.join(__dirname, 'src/assets/styles'),
|
||||
styles: path.join(__dirname, 'src/assets/styles'),
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
electron({
|
||||
include: [
|
||||
'electron',
|
||||
'preload',
|
||||
],
|
||||
outDir: path.join(__dirname, 'release/app/dist'),
|
||||
include: ['electron', 'preload', 'types'],
|
||||
transformOptions: {
|
||||
sourcemap: !!process.env.VSCODE_DEBUG,
|
||||
},
|
||||
// Will start Electron via VSCode Debug
|
||||
plugins: process.env.VSCODE_DEBUG
|
||||
? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')))]
|
||||
? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */ '[startup] Electron App')))]
|
||||
: undefined,
|
||||
}),
|
||||
],
|
||||
server: process.env.VSCODE_DEBUG ? (() => {
|
||||
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
||||
return {
|
||||
host: url.hostname,
|
||||
port: +url.port,
|
||||
}
|
||||
})() : undefined,
|
||||
server: process.env.VSCODE_DEBUG
|
||||
? (() => {
|
||||
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL);
|
||||
return {
|
||||
host: url.hostname,
|
||||
port: +url.port,
|
||||
};
|
||||
})()
|
||||
: undefined,
|
||||
clearScreen: false,
|
||||
})
|
||||
});
|
||||
|
||||
function debounce<Fn extends (...args: any[]) => void>(fn: Fn, delay = 299) {
|
||||
let t: NodeJS.Timeout
|
||||
let t: NodeJS.Timeout;
|
||||
return ((...args) => {
|
||||
clearTimeout(t)
|
||||
t = setTimeout(() => fn(...args), delay)
|
||||
}) as Fn
|
||||
clearTimeout(t);
|
||||
t = setTimeout(() => fn(...args), delay);
|
||||
}) as Fn;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user