mirror of
https://github.com/ivabus/gui
synced 2025-04-23 22:17:18 +03:00
main example of really bad wiring strategy
This commit is contained in:
parent
fb9e2a0121
commit
f897640683
3 changed files with 39 additions and 7 deletions
|
@ -3,6 +3,7 @@ const { app, BrowserWindow, ipcMain } = require('electron');
|
|||
const contextMenu = require('electron-context-menu');
|
||||
const serve = require('electron-serve');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
try {
|
||||
require('electron-reloader')(module);
|
||||
|
@ -32,11 +33,12 @@ function createWindow() {
|
|||
minWidth: 500,
|
||||
webPreferences: {
|
||||
enableRemoteModule: true,
|
||||
contextIsolation: true,
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true,
|
||||
spellcheck: false,
|
||||
devTools: dev,
|
||||
preload: path.join(app.getAppPath(), 'preload.cjs')
|
||||
webSecurity: false,
|
||||
devTools: dev
|
||||
// preload: path.join(app.getAppPath(), 'preload.cjs')
|
||||
},
|
||||
x: windowState.x,
|
||||
y: windowState.y,
|
||||
|
@ -101,3 +103,27 @@ app.on('window-all-closed', () => {
|
|||
ipcMain.on('to-main', (event, count) => {
|
||||
return mainWindow.webContents.send('from-main', `next count is ${count + 1}`);
|
||||
});
|
||||
|
||||
ipcMain.handle('get-installed-packages', async () => {
|
||||
const homePath = app.getPath('home');
|
||||
const teaPath = path.join(homePath, '.tea');
|
||||
const folders = await deepReadDir(teaPath);
|
||||
return folders;
|
||||
});
|
||||
|
||||
const deepReadDir = async (dirPath) => {
|
||||
let arrayOfFiles;
|
||||
try {
|
||||
arrayOfFiles = fs.readdirSync(dirPath)
|
||||
console.log(arrayOfFiles)
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
}
|
||||
// await Promise.all(
|
||||
// (await readdir(dirPath, {withFileTypes: true})).map(async (dirent) => {
|
||||
// const path = join(dirPath, dirent.name)
|
||||
// return dirent.isDirectory() ? await deepReadDir(path) : path
|
||||
// }),
|
||||
// )
|
||||
return arrayOfFiles;
|
||||
}
|
|
@ -10,6 +10,7 @@ import type { GUIPackage, Course, Category } from '../types';
|
|||
import { PackageStates } from '../types';
|
||||
import { loremIpsum } from 'lorem-ipsum';
|
||||
import _ from 'lodash';
|
||||
import { getInstalledPackages } from '$libs/teaDir';
|
||||
|
||||
const packages: Package[] = [
|
||||
{
|
||||
|
@ -155,7 +156,7 @@ const packages: Package[] = [
|
|||
];
|
||||
|
||||
export async function getPackages(): Promise<GUIPackage[]> {
|
||||
await delay(2000);
|
||||
await getInstalledPackages();
|
||||
return packages.map((pkg) => {
|
||||
return {
|
||||
...pkg,
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
import { app } from 'electron';
|
||||
import fs from 'fs';
|
||||
import { join } from 'upath';
|
||||
// import { app } from 'electron';
|
||||
// import fs from 'fs';
|
||||
// import { join } from 'upath';
|
||||
|
||||
type Dir = {
|
||||
name: string;
|
||||
path: string;
|
||||
children?: Dir[];
|
||||
};
|
||||
|
||||
const { ipcRenderer } = window.require('electron');
|
||||
export async function getInstalledPackages() {
|
||||
console.log('get installed pkgs');
|
||||
const pkgs = await ipcRenderer.invoke('get-installed-packages');
|
||||
console.log(pkgs);
|
||||
// const homePath = app.getPath('home');
|
||||
// const packageFolders = (await readDir('.tea/', {
|
||||
// dir: BaseDirectory.Home,
|
||||
|
|
Loading…
Reference in a new issue