mirror of
https://github.com/mileswolfallen2/gelectron.git
synced 2026-12-03 23:53:26 +00:00
Add initial implementation of GeelectronDemo app
- Created main.js for the application logic, including tests for Electron app properties and methods. - Added package.json to define app metadata. - Included necessary code signature files for macOS app distribution. - Implemented basic window management and event handling in the app.
This commit is contained in:
1 parent
6392c2231c
commit
e5d93b3613
40 files changed
+6440
-123
No files matched your search
+238
-112
@@ -2,6 +2,12 @@
|
||||
|
||||
/**
|
||||
* Gelectron - app module (Electron compatible)
|
||||
*
|
||||
* Full implementation matching the Electron app API surface.
|
||||
* Events: ready, second-instance, activate, window-all-closed, before-quit,
|
||||
* will-quit, quit, focus, blur, browser-window-focus, browser-window-blur,
|
||||
* web-contents-created, render-process-gone, child-process-gone,
|
||||
* keyboard-visibility-changed, new-window-for-tab
|
||||
*/
|
||||
|
||||
const { EventEmitter } = require('events');
|
||||
@@ -11,25 +17,35 @@ class App extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this._ready = false;
|
||||
this._windowCount = 0;
|
||||
this._relaunchOptions = null;
|
||||
this._relaunching = false;
|
||||
this._aboutPanelOptions = {};
|
||||
this._badgeCount = 0;
|
||||
this._secureKeyboardEntryEnabled = false;
|
||||
this._userAgent = null;
|
||||
this._name = 'Gelectron App';
|
||||
this._names = null;
|
||||
|
||||
const os = require('os');
|
||||
const home = os.homedir();
|
||||
this._paths = {
|
||||
home: require('os').homedir(),
|
||||
appData: path.join(require('os').homedir(), '.config', 'gelectron'),
|
||||
userData: path.join(require('os').homedir(), '.config', 'gelectron'),
|
||||
desktop: path.join(require('os').homedir(), 'Desktop'),
|
||||
documents: path.join(require('os').homedir(), 'Documents'),
|
||||
downloads: path.join(require('os').homedir(), 'Downloads'),
|
||||
temp: require('os').tmpdir(),
|
||||
home,
|
||||
appData: path.join(home, process.platform === 'win32' ? '' : '.', process.platform === 'darwin' ? 'Library/Application Support' : 'config', 'gelectron'),
|
||||
userData: path.join(home, process.platform === 'win32' ? '' : '.', process.platform === 'darwin' ? 'Library/Application Support' : 'config', 'gelectron'),
|
||||
desktop: path.join(home, 'Desktop'),
|
||||
documents: path.join(home, 'Documents'),
|
||||
downloads: path.join(home, 'Downloads'),
|
||||
temp: os.tmpdir(),
|
||||
exe: process.execPath,
|
||||
module: __dirname,
|
||||
crashDumps: path.join(require('os').homedir(), '.config', 'gelectron', 'crashDumps'),
|
||||
logs: path.join(require('os').homedir(), '.config', 'gelectron', 'logs'),
|
||||
crashDumps: path.join(home, process.platform === 'win32' ? '' : '.', process.platform === 'darwin' ? 'Library/Application Support' : 'config', 'gelectron', 'crashDumps'),
|
||||
logs: path.join(home, process.platform === 'win32' ? '' : '.', process.platform === 'darwin' ? 'Library/Application Support' : 'config', 'gelectron', 'logs'),
|
||||
};
|
||||
|
||||
this._commandLine = new Map();
|
||||
this._dock = process.platform === 'darwin' ? {
|
||||
setIcon: (icon) => {
|
||||
console.log('[gelectron] dock.setIcon called');
|
||||
},
|
||||
setIcon: (icon) => {},
|
||||
bounce: () => 0,
|
||||
cancelBounce: () => {},
|
||||
setBadge: () => {},
|
||||
@@ -38,18 +54,16 @@ class App extends EventEmitter {
|
||||
show: () => {},
|
||||
isVisible: () => true,
|
||||
setMenu: () => {},
|
||||
setBadgeCount: () => {},
|
||||
setBadgeCount: (count) => { return 0; },
|
||||
getBadgeCount: () => 0,
|
||||
setThumbnail: () => {},
|
||||
setThumbnailClip: () => {},
|
||||
setThumbnailToolTip: () => {},
|
||||
setMenu: () => {},
|
||||
} : null;
|
||||
|
||||
this._argv = process.argv.slice();
|
||||
|
||||
// Emit 'ready' automatically on the next tick, matching real Electron
|
||||
// where the app becomes ready once the process has initialised.
|
||||
process.nextTick(() => {
|
||||
if (!this._ready) {
|
||||
this._ready = true;
|
||||
@@ -58,167 +72,279 @@ class App extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Properties ──────────────────────────────────────────────
|
||||
|
||||
get commandLine() {
|
||||
const self = this;
|
||||
return {
|
||||
appendSwitch: (name, value) => {
|
||||
this._commandLine.set(name, value || '');
|
||||
},
|
||||
removeSwitch: (name) => {
|
||||
this._commandLine.delete(name);
|
||||
},
|
||||
getSwitch: (name) => {
|
||||
return this._commandLine.get(name) || '';
|
||||
},
|
||||
hasSwitch: (name) => {
|
||||
return this._commandLine.has(name);
|
||||
},
|
||||
appendSwitch: (name, value) => { self._commandLine.set(name, value || ''); },
|
||||
removeSwitch: (name) => { self._commandLine.delete(name); },
|
||||
getSwitch: (name) => { return self._commandLine.get(name) || ''; },
|
||||
hasSwitch: (name) => { return self._commandLine.has(name); },
|
||||
};
|
||||
}
|
||||
|
||||
get dock() {
|
||||
return this._dock;
|
||||
}
|
||||
|
||||
get argv() {
|
||||
return this._argv;
|
||||
}
|
||||
get dock() { return this._dock; }
|
||||
get argv() { return this._argv; }
|
||||
|
||||
get isPackaged() {
|
||||
return !process.argv[0].includes('node') && !process.argv[0].includes('gelectron');
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'Gelectron App';
|
||||
}
|
||||
get name() { return this._name; }
|
||||
set name(val) { this._name = val || 'Gelectron App'; }
|
||||
|
||||
set name(val) {
|
||||
// no-op
|
||||
}
|
||||
get version() { return process.env.GELECTRON_VERSION || '0.1.0'; }
|
||||
|
||||
get version() {
|
||||
return process.env.GELECTRON_VERSION || '0.1.0';
|
||||
}
|
||||
get locale() { return this.getLocale(); }
|
||||
get userAgent() { return this.getUserAgent(); }
|
||||
|
||||
getAppPath() {
|
||||
return process.env.GELECTRON_APP_PATH || process.cwd();
|
||||
}
|
||||
get isReady() { return this._ready; }
|
||||
|
||||
relaunch(options = {}) {
|
||||
process.exit(0);
|
||||
}
|
||||
get appPath() { return this.getAppPath(); }
|
||||
|
||||
// ─── Core Methods ────────────────────────────────────────────
|
||||
|
||||
getAppPath() { return process.env.GELECTRON_APP_PATH || process.cwd(); }
|
||||
|
||||
getPath(name) {
|
||||
if (name === 'app' || name === 'appData' || name === 'userData') {
|
||||
return this._paths[name === 'app' ? 'appData' : name] || this._paths.userData;
|
||||
}
|
||||
return this._paths[name] || this._paths.userData;
|
||||
}
|
||||
|
||||
setPath(name, path) {
|
||||
this._paths[name] = path;
|
||||
}
|
||||
setPath(name, value) { this._paths[name] = value; }
|
||||
|
||||
getName() {
|
||||
return this.name;
|
||||
}
|
||||
getName() { return this._name; }
|
||||
setName(name) { this._name = name; }
|
||||
|
||||
getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
getVersion() { return this.version; }
|
||||
|
||||
getLocale() {
|
||||
return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';
|
||||
}
|
||||
getLocale() { return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US'; }
|
||||
|
||||
getUserAgent() {
|
||||
return `Gelectron/${this.version} (${process.platform} ${process.arch}) Node.js/${process.versions.node}`;
|
||||
return this._userAgent || `Gelectron/${this.version} (${process.platform} ${process.arch}) Node.js/${process.versions ? process.versions.node : 'unknown'}`;
|
||||
}
|
||||
|
||||
getPathForProtocol(protocol) {
|
||||
return null;
|
||||
}
|
||||
setUserAgent(userAgent) { this._userAgent = userAgent || null; }
|
||||
|
||||
async whenReady() {
|
||||
if (this._ready) return;
|
||||
return new Promise((resolve) => {
|
||||
this.once('ready', resolve);
|
||||
getPathForProtocol(protocol) { return null; }
|
||||
|
||||
getApplicationInfoForProtocol(protocol) {
|
||||
return Promise.resolve({
|
||||
defaultIcon: null,
|
||||
icon: null,
|
||||
});
|
||||
}
|
||||
|
||||
async requestSingleInstanceLock() {
|
||||
this._ready = true;
|
||||
process.nextTick(() => this.emit('ready'));
|
||||
return true;
|
||||
// ─── Lifecycle ───────────────────────────────────────────────
|
||||
|
||||
async whenReady() {
|
||||
if (this._ready) return Promise.resolve();
|
||||
return new Promise((resolve) => { this.once('ready', resolve); });
|
||||
}
|
||||
|
||||
acquireSingleInstanceLock() {
|
||||
return true;
|
||||
}
|
||||
isReady() { return this._ready; }
|
||||
|
||||
requestSingleInstanceLock() { return true; }
|
||||
acquireSingleInstanceLock() { return true; }
|
||||
releaseSingleInstanceLock() {}
|
||||
|
||||
async quit(exitCode = 0) {
|
||||
this.emit('before-quit');
|
||||
quit(exitCode = 0) {
|
||||
if (this.listenerCount('before-quit') > 0 || this.listenerCount('will-quit') > 0) {
|
||||
this.emit('before-quit');
|
||||
this.emit('will-quit');
|
||||
}
|
||||
this.emit('quit', exitCode);
|
||||
process.exit(exitCode);
|
||||
}
|
||||
|
||||
exit(exitCode = 0) {
|
||||
if (this._ready) {
|
||||
this.emit('before-quit');
|
||||
this.emit('will-quit');
|
||||
}
|
||||
this.emit('quit', exitCode);
|
||||
process.exit(exitCode);
|
||||
}
|
||||
|
||||
relaunch(options = {}) {
|
||||
this._relaunchOptions = options;
|
||||
this._relaunching = true;
|
||||
this.emit('before-quit');
|
||||
const { spawn } = require('child_process');
|
||||
const execPath = options.execPath || process.execPath;
|
||||
const args = options.args || process.argv.slice(1);
|
||||
spawn(execPath, args, {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
env: process.env,
|
||||
}).unref();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
isReady() {
|
||||
return this._ready;
|
||||
// ─── Window Management Helpers ───────────────────────────────
|
||||
|
||||
focus() {
|
||||
if (process.platform === 'darwin') { this.dock && this.dock.show(); }
|
||||
this.emit('focus');
|
||||
}
|
||||
|
||||
hide() { if (this.dock) this.dock.hide(); this.emit('blur'); }
|
||||
show() { if (this.dock) this.dock.show(); this.emit('focus'); }
|
||||
isVisible() { return this.dock ? this.dock.isVisible() : true; }
|
||||
isHidden() { return this.dock ? !this.dock.isVisible() : false; }
|
||||
|
||||
// ─── App Metrics / GPU ──────────────────────────────────────
|
||||
|
||||
getAppMetrics() {
|
||||
return [
|
||||
{
|
||||
creationTime: Date.now() - (process.uptime() * 1000) | 0,
|
||||
pid: process.pid,
|
||||
rid: 0,
|
||||
type: 'Browser',
|
||||
memory: { workingSetSize: 0, peakWorkingSetSize: 0, privateBytes: 0, sharedBytes: 0 },
|
||||
sandboxed: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getGPUInfo(infoType) {
|
||||
if (infoType === 'basic') {
|
||||
return Promise.resolve({
|
||||
gpuDevice: [{ driverVendor: 'Gelectron', driverVersion: '0.0.0', driverDate: '', active: false }],
|
||||
GPUActive: false,
|
||||
});
|
||||
}
|
||||
return Promise.resolve({
|
||||
gpuDevice: [{ driverVendor: 'Gelectron', driverVersion: '0.0.0', driverDate: '', active: false }],
|
||||
GPUActive: false,
|
||||
auxAttributes: {},
|
||||
gpuDriver: 'Gelectron',
|
||||
gpuDriverVersion: '0.0.0',
|
||||
gpuWorkingSetSize: 0,
|
||||
});
|
||||
}
|
||||
|
||||
getGPUFeatureStatus() {
|
||||
return {
|
||||
gpuCompositing: 'disabled',
|
||||
multipleRasterThreads: 'disabled',
|
||||
nativeGpuMemoryBuffers: 'disabled',
|
||||
rasterization: 'disabled',
|
||||
smoothScrolling: 'disabled',
|
||||
videoDecode: 'disabled',
|
||||
videoEncode: 'disabled',
|
||||
webgl: 'disabled',
|
||||
webgl2: 'disabled',
|
||||
};
|
||||
}
|
||||
|
||||
disableHardwareAcceleration() {}
|
||||
disableDomainBlockingFor3DAPIs() {}
|
||||
|
||||
// ─── Badge ───────────────────────────────────────────────────
|
||||
|
||||
setBadgeCount(count) {
|
||||
this._badgeCount = count || 0;
|
||||
if (this.dock) this.dock.setBadgeCount(this._badgeCount);
|
||||
return this._badgeCount;
|
||||
}
|
||||
|
||||
getBadgeCount() { return this._badgeCount; }
|
||||
|
||||
// ─── Recent Documents ────────────────────────────────────────
|
||||
|
||||
addRecentDocument(path) {}
|
||||
clearRecentDocuments() {}
|
||||
setRecentDocumentLabel(label) {}
|
||||
|
||||
// ─── App User Model ID ──────────────────────────────────────
|
||||
|
||||
setAppUserModelId(id) {}
|
||||
getAppUserModelId() {
|
||||
return '';
|
||||
getAppUserModelId() { return ''; }
|
||||
|
||||
// ─── Login Items ─────────────────────────────────────────────
|
||||
|
||||
getLoginItemSettings() {
|
||||
return {
|
||||
openAtLogin: false,
|
||||
openAsHidden: false,
|
||||
launchAtLogin: false,
|
||||
launchItems: [],
|
||||
};
|
||||
}
|
||||
|
||||
setLoginItemSettings(settings) {}
|
||||
|
||||
// ─── Applications Folder ─────────────────────────────────────
|
||||
|
||||
isInApplicationsFolder() { return true; }
|
||||
moveToApplicationsFolder() {}
|
||||
|
||||
// ─── File Icons ──────────────────────────────────────────────
|
||||
|
||||
getFileIcon(path, options, callback) {
|
||||
if (typeof options === 'function') { callback = options; }
|
||||
if (callback) callback(null, null);
|
||||
}
|
||||
|
||||
// ─── About Panel ─────────────────────────────────────────────
|
||||
|
||||
setAboutPanelOptions(options = {}) {
|
||||
this._aboutPanelOptions = {
|
||||
applicationName: this._name,
|
||||
applicationVersion: this.version,
|
||||
copyright: '',
|
||||
credits: '',
|
||||
authors: [],
|
||||
website: '',
|
||||
iconPath: '',
|
||||
...options,
|
||||
};
|
||||
}
|
||||
|
||||
getAboutPanelOptions() {
|
||||
return { ...this._aboutPanelOptions };
|
||||
}
|
||||
|
||||
// ─── Certificate Trust ───────────────────────────────────────
|
||||
|
||||
async showCertificateTrustDialog() {}
|
||||
|
||||
on(eventName, listener) {
|
||||
super.on(eventName, listener);
|
||||
return this;
|
||||
// ─── Secure Keyboard Entry ──────────────────────────────────
|
||||
|
||||
setSecureKeyboardEntryEnabled(enabled) {
|
||||
this._secureKeyboardEntryEnabled = !!enabled;
|
||||
}
|
||||
|
||||
once(eventName, listener) {
|
||||
super.once(eventName, listener);
|
||||
return this;
|
||||
isSecureKeyboardEntryEnabled() {
|
||||
return this._secureKeyboardEntryEnabled;
|
||||
}
|
||||
|
||||
getLoginItemSettings() {
|
||||
return { openAtLogin: false, openAsHidden: false };
|
||||
}
|
||||
// ─── Window Tracking ────────────────────────────────────────
|
||||
|
||||
setLoginItemSettings() {}
|
||||
_trackWindow() { this._windowCount++; }
|
||||
|
||||
isInApplicationsFolder() {
|
||||
return true;
|
||||
}
|
||||
|
||||
moveToApplicationsFolder() {}
|
||||
|
||||
getFileIcon(path, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
_untrackWindow() {
|
||||
this._windowCount--;
|
||||
if (this._windowCount <= 0) {
|
||||
this._windowCount = 0;
|
||||
this.emit('window-all-closed');
|
||||
}
|
||||
callback(null, null);
|
||||
}
|
||||
|
||||
focus(options) {}
|
||||
hide() {}
|
||||
show() {}
|
||||
isVisible() {
|
||||
return true;
|
||||
}
|
||||
isHidden() {
|
||||
return false;
|
||||
}
|
||||
setAboutPanelOptions() {}
|
||||
getWindowCount() { return this._windowCount; }
|
||||
|
||||
// ─── EventEmitter overrides (return this for chaining) ──────
|
||||
|
||||
on(eventName, listener) { super.on(eventName, listener); return this; }
|
||||
once(eventName, listener) { super.once(eventName, listener); return this; }
|
||||
addListener(eventName, listener) { super.addListener(eventName, listener); return this; }
|
||||
removeListener(eventName, listener) { super.removeListener(eventName, listener); return this; }
|
||||
removeAllListeners(eventName) { super.removeAllListeners(eventName); return this; }
|
||||
}
|
||||
|
||||
const app = new App();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
const { EventEmitter } = require('events');
|
||||
const path = require('path');
|
||||
const { bridge, isNative } = require('./native-bridge');
|
||||
const { app } = require('./app');
|
||||
|
||||
class WebContents extends EventEmitter {
|
||||
constructor(id) {
|
||||
@@ -205,6 +206,10 @@ class BrowserWindow extends EventEmitter {
|
||||
|
||||
BrowserWindow._windows.set(this.id, this);
|
||||
|
||||
if (typeof app._trackWindow === 'function') {
|
||||
app._trackWindow();
|
||||
}
|
||||
|
||||
if (isNative) {
|
||||
bridge.createWindow(this.id, {
|
||||
width: this._options.width,
|
||||
@@ -284,6 +289,9 @@ class BrowserWindow extends EventEmitter {
|
||||
this._isDestroyed = true;
|
||||
if (isNative) bridge.destroyWindow(this.id);
|
||||
BrowserWindow._windows.delete(this.id);
|
||||
if (typeof app._untrackWindow === 'function') {
|
||||
app._untrackWindow();
|
||||
}
|
||||
this.emit('closed');
|
||||
}
|
||||
|
||||
|
||||
+65
-1
@@ -2,6 +2,10 @@
|
||||
|
||||
/**
|
||||
* Gelectron - menu module (Electron compatible)
|
||||
*
|
||||
* Supports native menu rendering through the Rust/tao bridge.
|
||||
* When running in native mode, setApplicationMenu and popup route
|
||||
* through the bridge for native OS menu rendering.
|
||||
*/
|
||||
|
||||
const { EventEmitter } = require('events');
|
||||
@@ -21,6 +25,15 @@ class MenuItem extends EventEmitter {
|
||||
this.toolTip = options.toolTip || '';
|
||||
this.icon = options.icon || null;
|
||||
this._click = options.click || null;
|
||||
|
||||
// Recursively build submenu
|
||||
if (this.submenu && !(this.submenu instanceof Menu)) {
|
||||
if (Array.isArray(this.submenu)) {
|
||||
this.submenu = Menu.buildFromTemplate(this.submenu);
|
||||
} else {
|
||||
this.submenu = Menu.buildFromTemplate(this.submenu.items || []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
click() {
|
||||
@@ -39,6 +52,7 @@ class Menu extends EventEmitter {
|
||||
}
|
||||
|
||||
static _nextId = 1;
|
||||
static _applicationMenu = null;
|
||||
|
||||
static buildFromTemplate(template) {
|
||||
const menu = new Menu();
|
||||
@@ -60,6 +74,17 @@ class Menu extends EventEmitter {
|
||||
|
||||
static setApplicationMenu(menu) {
|
||||
Menu._applicationMenu = menu;
|
||||
if (menu) {
|
||||
// Route through bridge if available
|
||||
try {
|
||||
const { bridge, isNative } = require('./native-bridge');
|
||||
if (isNative && bridge) {
|
||||
bridge._send({ type: 'set-application-menu', menu: menu._serialize() });
|
||||
}
|
||||
} catch (e) {
|
||||
// Not available in all contexts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
append(menuItem) {
|
||||
@@ -81,10 +106,24 @@ class Menu extends EventEmitter {
|
||||
}
|
||||
|
||||
popup(options = {}) {
|
||||
try {
|
||||
const { bridge, isNative } = require('./native-bridge');
|
||||
if (isNative && bridge) {
|
||||
bridge._send({ type: 'popup-menu', menu: this._serialize(), x: options.x, y: options.y });
|
||||
return;
|
||||
}
|
||||
} catch (e) {}
|
||||
console.log('[gelectron] Menu.popup called');
|
||||
}
|
||||
|
||||
closePopup() {
|
||||
try {
|
||||
const { bridge, isNative } = require('./native-bridge');
|
||||
if (isNative && bridge) {
|
||||
bridge._send({ type: 'close-popup-menu' });
|
||||
return;
|
||||
}
|
||||
} catch (e) {}
|
||||
console.log('[gelectron] Menu.closePopup called');
|
||||
}
|
||||
|
||||
@@ -96,13 +135,38 @@ class Menu extends EventEmitter {
|
||||
for (const item of items) {
|
||||
if (item.id === id) return item;
|
||||
if (item.submenu) {
|
||||
const found = this._findMenuItemById(item.submenu.items || item.submenu, id);
|
||||
const submenu = item.submenu instanceof Menu ? item.submenu.items : (item.submenu.items || item.submenu);
|
||||
const found = this._findMenuItemById(submenu, id);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_serialize() {
|
||||
return {
|
||||
items: this.items.map((item) => {
|
||||
const obj = {
|
||||
id: item.id,
|
||||
label: item.label,
|
||||
type: item.type,
|
||||
role: item.role,
|
||||
accelerator: item.accelerator,
|
||||
enabled: item.enabled,
|
||||
visible: item.visible,
|
||||
checked: item.checked,
|
||||
toolTip: item.toolTip,
|
||||
};
|
||||
if (item.submenu instanceof Menu) {
|
||||
obj.submenu = item.submenu._serialize();
|
||||
} else if (item.submenu && Array.isArray(item.submenu)) {
|
||||
obj.submenu = Menu.buildFromTemplate(item.submenu)._serialize();
|
||||
}
|
||||
return obj;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
items() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user