Prepping editor.

This commit is contained in:
2023-06-25 20:58:47 -07:00
parent 17ec6aad52
commit bf93740c20
28 changed files with 367 additions and 13 deletions

View File

@ -0,0 +1,11 @@
import vnscene from './vnscene';
export const API_HANDLERS:{
[key:string]:(...args:any)=>any
} = {};
const addHandlers = (handlers:{[key:string]:(...args:any)=>any}) => {
Object.keys(handlers).forEach(key => API_HANDLERS[key] = handlers[key]);
}
addHandlers(vnscene);

View File

@ -0,0 +1,6 @@
export default {
"vnscene:test": (bruh1:string, bruh2:string) => {
console.log("vnscene:test", bruh1, bruh2);
return 'test?';
}
};

64
editor/electron/main.ts Normal file
View File

@ -0,0 +1,64 @@
import { app, BrowserWindow, ipcMain } from 'electron';
import * as path from 'path';
import installExtension, { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer";
import { API_HANDLERS } from './api/handlers';
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
// contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
}
})
if (app.isPackaged) {
// 'build/index.html'
win.loadURL(`file://${__dirname}/../index.html`);
} else {
win.loadURL('http://localhost:3000/index.html');
win.webContents.openDevTools();
// Hot Reloading on 'node_modules/.bin/electronPath'
require('electron-reload')(__dirname, {
electron: path.join(__dirname,
'..',
'..',
'node_modules',
'.bin',
'electron' + (process.platform === "win32" ? ".cmd" : "")),
forceHardReset: true,
hardResetMethod: 'exit'
});
}
}
app.whenReady().then(() => {
// DevTools
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
// Add API Handlers
Object.entries(API_HANDLERS).forEach(entry => {
ipcMain.handle(entry[0], (event:any, ...args:any) => {
return entry[1](...args);
});
})
});

View File

@ -0,0 +1,13 @@
import { contextBridge, ipcRenderer } from 'electron';
const API_HANDLERS = [
"vnscene:test"
];
contextBridge.exposeInMainWorld(
'dawnapi',
API_HANDLERS.reduce((acc, key) => {
acc[key] = (...args:any) => ipcRenderer.invoke(key, ...args);
return acc;
}, {} as {[key:string]:()=>any})
);

View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"strict": true,
"outDir": "../build",
"rootDir": "../",
"noEmitOnError": true,
"typeRoots": [
"node_modules/@types"
]
}
}