mirror of
https://github.com/mileswolfallen2/gelectron.git
synced 2026-12-05 08:20:40 +00:00
- 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.
34 lines
768 B
JavaScript
34 lines
768 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Gelectron - contextBridge module (Electron compatible)
|
|
*/
|
|
|
|
const contextBridge = {
|
|
exposeInMainWorld(key, api) {
|
|
if (typeof globalThis.window === 'undefined') {
|
|
return;
|
|
}
|
|
|
|
// Create a frozen copy of the API
|
|
const safeApi = deepFreeze(JSON.parse(JSON.stringify(api)));
|
|
|
|
globalThis.window[key] = safeApi;
|
|
|
|
console.log(`[gelectron] contextBridge: exposed '${key}' to main world`);
|
|
},
|
|
};
|
|
|
|
function deepFreeze(obj) {
|
|
if (typeof obj !== 'object' || obj === null) return obj;
|
|
Object.freeze(obj);
|
|
Object.keys(obj).forEach((key) => {
|
|
if (typeof obj[key] === 'object' && obj[key] !== null && !Object.isFrozen(obj[key])) {
|
|
deepFreeze(obj[key]);
|
|
}
|
|
});
|
|
return obj;
|
|
}
|
|
|
|
module.exports = contextBridge;
|