Merge pull request #942 from Stremio/refactor/shell-init
Some checks are pending
Build / build (push) Waiting to run

refactor(Shell): remove init logic
This commit is contained in:
Tim 2025-06-21 01:24:42 +02:00 committed by GitHub
commit ab7fa8748a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 96 deletions

View file

@ -11,21 +11,6 @@ function Shell() {
const events = new EventEmitter();
function onTransportInit() {
active = true;
error = null;
starting = false;
onStateChanged();
}
function onTransportInitError(err) {
console.error(err);
active = false;
error = new Error(err);
starting = false;
onStateChanged();
transport = null;
}
function onStateChanged() {
events.emit('stateChanged');
}
@ -68,9 +53,22 @@ function Shell() {
active = false;
starting = true;
try {
transport = new ShellTransport();
transport.on('init', onTransportInit);
transport.on('init-error', onTransportInitError);
active = true;
error = null;
starting = false;
onStateChanged();
} catch (e) {
console.error(e);
active = false;
error = new Error(e);
starting = false;
onStateChanged();
transport = null;
}
onStateChanged();
};
this.stop = function() {

View file

@ -2,9 +2,6 @@
const EventEmitter = require('eventemitter3');
let shellAvailable = false;
const shellEvents = new EventEmitter();
const QtMsgTypes = {
signal: 1,
propertyUpdate: 2,
@ -19,27 +16,6 @@ const QtMsgTypes = {
};
const QtObjId = 'transport'; // the ID of our transport object
window.initShellComm = function () {
delete window.initShellComm;
shellEvents.emit('availabilityChanged');
};
const initialize = () => {
if(!window.qt) return Promise.reject('Qt API not found');
return new Promise((resolve) => {
function onShellAvailabilityChanged() {
shellEvents.off('availabilityChanged', onShellAvailabilityChanged);
shellAvailable = true;
resolve();
}
if (shellAvailable) {
onShellAvailabilityChanged();
} else {
shellEvents.on('availabilityChanged', onShellAvailabilityChanged);
}
});
};
function ShellTransport() {
const events = new EventEmitter();
@ -47,8 +23,6 @@ function ShellTransport() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const shell = this;
initialize()
.then(() => {
const transport = window.qt && window.qt.webChannelTransport;
if (!transport) throw 'no viable transport found (qt.webChannelTransport)';
@ -101,12 +75,8 @@ function ShellTransport() {
if (msg.object === QtObjId && msg.type === QtMsgTypes.signal)
events.emit(msg.args[0], msg.args[1]);
events.emit('init');
};
send({ type: QtMsgTypes.init });
}) .catch((error) => {
events.emit('init-error', error);
});
this.on = function(name, listener) {
events.on(name, listener);