2025-02-05 14:18:24 -05:00
|
|
|
import { IpcMainImpl } from '@electron/internal/browser/ipc-main-impl';
|
|
|
|
|
2025-01-31 12:40:19 -05:00
|
|
|
const { ServiceWorkerMain } = process._linkedBinding('electron_browser_service_worker_main');
|
|
|
|
|
2025-02-05 14:18:24 -05:00
|
|
|
Object.defineProperty(ServiceWorkerMain.prototype, 'ipc', {
|
|
|
|
get () {
|
|
|
|
const ipc = new IpcMainImpl();
|
|
|
|
Object.defineProperty(this, 'ipc', { value: ipc });
|
|
|
|
return ipc;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ServiceWorkerMain.prototype.send = function (channel, ...args) {
|
|
|
|
if (typeof channel !== 'string') {
|
|
|
|
throw new TypeError('Missing required channel argument');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return this._send(false /* internal */, channel, args);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error sending from ServiceWorkerMain: ', e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-01-31 12:40:19 -05:00
|
|
|
ServiceWorkerMain.prototype.startTask = function () {
|
|
|
|
// TODO(samuelmaddock): maybe make timeout configurable in the future
|
|
|
|
const hasTimeout = false;
|
|
|
|
const { id, ok } = this._startExternalRequest(hasTimeout);
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
throw new Error('Unable to start service worker task.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
end: () => this._finishExternalRequest(id)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ServiceWorkerMain;
|