feat: add Gelectron compatibility layer for Electron modules

- Introduced contextBridge module for exposing APIs to the main world.
- Added dialog module for handling open, save, and message dialogs.
- Created index module as a drop-in replacement for Electron's main API.
- Implemented ipcMain and ipcRenderer modules for inter-process communication.
- Developed menu and menu item modules for creating application menus.
- Added nativeImage module for handling images in various formats.
- Implemented notification module for displaying system notifications.
- Created preload-loader for injecting preload scripts into the renderer process.
- Developed runtime module for running Electron apps in a Node.js environment.
- Added safe-storage module for basic string encryption and decryption.
- Implemented shell module for opening external URLs and managing file paths.
- Created tray module for managing system tray icons and menus.
- Developed webContents utilities for interacting with browser windows.
This commit is contained in:
miles committed 2026-07-26 17:12:47 -05:00
1 parent 4af8378d72
commit 86c19b0012
39 files changed
+4687 -2

No files matched your search

+117
View File
@@ -0,0 +1,117 @@
'use strict';
/**
* Gelectron - nativeImage module (Electron compatible)
*/
class NativeImage {
constructor() {
this._isEmpty = true;
this._width = 0;
this._height = 0;
this._data = null;
}
static createFromPath(path) {
const img = new NativeImage();
try {
const fs = require('fs');
const data = fs.readFileSync(path);
// Basic PNG header parsing for dimensions
if (data.length > 24 && data[0] === 0x89 && data[1] === 0x50) {
img._width = data.readUInt32BE(16);
img._height = data.readUInt32BE(20);
img._data = data;
img._isEmpty = false;
}
} catch (err) {
console.error(`[gelectron] Failed to load image: ${path}`, err.message);
}
return img;
}
static createFromBuffer(buffer, options = {}) {
const img = new NativeImage();
if (buffer && buffer.length > 0) {
img._data = buffer;
img._isEmpty = false;
img._width = options.width || 0;
img._height = options.height || 0;
// Try to detect PNG dimensions
if (buffer.length > 24 && buffer[0] === 0x89 && buffer[1] === 0x50) {
img._width = buffer.readUInt32BE(16);
img._height = buffer.readUInt32BE(20);
}
}
return img;
}
static createFromDataURL(dataURL) {
const matches = dataURL.match(/^data:[^;]+;base64,(.+)$/);
if (matches) {
return NativeImage.createFromBuffer(Buffer.from(matches[1], 'base64'));
}
return NativeImage.createEmpty();
}
static createEmpty() {
return new NativeImage();
}
toPNG(options = {}) {
return this._data || Buffer.alloc(0);
}
toJPEG(quality) {
return this._data || Buffer.alloc(0);
}
toBitmap(options = {}) {
return this._data || Buffer.alloc(0);
}
toDataURL() {
if (!this._data) return 'data:,';
const base64 = this._data.toString('base64');
return `data:image/png;base64,${base64}`;
}
resize(options) {
const resized = new NativeImage();
resized._width = options.width || this._width;
resized._height = options.height || this._height;
resized._data = this._data;
resized._isEmpty = this._isEmpty;
return resized;
}
crop(rect) {
return this.resize({ width: rect.width, height: rect.height });
}
getBitmap(options = {}) {
return this._data || Buffer.alloc(0);
}
getSize() {
return { width: this._width, height: this._height };
}
isEmpty() {
return this._isEmpty;
}
setTemplateImage(template) {
this._isTemplate = template;
}
isTemplateImage() {
return this._isTemplate || false;
}
toPNG(options) { return this.toPNG(options); }
toJPEG(quality) { return this.toJPEG(quality); }
}
module.exports = NativeImage;