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:
miles committed 2026-07-27 23:56:34 -05:00
1 parent 6392c2231c
commit e5d93b3613
40 files changed
+6440 -123

No files matched your search

+411
View File
@@ -162,6 +162,57 @@
font-family: 'SF Mono', Menlo, monospace;
}
.test-card { grid-column: 1 / -1; }
.test-results { margin-top: 12px; }
.test-row {
display: flex;
align-items: center;
padding: 6px 0;
border-bottom: 1px solid #1f1f35;
font-size: 13px;
}
.test-row:last-child { border-bottom: none; }
.test-pass { color: #6bcb77; }
.test-fail { color: #ff6b6b; }
.test-name { flex: 1; color: #b0b0cc; }
.test-value { color: #8888aa; font-family: 'SF Mono', Menlo, monospace; margin-left: 12px; }
.btn-grid {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 12px;
}
.btn-grid button {
background: #2a2a4a;
color: #e0e0e0;
border: 1px solid #3a3a6a;
border-radius: 8px;
padding: 8px 14px;
font-size: 13px;
cursor: pointer;
transition: background 0.15s, transform 0.1s;
}
.btn-grid button:hover { background: #3a3a6a; }
.btn-grid button:active { transform: scale(0.95); }
.btn-grid button.active { background: #7b68ee; border-color: #7b68ee; }
.demo-output {
margin-top: 10px;
background: #12121f;
border: 1px solid #2a2a4a;
border-radius: 8px;
padding: 12px;
font-family: 'SF Mono', Menlo, monospace;
font-size: 12px;
color: #b0b0cc;
white-space: pre-wrap;
word-break: break-all;
max-height: 180px;
overflow-y: auto;
display: none;
}
footer {
padding: 16px 32px;
border-top: 1px solid #2a2a4a;
@@ -225,6 +276,54 @@
<span style="background: #ee5a24;"></span>
</div>
</div>
<div class="card" style="grid-column: 1 / -1;">
<h2>App Module Demo</h2>
<p>Interactive demo of the Electron app API — properties, methods, and lifecycle.</p>
<div class="btn-grid">
<button onclick="demoApp('version')">getVersion()</button>
<button onclick="demoApp('locale')">getLocale()</button>
<button onclick="demoApp('userAgent')">getUserAgent()</button>
<button onclick="demoApp('setUserAgent')">setUserAgent()</button>
<button onclick="demoApp('appPath')">getAppPath()</button>
<button onclick="demoApp('isReady')">isReady</button>
<button onclick="demoApp('badge')">setBadgeCount(7)</button>
<button onclick="demoApp('metrics')">getAppMetrics()</button>
<button onclick="demoApp('gpu')">getGPUInfo()</button>
<button onclick="demoApp('gpuFeatures')">getGPUFeatureStatus()</button>
<button onclick="demoApp('loginItem')">getLoginItemSettings()</button>
<button onclick="demoApp('aboutPanel')">getAboutPanelOptions()</button>
<button onclick="demoApp('secureKeyboard')">setSecureKeyboardEntry()</button>
<button onclick="demoApp('name')">app.name =</button>
<button onclick="demoApp('paths')">getPath(home)</button>
<button onclick="demoApp('dock')">dock.bounce()</button>
</div>
<div class="demo-output" id="app-demo-output"></div>
</div>
<div class="card" style="grid-column: 1 / -1;">
<h2>Menu Module Demo</h2>
<p>Interactive demo of the Electron Menu API — build, set, and inspect native menus.</p>
<div class="btn-grid">
<button onclick="demoMenu('build')">Menu.buildFromTemplate()</button>
<button onclick="demoMenu('set')">Menu.setApplicationMenu()</button>
<button onclick="demoMenu('get')">Menu.getApplicationMenu()</button>
<button onclick="demoMenu('findById')">getMenuItemById()</button>
<button onclick="demoMenu('append')">menu.append()</button>
<button onclick="demoMenu('serialize')">menu._serialize()</button>
<button onclick="demoMenu('count')">menu.items.length</button>
<button onclick="demoMenu('submenu')">Submenu nesting</button>
</div>
<div class="demo-output" id="menu-demo-output"></div>
</div>
<div class="card test-card">
<h2>App Module Tests</h2>
<p>Automated tests for the Electron app compatibility layer.</p>
<div id="app-tests" class="test-results">
<p style="color: #8888aa; font-size: 13px;">Waiting for test results...</p>
</div>
</div>
</main>
<footer>Gelectron v0.1.0 &mdash; Electron API compatibility layer powered by Gecko/Servo</footer>
@@ -290,6 +389,318 @@
document.getElementById('env-arch').textContent = 'unknown (browser sandbox)';
document.getElementById('env-node').textContent = 'N/A in renderer';
document.getElementById('env-ua').textContent = navigator.userAgent;
// App module interactive demo
function demoApp(action) {
var out = document.getElementById('app-demo-output');
out.style.display = 'block';
var electron = window.electron;
if (!electron || !electron.app) {
out.textContent = 'Error: window.electron.app not available (renderer-only mode)';
return;
}
var app = electron.app;
var result = '';
switch (action) {
case 'version':
result = 'app.getVersion() → ' + app.getVersion() +
'\napp.version (property) → ' + app.version;
break;
case 'locale':
result = 'app.getLocale() → ' + app.getLocale() +
'\napp.locale (property) → ' + app.locale;
break;
case 'userAgent':
result = 'app.getUserAgent() → ' + app.getUserAgent() +
'\napp.userAgent (property) → ' + app.userAgent;
break;
case 'setUserAgent':
app.setUserAgent('GelectronDemo/2.0');
result = 'app.setUserAgent("GelectronDemo/2.0")' +
'\napp.getUserAgent() → ' + app.getUserAgent();
app.setUserAgent(null);
result += '\napp.setUserAgent(null) reset → ' + app.getUserAgent();
break;
case 'appPath':
result = 'app.getAppPath() → ' + app.getAppPath() +
'\napp.appPath (property) → ' + app.appPath;
break;
case 'isReady':
result = 'app.isReady (property) → ' + app.isReady +
'\napp.isReady() method → ' + app.isReady() +
'\napp.whenReady() → [Promise resolved]';
app.whenReady().then(function() {
out.textContent += '\n→ whenReady promise resolved!';
});
break;
case 'badge':
app.setBadgeCount(7);
result = 'app.setBadgeCount(7)' +
'\napp.getBadgeCount() → ' + app.getBadgeCount();
app.setBadgeCount(0);
result += '\napp.setBadgeCount(0) → ' + app.getBadgeCount();
break;
case 'metrics':
var m = app.getAppMetrics();
result = 'app.getAppMetrics() → [' + m.length + ' entries]' +
'\n pid: ' + m[0].pid +
'\n type: ' + m[0].type +
'\n memory: ' + JSON.stringify(m[0].memory) +
'\n sandboxed: ' + m[0].sandboxed;
break;
case 'gpu':
app.getGPUInfo('basic').then(function(info) {
out.textContent = 'app.getGPUInfo("basic") →\n' +
' GPUActive: ' + info.GPUActive +
'\n gpuDevice: ' + JSON.stringify(info.gpuDevice, null, 2);
});
result = 'Loading GPU info...';
break;
case 'gpuFeatures':
var f = app.getGPUFeatureStatus();
var lines = ['app.getGPUFeatureStatus() →'];
for (var k in f) lines.push(' ' + k + ': ' + f[k]);
result = lines.join('\n');
break;
case 'loginItem':
var s = app.getLoginItemSettings();
result = 'app.getLoginItemSettings() →\n' +
' openAtLogin: ' + s.openAtLogin +
'\n openAsHidden: ' + s.openAsHidden +
'\n launchAtLogin: ' + s.launchAtLogin +
'\n launchItems: ' + JSON.stringify(s.launchItems);
break;
case 'aboutPanel':
app.setAboutPanelOptions({ applicationName: 'Gelectron Demo', copyright: 'MIT' });
var o = app.getAboutPanelOptions();
result = 'app.setAboutPanelOptions({ applicationName: "Gelectron Demo", copyright: "MIT" })' +
'\napp.getAboutPanelOptions() →\n' + JSON.stringify(o, null, 2);
break;
case 'secureKeyboard':
app.setSecureKeyboardEntryEnabled(true);
result = 'app.setSecureKeyboardEntryEnabled(true)' +
'\napp.isSecureKeyboardEntryEnabled() → ' + app.isSecureKeyboardEntryEnabled();
app.setSecureKeyboardEntryEnabled(false);
result += '\napp.setSecureKeyboardEntryEnabled(false)' +
'\napp.isSecureKeyboardEntryEnabled() → ' + app.isSecureKeyboardEntryEnabled();
break;
case 'name':
var old = app.name;
app.name = 'Gelectron Demo App';
result = 'app.name = "Gelectron Demo App"' +
'\napp.name → ' + app.name +
'\napp.getName() → ' + app.getName();
app.name = old;
result += '\n(app.name restored to "' + old + '")';
break;
case 'paths':
result = 'app.getPath("home") → ' + app.getPath('home') +
'\napp.getPath("userData") → ' + app.getPath('userData') +
'\napp.getPath("temp") → ' + app.getPath('temp') +
'\napp.getPath("desktop") → ' + app.getPath('desktop') +
'\napp.getPath("documents") → ' + app.getPath('documents') +
'\napp.getPath("downloads") → ' + app.getPath('downloads') +
'\napp.getPath("logs") → ' + app.getPath('logs');
break;
case 'dock':
if (app.dock) {
var id = app.dock.bounce();
result = 'app.dock.bounce() → ' + id +
'\napp.dock.isVisible() → ' + app.dock.isVisible() +
'\napp.dock.getBadge() → "' + app.dock.getBadge() + '"';
} else {
result = 'app.dock → null (not macOS)';
}
break;
}
out.textContent = result;
}
// Menu module interactive demo
function demoMenu(action) {
var out = document.getElementById('menu-demo-output');
out.style.display = 'block';
var electron = window.electron;
if (!electron || !electron.Menu) {
out.textContent = 'Error: window.electron.Menu not available';
return;
}
var Menu = electron.Menu;
var MenuItem = electron.MenuItem;
var result = '';
switch (action) {
case 'build': {
var menu = Menu.buildFromTemplate([
{ label: 'File', submenu: [
{ label: 'New', accelerator: 'CmdOrCtrl+N' },
{ label: 'Open', accelerator: 'CmdOrCtrl+O' },
{ type: 'separator' },
{ label: 'Quit', accelerator: 'CmdOrCtrl+Q' },
]},
{ label: 'Edit', submenu: [
{ label: 'Cut', accelerator: 'CmdOrCtrl+X' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V' },
]},
{ label: 'Help', submenu: [
{ label: 'About Gelectron' },
]},
]);
result = 'Menu.buildFromTemplate([...]) → Menu {\n' +
' items.length: ' + menu.items.length + '\n' +
' items[0].label: "' + menu.items[0].label + '"\n' +
' items[0].submenu.items.length: ' + menu.items[0].submenu.items.length + '\n' +
' items[1].label: "' + menu.items[1].label + '"\n' +
' items[2].label: "' + menu.items[2].label + '"\n' +
'}';
break;
}
case 'set': {
var menu = Menu.buildFromTemplate([
{ label: 'File', submenu: [
{ label: 'New Window', accelerator: 'CmdOrCtrl+N' },
{ type: 'separator' },
{ label: 'Quit', accelerator: 'CmdOrCtrl+Q' },
]},
{ label: 'View', submenu: [
{ label: 'Reload', accelerator: 'CmdOrCtrl+R' },
{ label: 'Toggle DevTools', accelerator: 'CmdOrCtrl+Shift+I' },
]},
]);
Menu.setApplicationMenu(menu);
var current = Menu.getApplicationMenu();
result = 'Menu.setApplicationMenu(menu) → sent to native bridge' +
'\nMenu.getApplicationMenu() → ' + (current ? 'Menu { items: ' + current.items.length + ' }' : 'null');
break;
}
case 'get': {
var current = Menu.getApplicationMenu();
if (current) {
var labels = current.items.map(function(i) { return i.label; });
result = 'Menu.getApplicationMenu() → Menu {\n' +
' items: [' + labels.join(', ') + ']\n' +
' items.length: ' + current.items.length + '\n' +
'}';
} else {
result = 'Menu.getApplicationMenu() → null\n(No application menu set yet. Click "Menu.setApplicationMenu()" first.)';
}
break;
}
case 'findById': {
var menu = Menu.buildFromTemplate([
{ id: 'file-menu', label: 'File', submenu: [
{ id: 'new-file', label: 'New File' },
{ id: 'open-file', label: 'Open File' },
]},
{ id: 'edit-menu', label: 'Edit', submenu: [
{ id: 'copy-item', label: 'Copy' },
]},
]);
var item = menu.getMenuItemById('new-file');
var item2 = menu.getMenuItemById('copy-item');
var missing = menu.getMenuItemById('nonexistent');
result = 'menu.getMenuItemById("new-file") →\n' +
' label: "' + (item ? item.label : 'null') + '"\n' +
' id: "' + (item ? item.id : 'null') + '"' +
'\nmenu.getMenuItemById("copy-item") →\n' +
' label: "' + (item2 ? item2.label : 'null') + '"' +
'\nmenu.getMenuItemById("nonexistent") → ' + (missing ? 'found' : 'null');
break;
}
case 'append': {
var menu = Menu.buildFromTemplate([
{ label: 'Existing Item' },
]);
result = 'Before append: items.length = ' + menu.items.length;
menu.append(new MenuItem({ label: 'Appended Item', type: 'normal' }));
result += '\nmenu.append(new MenuItem({ label: "Appended Item" }))' +
'\nAfter append: items.length = ' + menu.items.length +
'\n items[0].label: "' + menu.items[0].label + '"' +
'\n items[1].label: "' + menu.items[1].label + '"';
break;
}
case 'serialize': {
var menu = Menu.buildFromTemplate([
{ label: 'File', submenu: [
{ label: 'New', accelerator: 'CmdOrCtrl+N' },
{ type: 'separator' },
{ label: 'Quit' },
]},
{ label: 'Edit', enabled: false },
]);
var s = menu._serialize();
result = 'menu._serialize() →\n' + JSON.stringify(s, null, 2);
break;
}
case 'count': {
var menu = Menu.buildFromTemplate([
{ label: 'File', submenu: [{ label: 'New' }] },
{ label: 'Edit' },
{ label: 'View' },
{ label: 'Help' },
]);
result = 'Menu.buildFromTemplate(4 top-level items)' +
'\nmenu.items.length → ' + menu.items.length +
'\nmenu.items.map(i => i.label) → [' +
menu.items.map(function(i) { return '"' + i.label + '"'; }).join(', ') + ']' +
'\nmenu.items[0].submenu.items.length → ' + menu.items[0].submenu.items.length;
break;
}
case 'submenu': {
var menu = Menu.buildFromTemplate([
{ label: 'Format', submenu: [
{ label: 'Font', submenu: [
{ label: 'Bold', type: 'checkbox' },
{ label: 'Italic', type: 'checkbox' },
{ label: 'Underline', type: 'checkbox' },
]},
{ type: 'separator' },
{ label: 'Align Left' },
{ label: 'Align Center' },
{ label: 'Align Right' },
]},
]);
var fmt = menu.items[0];
result = 'Menu with nested submenus:' +
'\nmenu.items[0].label → "' + fmt.label + '"' +
'\nmenu.items[0].submenu.items.length → ' + fmt.submenu.items.length +
'\nmenu.items[0].submenu.items[0].label → "' + fmt.submenu.items[0].label + '"' +
'\nmenu.items[0].submenu.items[0].submenu.items.length → ' +
fmt.submenu.items[0].submenu.items.length +
'\n nested items: ' +
fmt.submenu.items[0].submenu.items.map(function(i) {
return '"' + i.label + '"';
}).join(', ');
break;
}
}
out.textContent = result;
}
// App test results renderer
function renderAppTests() {
var results = window.__appTestResults;
if (!results) return;
var el = document.getElementById('app-tests');
var html = '';
var pass = 0, fail = 0;
for (var i = 0; i < results.length; i++) {
var r = results[i];
var cls = r.status === 'PASS' ? 'test-pass' : 'test-fail';
var icon = r.status === 'PASS' ? '\u2713' : '\u2717';
if (r.status === 'PASS') pass++; else fail++;
html += '<div class="test-row">' +
'<span class="' + cls + '">' + icon + '</span>' +
'<span class="test-name">' + r.name + '</span>' +
'<span class="test-value">' + r.value + '</span>' +
'</div>';
}
html = '<div style="margin-bottom: 12px; font-size: 14px; font-weight: 600;">' +
'<span class="test-pass">' + pass + ' passed</span> &middot; ' +
'<span class="test-fail">' + fail + ' failed</span> &middot; ' +
(pass + fail) + ' total</div>' + html;
el.innerHTML = html;
}
</script>
</body>
</html>
+444
View File
@@ -1,8 +1,393 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const results = [];
function test(name, fn) {
try {
const val = fn();
results.push({ name, status: 'PASS', value: String(val) });
} catch (e) {
results.push({ name, status: 'FAIL', value: e.message });
}
}
function asyncTest(name, fn) {
return fn().then((val) => {
results.push({ name, status: 'PASS', value: String(val) });
}).catch((e) => {
results.push({ name, status: 'FAIL', value: e.message });
});
}
let mainWindow = null;
// ─── Properties ────────────────────────────────────────────────
test('app.requestSingleInstanceLock() returns boolean', () => {
const lock = app.requestSingleInstanceLock();
if (typeof lock !== 'boolean') throw new Error('Expected boolean, got ' + typeof lock);
return lock;
});
test('app.isReady() (method)', () => app.isReady());
test('app.isReady (property)', () => {
if (typeof app.isReady !== 'boolean') throw new Error('Expected boolean, got ' + typeof app.isReady);
return app.isReady;
});
test('app.appPath (property)', () => {
if (typeof app.appPath !== 'string') throw new Error('Expected string, got ' + typeof app.appPath);
return app.appPath;
});
test('app.locale (property)', () => {
if (typeof app.locale !== 'string') throw new Error('Expected string, got ' + typeof app.locale);
return app.locale;
});
test('app.userAgent (property)', () => {
if (typeof app.userAgent !== 'string') throw new Error('Expected string, got ' + typeof app.userAgent);
return app.userAgent;
});
test('app.getVersion()', () => app.getVersion());
test('app.getName()', () => app.getName());
test('app.getAppPath()', () => app.getAppPath());
test('app.name get/set', () => {
const old = app.name;
app.name = 'TestApp';
const result = app.name;
app.name = old;
if (result !== 'TestApp') throw new Error('Expected TestApp, got ' + result);
return result;
});
test('app.name set null reverts', () => {
app.name = null;
return app.name === 'Gelectron App';
});
// ─── Path Methods ──────────────────────────────────────────────
test('app.getPath("home")', () => app.getPath('home'));
test('app.getPath("userData")', () => app.getPath('userData'));
test('app.getPath("temp")', () => app.getPath('temp'));
test('app.getPath("desktop")', () => app.getPath('desktop'));
test('app.getPath("documents")', () => app.getPath('documents'));
test('app.getPath("downloads")', () => app.getPath('downloads'));
test('app.getPath("logs")', () => app.getPath('logs'));
test('app.getPath("crashDumps")', () => app.getPath('crashDumps'));
test('app.getPath("app") returns userData', () => {
return app.getPath('app') === app.getPath('userData');
});
test('app.setPath / app.getPath roundtrip', () => {
app.setPath('testPath', '/tmp/test-gelectron');
return app.getPath('testPath') === '/tmp/test-gelectron';
});
test('app.getPath("unknown") returns userData fallback', () => {
return app.getPath('nonexistent') === app.getPath('userData');
});
// ─── User Agent / Locale ───────────────────────────────────────
test('app.getLocale()', () => app.getLocale());
test('app.getUserAgent()', () => app.getUserAgent());
test('app.setUserAgent()', () => {
app.setUserAgent('TestAgent/1.0');
const result = app.getUserAgent();
app.setUserAgent(null);
return result;
});
test('app.setUserAgent(null) resets', () => {
app.setUserAgent(null);
const ua = app.getUserAgent();
if (!ua.includes('Gelectron')) throw new Error('Expected Gelectron UA, got ' + ua);
return true;
});
// ─── Lifecycle ─────────────────────────────────────────────────
test('app.isPackaged is boolean', () => {
if (typeof app.isPackaged !== 'boolean') throw new Error('Expected boolean');
return app.isPackaged;
});
test('app.whenReady() returns Promise', () => {
const p = app.whenReady();
if (!p || typeof p.then !== 'function') throw new Error('Not a Promise');
return true;
});
test('app.requestSingleInstanceLock() sync', () => {
const result = app.requestSingleInstanceLock();
return typeof result === 'boolean';
});
test('app.acquireSingleInstanceLock() sync', () => {
const result = app.acquireSingleInstanceLock();
return typeof result === 'boolean';
});
test('app.releaseSingleInstanceLock() no-op', () => {
app.releaseSingleInstanceLock();
return true;
});
// ─── Events ────────────────────────────────────────────────────
test('app.on / app.removeListener', () => {
let called = false;
const fn = () => { called = true; };
app.on('test-event', fn);
app.emit('test-event');
app.removeListener('test-event', fn);
return called;
});
test('app.once fires once', () => {
let count = 0;
app.once('test-once', () => { count++; });
app.emit('test-once');
app.emit('test-once');
return count === 1;
});
test('app.addListener returns this', () => {
const fn = () => {};
const result = app.addListener('test-chain', fn);
app.removeListener('test-chain', fn);
return result === app;
});
test('app.emit("activate") does not crash', () => {
app.emit('activate');
return true;
});
test('app.emit("focus") does not crash', () => {
app.emit('focus');
return true;
});
test('app.emit("blur") does not crash', () => {
app.emit('blur');
return true;
});
test('app.emit("browser-window-focus") does not crash', () => {
app.emit('browser-window-focus');
return true;
});
test('app.emit("browser-window-blur") does not crash', () => {
app.emit('browser-window-blur');
return true;
});
test('app.emit("web-contents-created") does not crash', () => {
app.emit('web-contents-created', {}, {});
return true;
});
// ─── Dock (macOS) ──────────────────────────────────────────────
test('app.dock exists (macOS)', () => {
if (process.platform === 'darwin') {
if (!app.dock) throw new Error('app.dock is null on macOS');
return typeof app.dock;
}
return 'N/A (not macOS)';
});
test('app.dock.bounce', () => {
if (process.platform === 'darwin') return app.dock.bounce();
return 'N/A';
});
test('app.dock.setBadgeCount / getBadgeCount', () => {
if (process.platform === 'darwin') {
app.dock.setBadgeCount(5);
return app.dock.getBadgeCount();
}
return 'N/A';
});
// ─── Command Line ──────────────────────────────────────────────
test('app.commandLine.appendSwitch', () => {
app.commandLine.appendSwitch('test-switch', 'test-value');
return app.commandLine.hasSwitch('test-switch');
});
test('app.commandLine.getSwitch', () => app.commandLine.getSwitch('test-switch'));
test('app.commandLine.removeSwitch', () => {
app.commandLine.removeSwitch('test-switch');
return !app.commandLine.hasSwitch('test-switch');
});
// ─── Badge ─────────────────────────────────────────────────────
test('app.setBadgeCount / getBadgeCount', () => {
const result = app.setBadgeCount(3);
if (app.getBadgeCount() !== 3) throw new Error('Expected 3, got ' + app.getBadgeCount());
app.setBadgeCount(0);
return result;
});
test('app.setBadgeCount(0) resets', () => {
app.setBadgeCount(5);
app.setBadgeCount(0);
return app.getBadgeCount() === 0;
});
// ─── Metrics / GPU ────────────────────────────────────────────
test('app.getAppMetrics() returns array', () => {
const metrics = app.getAppMetrics();
if (!Array.isArray(metrics)) throw new Error('Expected array');
if (metrics.length === 0) throw new Error('Expected at least one entry');
const m = metrics[0];
if (typeof m.pid !== 'number') throw new Error('Expected pid to be number');
if (!m.memory) throw new Error('Expected memory object');
return metrics.length + ' entries';
});
test('app.getGPUInfo("basic")', async () => {
const info = await app.getGPUInfo('basic');
if (!info || !info.gpuDevice) throw new Error('Missing gpuDevice');
return info.GPUActive;
});
test('app.getGPUInfo("complete")', async () => {
const info = await app.getGPUInfo('complete');
if (!info || !info.gpuDriver) throw new Error('Missing gpuDriver');
return info.gpuDriver;
});
test('app.getGPUFeatureStatus()', () => {
const status = app.getGPUFeatureStatus();
if (!status || typeof status.gpuCompositing !== 'string') throw new Error('Missing gpuCompositing');
return Object.keys(status).length + ' features';
});
test('app.disableHardwareAcceleration() no-op', () => {
app.disableHardwareAcceleration();
return true;
});
test('app.disableDomainBlockingFor3DAPIs() no-op', () => {
app.disableDomainBlockingFor3DAPIs();
return true;
});
// ─── Login Items ───────────────────────────────────────────────
test('app.getLoginItemSettings()', () => {
const s = app.getLoginItemSettings();
if (typeof s.openAtLogin !== 'boolean') throw new Error('Missing openAtLogin');
if (!s.hasOwnProperty('launchAtLogin')) throw new Error('Missing launchAtLogin');
return true;
});
test('app.setLoginItemSettings() no-op', () => {
app.setLoginItemSettings({ openAtLogin: true });
return true;
});
// ─── About Panel ───────────────────────────────────────────────
test('app.setAboutPanelOptions / getAboutPanelOptions', () => {
app.setAboutPanelOptions({ applicationName: 'Test', copyright: 'MIT' });
const opts = app.getAboutPanelOptions();
if (opts.applicationName !== 'Test') throw new Error('Expected Test, got ' + opts.applicationName);
return opts.copyright;
});
test('app.setAboutPanelOptions() with no args resets', () => {
app.setAboutPanelOptions();
const opts = app.getAboutPanelOptions();
return typeof opts === 'object';
});
// ─── Recent Documents ──────────────────────────────────────────
test('app.addRecentDocument() no-op', () => { app.addRecentDocument('/tmp/test'); return true; });
test('app.clearRecentDocuments() no-op', () => { app.clearRecentDocuments(); return true; });
test('app.setRecentDocumentLabel() no-op', () => { app.setRecentDocumentLabel('Test'); return true; });
// ─── App User Model ID ────────────────────────────────────────
test('app.setAppUserModelId() no-op', () => { app.setAppUserModelId('com.test'); return true; });
test('app.getAppUserModelId()', () => {
const result = app.getAppUserModelId();
if (typeof result !== 'string') throw new Error('Expected string');
return result === '' ? '(empty)' : result;
});
// ─── Applications Folder ──────────────────────────────────────
test('app.isInApplicationsFolder()', () => app.isInApplicationsFolder());
test('app.moveToApplicationsFolder() no-op', () => { app.moveToApplicationsFolder(); return true; });
// ─── File Icons ────────────────────────────────────────────────
test('app.getFileIcon() callback', (done) => {
return new Promise((resolve) => {
app.getFileIcon('/tmp', (err, icon) => {
resolve(true);
});
});
});
// ─── Certificate Trust ────────────────────────────────────────
test('app.showCertificateTrustDialog()', async () => {
await app.showCertificateTrustDialog();
return true;
});
// ─── Secure Keyboard Entry ────────────────────────────────────
test('app.setSecureKeyboardEntryEnabled / isSecureKeyboardEntryEnabled', () => {
app.setSecureKeyboardEntryEnabled(true);
const result = app.isSecureKeyboardEntryEnabled();
app.setSecureKeyboardEntryEnabled(false);
return result;
});
// ─── Window Count ──────────────────────────────────────────────
test('app.getWindowCount() initial', () => {
return app.getWindowCount();
});
test('app.getPath("appData")', () => app.getPath('appData'));
test('app.getPath("exe")', () => app.getPath('exe'));
test('app.getPath("module")', () => app.getPath('module'));
// ─── Launch App ────────────────────────────────────────────────
const gotLock = app.requestSingleInstanceLock();
if (!gotLock) {
app.quit();
@@ -16,6 +401,8 @@ if (!gotLock) {
});
app.whenReady().then(() => {
test('app.whenReady() resolved', () => true);
mainWindow = new BrowserWindow({
width: 900,
height: 680,
@@ -27,8 +414,65 @@ if (!gotLock) {
},
});
test('BrowserWindow created', () => mainWindow.id > 0);
test('BrowserWindow.getSize()', () => {
const [w, h] = mainWindow.getSize();
if (w < 100 || h < 100) throw new Error('Size too small: ' + w + 'x' + h);
return w + 'x' + h;
});
test('BrowserWindow.getTitle()', () => mainWindow.getTitle());
test('BrowserWindow.isVisible()', () => mainWindow.isVisible());
test('BrowserWindow.isDestroyed()', () => !mainWindow.isDestroyed());
test('BrowserWindow.isNormal()', () => mainWindow.isNormal());
test('BrowserWindow.isResizable()', () => mainWindow.isResizable());
test('BrowserWindow.getAllWindows().length', () => BrowserWindow.getAllWindows().length);
test('BrowserWindow.fromId(id)', () => {
const win = BrowserWindow.fromId(mainWindow.id);
return win ? win.id === mainWindow.id : false;
});
test('window-all-closed listener registered', () => {
app.on('window-all-closed', () => {
app.quit();
});
return true;
});
test('app.relaunch is a function', () => typeof app.relaunch === 'function');
test('app.exit is a function', () => typeof app.exit === 'function');
test('app.quit is a function', () => typeof app.quit === 'function');
test('app.getWindowCount() after create', () => app.getWindowCount());
test('app.getPathForProtocol()', () => {
const result = app.getPathForProtocol('https:');
return result === null ? 'null' : result;
});
test('app.getApplicationInfoForProtocol()', async () => {
const result = await app.getApplicationInfoForProtocol('https:');
return typeof result === 'object';
});
mainWindow.loadFile(path.join(__dirname, 'index.html'));
mainWindow.webContents.on('did-finish-load', () => {
const testResults = JSON.stringify(results);
mainWindow.webContents.executeJavaScript(
`window.__appTestResults = ${testResults}; renderAppTests();`
);
});
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});