@lvce-editor/update-worker 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/updateWorkerMain.js +238 -192
- package/package.json +1 -1
package/dist/updateWorkerMain.js
CHANGED
|
@@ -182,8 +182,8 @@ const getModuleNotFoundError = stderr => {
|
|
|
182
182
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
183
183
|
const message = lines[messageIndex];
|
|
184
184
|
return {
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
186
|
+
message
|
|
187
187
|
};
|
|
188
188
|
};
|
|
189
189
|
const isModuleNotFoundError = stderr => {
|
|
@@ -206,14 +206,14 @@ const isUnhelpfulNativeModuleError = stderr => {
|
|
|
206
206
|
const getNativeModuleErrorMessage = stderr => {
|
|
207
207
|
const message = getMessageCodeBlock(stderr);
|
|
208
208
|
return {
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
210
|
+
message: `Incompatible native node module: ${message}`
|
|
211
211
|
};
|
|
212
212
|
};
|
|
213
213
|
const getModuleSyntaxError = () => {
|
|
214
214
|
return {
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
216
|
+
message: `ES Modules are not supported in electron`
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
219
|
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
@@ -232,8 +232,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
232
232
|
rest
|
|
233
233
|
} = getDetails(lines);
|
|
234
234
|
return {
|
|
235
|
-
message: actualMessage,
|
|
236
235
|
code: '',
|
|
236
|
+
message: actualMessage,
|
|
237
237
|
stack: rest
|
|
238
238
|
};
|
|
239
239
|
};
|
|
@@ -243,8 +243,8 @@ class IpcError extends VError {
|
|
|
243
243
|
if (stdout || stderr) {
|
|
244
244
|
// @ts-ignore
|
|
245
245
|
const {
|
|
246
|
-
message,
|
|
247
246
|
code,
|
|
247
|
+
message,
|
|
248
248
|
stack
|
|
249
249
|
} = getHelpfulChildProcessError(stdout, stderr);
|
|
250
250
|
const cause = new Error(message);
|
|
@@ -305,8 +305,8 @@ const wrap$f = global => {
|
|
|
305
305
|
};
|
|
306
306
|
const waitForFirstMessage = async port => {
|
|
307
307
|
const {
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
promise,
|
|
309
|
+
resolve
|
|
310
310
|
} = Promise.withResolvers();
|
|
311
311
|
port.addEventListener('message', resolve, {
|
|
312
312
|
once: true
|
|
@@ -326,8 +326,8 @@ const listen$6 = async () => {
|
|
|
326
326
|
const type = firstMessage.params[0];
|
|
327
327
|
if (type === 'message-port') {
|
|
328
328
|
parentIpc.send({
|
|
329
|
-
jsonrpc: '2.0',
|
|
330
329
|
id: firstMessage.id,
|
|
330
|
+
jsonrpc: '2.0',
|
|
331
331
|
result: null
|
|
332
332
|
});
|
|
333
333
|
parentIpc.dispose();
|
|
@@ -369,56 +369,35 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
369
369
|
wrap: wrap$e
|
|
370
370
|
};
|
|
371
371
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
372
|
+
class CommandNotFoundError extends Error {
|
|
373
|
+
constructor(command) {
|
|
374
|
+
super(`Command not found ${command}`);
|
|
375
|
+
this.name = 'CommandNotFoundError';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const commands = Object.create(null);
|
|
379
|
+
const register = commandMap => {
|
|
380
|
+
Object.assign(commands, commandMap);
|
|
379
381
|
};
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
callbacks[id] = fn;
|
|
382
|
+
const getCommand = key => {
|
|
383
|
+
return commands[key];
|
|
383
384
|
};
|
|
385
|
+
const execute = (command, ...args) => {
|
|
386
|
+
const fn = getCommand(command);
|
|
387
|
+
if (!fn) {
|
|
388
|
+
throw new CommandNotFoundError(command);
|
|
389
|
+
}
|
|
390
|
+
return fn(...args);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const Two$1 = '2.0';
|
|
394
|
+
const callbacks = Object.create(null);
|
|
384
395
|
const get$1 = id => {
|
|
385
396
|
return callbacks[id];
|
|
386
397
|
};
|
|
387
|
-
const remove = id => {
|
|
398
|
+
const remove$1 = id => {
|
|
388
399
|
delete callbacks[id];
|
|
389
400
|
};
|
|
390
|
-
let id = 0;
|
|
391
|
-
const create$3 = () => {
|
|
392
|
-
return ++id;
|
|
393
|
-
};
|
|
394
|
-
const registerPromise = () => {
|
|
395
|
-
const id = create$3();
|
|
396
|
-
const {
|
|
397
|
-
resolve,
|
|
398
|
-
promise
|
|
399
|
-
} = Promise.withResolvers();
|
|
400
|
-
set$2(id, resolve);
|
|
401
|
-
return {
|
|
402
|
-
id,
|
|
403
|
-
promise
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
const create$2 = (method, params) => {
|
|
407
|
-
const {
|
|
408
|
-
id,
|
|
409
|
-
promise
|
|
410
|
-
} = registerPromise();
|
|
411
|
-
const message = {
|
|
412
|
-
jsonrpc: Two,
|
|
413
|
-
method,
|
|
414
|
-
params,
|
|
415
|
-
id
|
|
416
|
-
};
|
|
417
|
-
return {
|
|
418
|
-
message,
|
|
419
|
-
promise
|
|
420
|
-
};
|
|
421
|
-
};
|
|
422
401
|
class JsonRpcError extends Error {
|
|
423
402
|
constructor(message) {
|
|
424
403
|
super(message);
|
|
@@ -435,12 +414,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
435
414
|
switch (type) {
|
|
436
415
|
case DomException:
|
|
437
416
|
return DOMException;
|
|
438
|
-
case TypeError$1:
|
|
439
|
-
return TypeError;
|
|
440
|
-
case SyntaxError$1:
|
|
441
|
-
return SyntaxError;
|
|
442
417
|
case ReferenceError$1:
|
|
443
418
|
return ReferenceError;
|
|
419
|
+
case SyntaxError$1:
|
|
420
|
+
return SyntaxError;
|
|
421
|
+
case TypeError$1:
|
|
422
|
+
return TypeError;
|
|
444
423
|
default:
|
|
445
424
|
return Error;
|
|
446
425
|
}
|
|
@@ -569,7 +548,7 @@ const resolve = (id, response) => {
|
|
|
569
548
|
return;
|
|
570
549
|
}
|
|
571
550
|
fn(response);
|
|
572
|
-
remove(id);
|
|
551
|
+
remove$1(id);
|
|
573
552
|
};
|
|
574
553
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
575
554
|
const getErrorType = prettyError => {
|
|
@@ -596,27 +575,27 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
596
575
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
597
576
|
return {
|
|
598
577
|
code: MethodNotFound,
|
|
599
|
-
|
|
600
|
-
|
|
578
|
+
data: error.stack,
|
|
579
|
+
message: error.message
|
|
601
580
|
};
|
|
602
581
|
}
|
|
603
582
|
return {
|
|
604
583
|
code: Custom,
|
|
605
|
-
message: prettyError.message,
|
|
606
584
|
data: {
|
|
607
|
-
stack: getStack(prettyError),
|
|
608
|
-
codeFrame: prettyError.codeFrame,
|
|
609
|
-
type: getErrorType(prettyError),
|
|
610
585
|
code: prettyError.code,
|
|
611
|
-
|
|
612
|
-
|
|
586
|
+
codeFrame: prettyError.codeFrame,
|
|
587
|
+
name: prettyError.name,
|
|
588
|
+
stack: getStack(prettyError),
|
|
589
|
+
type: getErrorType(prettyError)
|
|
590
|
+
},
|
|
591
|
+
message: prettyError.message
|
|
613
592
|
};
|
|
614
593
|
};
|
|
615
594
|
const create$1$1 = (id, error) => {
|
|
616
595
|
return {
|
|
617
|
-
|
|
596
|
+
error,
|
|
618
597
|
id,
|
|
619
|
-
|
|
598
|
+
jsonrpc: Two$1
|
|
620
599
|
};
|
|
621
600
|
};
|
|
622
601
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
@@ -627,8 +606,8 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
627
606
|
};
|
|
628
607
|
const create$5 = (message, result) => {
|
|
629
608
|
return {
|
|
630
|
-
jsonrpc: Two,
|
|
631
609
|
id: message.id,
|
|
610
|
+
jsonrpc: Two$1,
|
|
632
611
|
result: result ?? null
|
|
633
612
|
};
|
|
634
613
|
};
|
|
@@ -638,14 +617,14 @@ const getSuccessResponse = (message, result) => {
|
|
|
638
617
|
};
|
|
639
618
|
const getErrorResponseSimple = (id, error) => {
|
|
640
619
|
return {
|
|
641
|
-
jsonrpc: Two,
|
|
642
|
-
id,
|
|
643
620
|
error: {
|
|
644
621
|
code: Custom,
|
|
622
|
+
data: error,
|
|
645
623
|
// @ts-ignore
|
|
646
|
-
message: error.message
|
|
647
|
-
|
|
648
|
-
|
|
624
|
+
message: error.message
|
|
625
|
+
},
|
|
626
|
+
id,
|
|
627
|
+
jsonrpc: Two$1
|
|
649
628
|
};
|
|
650
629
|
};
|
|
651
630
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -675,35 +654,35 @@ const normalizeParams = args => {
|
|
|
675
654
|
if (args.length === 1) {
|
|
676
655
|
const options = args[0];
|
|
677
656
|
return {
|
|
657
|
+
execute: options.execute,
|
|
678
658
|
ipc: options.ipc,
|
|
659
|
+
logError: options.logError || defaultLogError,
|
|
679
660
|
message: options.message,
|
|
680
|
-
execute: options.execute,
|
|
681
|
-
resolve: options.resolve || defaultResolve,
|
|
682
661
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
683
|
-
|
|
684
|
-
|
|
662
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
663
|
+
resolve: options.resolve || defaultResolve
|
|
685
664
|
};
|
|
686
665
|
}
|
|
687
666
|
return {
|
|
667
|
+
execute: args[2],
|
|
688
668
|
ipc: args[0],
|
|
669
|
+
logError: args[5],
|
|
689
670
|
message: args[1],
|
|
690
|
-
execute: args[2],
|
|
691
|
-
resolve: args[3],
|
|
692
671
|
preparePrettyError: args[4],
|
|
693
|
-
|
|
694
|
-
|
|
672
|
+
requiresSocket: args[6],
|
|
673
|
+
resolve: args[3]
|
|
695
674
|
};
|
|
696
675
|
};
|
|
697
676
|
const handleJsonRpcMessage = async (...args) => {
|
|
698
677
|
const options = normalizeParams(args);
|
|
699
678
|
const {
|
|
700
|
-
message,
|
|
701
|
-
ipc,
|
|
702
679
|
execute,
|
|
703
|
-
|
|
704
|
-
preparePrettyError,
|
|
680
|
+
ipc,
|
|
705
681
|
logError,
|
|
706
|
-
|
|
682
|
+
message,
|
|
683
|
+
preparePrettyError,
|
|
684
|
+
requiresSocket,
|
|
685
|
+
resolve
|
|
707
686
|
} = options;
|
|
708
687
|
if ('id' in message) {
|
|
709
688
|
if ('method' in message) {
|
|
@@ -725,11 +704,51 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
725
704
|
}
|
|
726
705
|
throw new JsonRpcError('unexpected message');
|
|
727
706
|
};
|
|
728
|
-
|
|
707
|
+
|
|
708
|
+
const Two = '2.0';
|
|
709
|
+
|
|
710
|
+
const create$4 = (method, params) => {
|
|
711
|
+
return {
|
|
712
|
+
jsonrpc: Two,
|
|
713
|
+
method,
|
|
714
|
+
params
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
const create$3 = (id, method, params) => {
|
|
719
|
+
const message = {
|
|
720
|
+
id,
|
|
721
|
+
jsonrpc: Two,
|
|
722
|
+
method,
|
|
723
|
+
params
|
|
724
|
+
};
|
|
725
|
+
return message;
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
let id = 0;
|
|
729
|
+
const create$2 = () => {
|
|
730
|
+
return ++id;
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
const registerPromise = map => {
|
|
734
|
+
const id = create$2();
|
|
729
735
|
const {
|
|
730
|
-
|
|
736
|
+
promise,
|
|
737
|
+
resolve
|
|
738
|
+
} = Promise.withResolvers();
|
|
739
|
+
map[id] = resolve;
|
|
740
|
+
return {
|
|
741
|
+
id,
|
|
742
|
+
promise
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
747
|
+
const {
|
|
748
|
+
id,
|
|
731
749
|
promise
|
|
732
|
-
} =
|
|
750
|
+
} = registerPromise(callbacks);
|
|
751
|
+
const message = create$3(id, method, params);
|
|
733
752
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
734
753
|
ipc.sendAndTransfer(message);
|
|
735
754
|
} else {
|
|
@@ -738,60 +757,40 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
738
757
|
const responseMessage = await promise;
|
|
739
758
|
return unwrapJsonRpcResult(responseMessage);
|
|
740
759
|
};
|
|
741
|
-
const send = (transport, method, ...params) => {
|
|
742
|
-
const message = create$4(method, params);
|
|
743
|
-
transport.send(message);
|
|
744
|
-
};
|
|
745
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
746
|
-
return invokeHelper(ipc, method, params, false);
|
|
747
|
-
};
|
|
748
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
749
|
-
return invokeHelper(ipc, method, params, true);
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
class CommandNotFoundError extends Error {
|
|
753
|
-
constructor(command) {
|
|
754
|
-
super(`Command not found ${command}`);
|
|
755
|
-
this.name = 'CommandNotFoundError';
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
const commands = Object.create(null);
|
|
759
|
-
const register = commandMap => {
|
|
760
|
-
Object.assign(commands, commandMap);
|
|
761
|
-
};
|
|
762
|
-
const getCommand = key => {
|
|
763
|
-
return commands[key];
|
|
764
|
-
};
|
|
765
|
-
const execute = (command, ...args) => {
|
|
766
|
-
const fn = getCommand(command);
|
|
767
|
-
if (!fn) {
|
|
768
|
-
throw new CommandNotFoundError(command);
|
|
769
|
-
}
|
|
770
|
-
return fn(...args);
|
|
771
|
-
};
|
|
772
|
-
|
|
773
760
|
const createRpc = ipc => {
|
|
761
|
+
const callbacks = Object.create(null);
|
|
762
|
+
ipc._resolve = (id, response) => {
|
|
763
|
+
const fn = callbacks[id];
|
|
764
|
+
if (!fn) {
|
|
765
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
fn(response);
|
|
769
|
+
delete callbacks[id];
|
|
770
|
+
};
|
|
774
771
|
const rpc = {
|
|
772
|
+
async dispose() {
|
|
773
|
+
await ipc?.dispose();
|
|
774
|
+
},
|
|
775
|
+
invoke(method, ...params) {
|
|
776
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
777
|
+
},
|
|
778
|
+
invokeAndTransfer(method, ...params) {
|
|
779
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
780
|
+
},
|
|
775
781
|
// @ts-ignore
|
|
776
782
|
ipc,
|
|
777
783
|
/**
|
|
778
784
|
* @deprecated
|
|
779
785
|
*/
|
|
780
786
|
send(method, ...params) {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
invoke(method, ...params) {
|
|
784
|
-
return invoke$1(ipc, method, ...params);
|
|
785
|
-
},
|
|
786
|
-
invokeAndTransfer(method, ...params) {
|
|
787
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
788
|
-
},
|
|
789
|
-
async dispose() {
|
|
790
|
-
await ipc?.dispose();
|
|
787
|
+
const message = create$4(method, params);
|
|
788
|
+
ipc.send(message);
|
|
791
789
|
}
|
|
792
790
|
};
|
|
793
791
|
return rpc;
|
|
794
792
|
};
|
|
793
|
+
|
|
795
794
|
const requiresSocket = () => {
|
|
796
795
|
return false;
|
|
797
796
|
};
|
|
@@ -804,8 +803,9 @@ const logError = () => {
|
|
|
804
803
|
const handleMessage = event => {
|
|
805
804
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
806
805
|
const actualExecute = event?.target?.execute || execute;
|
|
807
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
806
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
808
807
|
};
|
|
808
|
+
|
|
809
809
|
const handleIpc = ipc => {
|
|
810
810
|
if ('addEventListener' in ipc) {
|
|
811
811
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -814,6 +814,7 @@ const handleIpc = ipc => {
|
|
|
814
814
|
ipc.on('message', handleMessage);
|
|
815
815
|
}
|
|
816
816
|
};
|
|
817
|
+
|
|
817
818
|
const listen$1 = async (module, options) => {
|
|
818
819
|
const rawIpc = await module.listen(options);
|
|
819
820
|
if (module.signal) {
|
|
@@ -822,6 +823,7 @@ const listen$1 = async (module, options) => {
|
|
|
822
823
|
const ipc = module.wrap(rawIpc);
|
|
823
824
|
return ipc;
|
|
824
825
|
};
|
|
826
|
+
|
|
825
827
|
const create$1 = async ({
|
|
826
828
|
commandMap
|
|
827
829
|
}) => {
|
|
@@ -832,17 +834,26 @@ const create$1 = async ({
|
|
|
832
834
|
const rpc = createRpc(ipc);
|
|
833
835
|
return rpc;
|
|
834
836
|
};
|
|
835
|
-
const WebWorkerRpcClient = {
|
|
836
|
-
__proto__: null,
|
|
837
|
-
create: create$1
|
|
838
|
-
};
|
|
839
|
-
|
|
840
|
-
const Electron = 2;
|
|
841
837
|
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const
|
|
838
|
+
const createMockRpc = ({
|
|
839
|
+
commandMap
|
|
840
|
+
}) => {
|
|
841
|
+
const invocations = [];
|
|
842
|
+
const invoke = (method, ...params) => {
|
|
843
|
+
invocations.push([method, ...params]);
|
|
844
|
+
const command = commandMap[method];
|
|
845
|
+
if (!command) {
|
|
846
|
+
throw new Error(`command ${method} not found`);
|
|
847
|
+
}
|
|
848
|
+
return command(...params);
|
|
849
|
+
};
|
|
850
|
+
const mockRpc = {
|
|
851
|
+
invocations,
|
|
852
|
+
invoke,
|
|
853
|
+
invokeAndTransfer: invoke
|
|
854
|
+
};
|
|
855
|
+
return mockRpc;
|
|
856
|
+
};
|
|
846
857
|
|
|
847
858
|
const rpcs = Object.create(null);
|
|
848
859
|
const set$1 = (id, rpc) => {
|
|
@@ -851,9 +862,17 @@ const set$1 = (id, rpc) => {
|
|
|
851
862
|
const get = id => {
|
|
852
863
|
return rpcs[id];
|
|
853
864
|
};
|
|
865
|
+
const remove = id => {
|
|
866
|
+
delete rpcs[id];
|
|
867
|
+
};
|
|
854
868
|
|
|
869
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
855
870
|
const create = rpcId => {
|
|
856
871
|
return {
|
|
872
|
+
async dispose() {
|
|
873
|
+
const rpc = get(rpcId);
|
|
874
|
+
await rpc.dispose();
|
|
875
|
+
},
|
|
857
876
|
// @ts-ignore
|
|
858
877
|
invoke(method, ...params) {
|
|
859
878
|
const rpc = get(rpcId);
|
|
@@ -866,19 +885,35 @@ const create = rpcId => {
|
|
|
866
885
|
// @ts-ignore
|
|
867
886
|
return rpc.invokeAndTransfer(method, ...params);
|
|
868
887
|
},
|
|
888
|
+
registerMockRpc(commandMap) {
|
|
889
|
+
const mockRpc = createMockRpc({
|
|
890
|
+
commandMap
|
|
891
|
+
});
|
|
892
|
+
set$1(rpcId, mockRpc);
|
|
893
|
+
// @ts-ignore
|
|
894
|
+
mockRpc[Symbol.dispose] = () => {
|
|
895
|
+
remove(rpcId);
|
|
896
|
+
};
|
|
897
|
+
// @ts-ignore
|
|
898
|
+
return mockRpc;
|
|
899
|
+
},
|
|
869
900
|
set(rpc) {
|
|
870
901
|
set$1(rpcId, rpc);
|
|
871
|
-
},
|
|
872
|
-
async dispose() {
|
|
873
|
-
const rpc = get(rpcId);
|
|
874
|
-
await rpc.dispose();
|
|
875
902
|
}
|
|
876
903
|
};
|
|
877
904
|
};
|
|
878
905
|
|
|
906
|
+
const Electron = 2;
|
|
907
|
+
|
|
908
|
+
const RendererWorker = 1;
|
|
909
|
+
|
|
910
|
+
const DownloadingUpdate = 2;
|
|
911
|
+
const DownloadedUpdate = 3;
|
|
912
|
+
|
|
879
913
|
const {
|
|
880
914
|
invoke,
|
|
881
|
-
set
|
|
915
|
+
set
|
|
916
|
+
} = create(RendererWorker);
|
|
882
917
|
|
|
883
918
|
const emptyObject = {};
|
|
884
919
|
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
@@ -929,8 +964,7 @@ const downloadToDisk = async (diskPath, response) => {
|
|
|
929
964
|
|
|
930
965
|
const downloadUpdate = async updateUrl => {
|
|
931
966
|
const response = await fetch(updateUrl, {
|
|
932
|
-
priority: 'low'
|
|
933
|
-
redirect: 'follow'
|
|
967
|
+
priority: 'low'
|
|
934
968
|
});
|
|
935
969
|
if (!response.ok) {
|
|
936
970
|
throw new Error(response.statusText);
|
|
@@ -938,8 +972,24 @@ const downloadUpdate = async updateUrl => {
|
|
|
938
972
|
return response;
|
|
939
973
|
};
|
|
940
974
|
|
|
975
|
+
const isLowDiskSpaceError = error => {
|
|
976
|
+
return error instanceof DOMException && error.name === 'NetworkError';
|
|
977
|
+
};
|
|
941
978
|
const putInCache = async (url, response, cache) => {
|
|
942
|
-
|
|
979
|
+
try {
|
|
980
|
+
await cache.put(url, response);
|
|
981
|
+
} catch (error) {
|
|
982
|
+
// Gracefully handle cache errors (e.g., low disk space)
|
|
983
|
+
// Don't block the update process if caching fails
|
|
984
|
+
if (isLowDiskSpaceError(error)) {
|
|
985
|
+
// Silently ignore network errors when putting to cache
|
|
986
|
+
// This can happen when disk space is low
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
// For other errors, also ignore to not block the update process
|
|
990
|
+
// but log them for debugging purposes
|
|
991
|
+
console.warn('Failed to put response in cache:', error);
|
|
992
|
+
}
|
|
943
993
|
};
|
|
944
994
|
|
|
945
995
|
const downloadUpdateToCache = async (downloadUrl, cache) => {
|
|
@@ -972,9 +1022,8 @@ const getCacheInternal = async (bucketName, cacheName) => {
|
|
|
972
1022
|
const twoWeeks = 14 * 24 * 60 * 60 * 1000;
|
|
973
1023
|
// @ts-ignore
|
|
974
1024
|
const bucket = await navigator.storageBuckets.open(bucketName, {
|
|
975
|
-
|
|
976
|
-
// 1 GB
|
|
977
|
-
expires: Date.now() + twoWeeks
|
|
1025
|
+
expires: Date.now() + twoWeeks,
|
|
1026
|
+
quota: 1000 * 1024 * 1024 // 1 GB
|
|
978
1027
|
});
|
|
979
1028
|
const cache = await bucket.caches.open(cacheName);
|
|
980
1029
|
return cache;
|
|
@@ -1030,7 +1079,7 @@ const getLatestReleaseVersion = async repository => {
|
|
|
1030
1079
|
};
|
|
1031
1080
|
|
|
1032
1081
|
const getUpdateUrl = (repository, fileNameTemplate, version) => {
|
|
1033
|
-
const fileName = fileNameTemplate.replace('${version}', version);
|
|
1082
|
+
const fileName = fileNameTemplate.replace('${version}', () => version);
|
|
1034
1083
|
const url = `https://github.com/${repository}/releases/download/v${version}/${fileName}`;
|
|
1035
1084
|
return url;
|
|
1036
1085
|
};
|
|
@@ -1040,42 +1089,39 @@ const exec = async (path, args, options) => {
|
|
|
1040
1089
|
await invoke('Exec.exec', path, args, options);
|
|
1041
1090
|
// TODO
|
|
1042
1091
|
return {
|
|
1043
|
-
|
|
1044
|
-
|
|
1092
|
+
event: {},
|
|
1093
|
+
type: 0
|
|
1045
1094
|
};
|
|
1046
1095
|
};
|
|
1047
1096
|
|
|
1048
1097
|
const Error$1 = 2;
|
|
1049
1098
|
|
|
1050
|
-
const
|
|
1099
|
+
const getNSISUpdateArgs = () => {
|
|
1051
1100
|
const args = ['--updated', '/S', '--force-run'];
|
|
1052
1101
|
return args;
|
|
1053
1102
|
};
|
|
1054
1103
|
|
|
1055
1104
|
const installAndRestart = async downloadPath => {
|
|
1056
1105
|
try {
|
|
1057
|
-
const args =
|
|
1106
|
+
const args = getNSISUpdateArgs();
|
|
1058
1107
|
const {
|
|
1059
|
-
|
|
1060
|
-
|
|
1108
|
+
event,
|
|
1109
|
+
type
|
|
1061
1110
|
} = await exec(downloadPath, args, {
|
|
1062
|
-
|
|
1063
|
-
|
|
1111
|
+
detached: true,
|
|
1112
|
+
stdio: 'inherit'
|
|
1064
1113
|
});
|
|
1065
1114
|
if (type === Error$1) {
|
|
1066
1115
|
throw new Error(`Child process error: ${event}`);
|
|
1067
1116
|
}
|
|
1068
1117
|
} catch (error) {
|
|
1069
|
-
throw new VError(error, `Failed to install
|
|
1118
|
+
throw new VError(error, `Failed to install NSIS update`);
|
|
1070
1119
|
}
|
|
1071
1120
|
};
|
|
1072
1121
|
|
|
1073
1122
|
const isCached = async (url, cache) => {
|
|
1074
1123
|
const match = await cache.match(url);
|
|
1075
|
-
|
|
1076
|
-
return true;
|
|
1077
|
-
}
|
|
1078
|
-
return false;
|
|
1124
|
+
return !!match;
|
|
1079
1125
|
};
|
|
1080
1126
|
|
|
1081
1127
|
const isOnline = () => {
|
|
@@ -1095,52 +1141,52 @@ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bu
|
|
|
1095
1141
|
try {
|
|
1096
1142
|
if (!isOnline()) {
|
|
1097
1143
|
return {
|
|
1098
|
-
|
|
1099
|
-
|
|
1144
|
+
error: undefined,
|
|
1145
|
+
updated: false
|
|
1100
1146
|
};
|
|
1101
1147
|
}
|
|
1102
1148
|
const info = await getLatestReleaseVersion(repository);
|
|
1103
1149
|
if (!info || !info.version) {
|
|
1104
1150
|
return {
|
|
1105
|
-
|
|
1106
|
-
|
|
1151
|
+
error: undefined,
|
|
1152
|
+
updated: false
|
|
1107
1153
|
};
|
|
1108
1154
|
}
|
|
1109
1155
|
const cache = await getCache(bucketName, cacheName);
|
|
1110
1156
|
if (!(await shouldUpdate(updateSetting, info.version))) {
|
|
1111
1157
|
return {
|
|
1112
|
-
|
|
1113
|
-
|
|
1158
|
+
error: undefined,
|
|
1159
|
+
updated: false
|
|
1114
1160
|
};
|
|
1115
1161
|
}
|
|
1116
1162
|
const downloadUrl = getUpdateUrl(repository, fileNameTemplate, info.version);
|
|
1117
1163
|
|
|
1118
1164
|
// @ts-ignore
|
|
1119
1165
|
await invoke('Layout.setUpdateState', {
|
|
1120
|
-
|
|
1121
|
-
|
|
1166
|
+
progress: 0,
|
|
1167
|
+
state: DownloadingUpdate
|
|
1122
1168
|
});
|
|
1123
1169
|
if (!(await isCached(downloadUrl, cache))) {
|
|
1124
1170
|
await downloadUpdateToCache(downloadUrl, cache);
|
|
1125
1171
|
}
|
|
1126
1172
|
// @ts-ignore
|
|
1127
1173
|
await invoke('Layout.setUpdateState', {
|
|
1128
|
-
|
|
1129
|
-
|
|
1174
|
+
progress: 1,
|
|
1175
|
+
state: DownloadedUpdate
|
|
1130
1176
|
});
|
|
1131
1177
|
const messageRestart = promptRestart();
|
|
1132
1178
|
const shouldRestart = await confirmPrompt(messageRestart);
|
|
1133
1179
|
if (!shouldRestart) {
|
|
1134
1180
|
return {
|
|
1135
|
-
|
|
1136
|
-
|
|
1181
|
+
error: undefined,
|
|
1182
|
+
updated: false
|
|
1137
1183
|
};
|
|
1138
1184
|
}
|
|
1139
1185
|
const response = await cache.match(downloadUrl);
|
|
1140
1186
|
if (!response) {
|
|
1141
1187
|
return {
|
|
1142
|
-
|
|
1143
|
-
|
|
1188
|
+
error: undefined,
|
|
1189
|
+
updated: false
|
|
1144
1190
|
};
|
|
1145
1191
|
}
|
|
1146
1192
|
const diskPath = await getDiskPath(downloadUrl);
|
|
@@ -1149,14 +1195,14 @@ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bu
|
|
|
1149
1195
|
}
|
|
1150
1196
|
await installAndRestart(diskPath);
|
|
1151
1197
|
return {
|
|
1152
|
-
|
|
1153
|
-
|
|
1198
|
+
error: undefined,
|
|
1199
|
+
updated: true
|
|
1154
1200
|
};
|
|
1155
1201
|
} catch (error) {
|
|
1156
1202
|
console.error(error);
|
|
1157
1203
|
return {
|
|
1158
|
-
|
|
1159
|
-
|
|
1204
|
+
error: undefined,
|
|
1205
|
+
updated: false
|
|
1160
1206
|
};
|
|
1161
1207
|
}
|
|
1162
1208
|
};
|
|
@@ -1176,8 +1222,8 @@ const checkForUpdates = async (updateSetting, repository) => {
|
|
|
1176
1222
|
const result = await requestLock(lockName, async lock => {
|
|
1177
1223
|
if (!lock) {
|
|
1178
1224
|
return {
|
|
1179
|
-
|
|
1180
|
-
|
|
1225
|
+
error: undefined,
|
|
1226
|
+
updated: false
|
|
1181
1227
|
};
|
|
1182
1228
|
}
|
|
1183
1229
|
const result = await doCheckForUpdates(updateSetting, repository, fileNameTemplate, bucketName, cacheName);
|
|
@@ -1187,12 +1233,12 @@ const checkForUpdates = async (updateSetting, repository) => {
|
|
|
1187
1233
|
};
|
|
1188
1234
|
|
|
1189
1235
|
const commandMap = {
|
|
1190
|
-
'Update.
|
|
1191
|
-
'Update.
|
|
1236
|
+
'Update.checkForUpdates': checkForUpdates,
|
|
1237
|
+
'Update.downloadToCache': downloadUpdateToCache
|
|
1192
1238
|
};
|
|
1193
1239
|
|
|
1194
1240
|
const listen = async () => {
|
|
1195
|
-
const rpc = await
|
|
1241
|
+
const rpc = await create$1({
|
|
1196
1242
|
commandMap: commandMap
|
|
1197
1243
|
});
|
|
1198
1244
|
set(rpc);
|