UNPKG

@jawirhytam/kurokuro

Version:

A DjawaScript Turtle Graphics library.

59 lines (48 loc) 1.71 kB
// main.js - Electron main process const { app, BrowserWindow } = require('electron'); const path = require('path'); function createWindow() { // Get the DjawaScript code content from environment variable const scriptContent = process.env.KUROKURO_SCRIPT_CONTENT; if (!scriptContent) { console.error('Error: KUROKURO_SCRIPT_CONTENT environment variable not set.'); app.quit(); return; } // Create the browser window. const mainWindow = new BrowserWindow({ width: 800, height: 750, webPreferences: { // No preload needed for this simpler model contextIsolation: true, nodeIntegration: false, } }); // and load the index.html of the app. mainWindow.loadFile('index.html'); // Open the DevTools. // mainWindow.webContents.openDevTools(); // Once the page is loaded, execute the user's script mainWindow.webContents.on('did-finish-load', () => { mainWindow.webContents.executeJavaScript(scriptContent) .then(result => { console.log("User script executed.", result); }) .catch(err => { console.error("Error executing user script:", err); }); }); } // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.whenReady().then(createWindow); // Quit when all windows are closed, except on macOS. app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit(); }); app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow(); });