@lvce-editor/update-worker 2.4.0 → 2.6.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 +236 -189
- 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;
|
|
@@ -938,8 +973,24 @@ const downloadUpdate = async updateUrl => {
|
|
|
938
973
|
return response;
|
|
939
974
|
};
|
|
940
975
|
|
|
976
|
+
const isLowDiskSpaceError = error => {
|
|
977
|
+
return error instanceof DOMException && error.name === 'NetworkError';
|
|
978
|
+
};
|
|
941
979
|
const putInCache = async (url, response, cache) => {
|
|
942
|
-
|
|
980
|
+
try {
|
|
981
|
+
await cache.put(url, response);
|
|
982
|
+
} catch (error) {
|
|
983
|
+
// Gracefully handle cache errors (e.g., low disk space)
|
|
984
|
+
// Don't block the update process if caching fails
|
|
985
|
+
if (isLowDiskSpaceError(error)) {
|
|
986
|
+
// Silently ignore network errors when putting to cache
|
|
987
|
+
// This can happen when disk space is low
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
// For other errors, also ignore to not block the update process
|
|
991
|
+
// but log them for debugging purposes
|
|
992
|
+
console.warn('Failed to put response in cache:', error);
|
|
993
|
+
}
|
|
943
994
|
};
|
|
944
995
|
|
|
945
996
|
const downloadUpdateToCache = async (downloadUrl, cache) => {
|
|
@@ -972,9 +1023,8 @@ const getCacheInternal = async (bucketName, cacheName) => {
|
|
|
972
1023
|
const twoWeeks = 14 * 24 * 60 * 60 * 1000;
|
|
973
1024
|
// @ts-ignore
|
|
974
1025
|
const bucket = await navigator.storageBuckets.open(bucketName, {
|
|
975
|
-
|
|
976
|
-
// 1 GB
|
|
977
|
-
expires: Date.now() + twoWeeks
|
|
1026
|
+
expires: Date.now() + twoWeeks,
|
|
1027
|
+
quota: 1000 * 1024 * 1024 // 1 GB
|
|
978
1028
|
});
|
|
979
1029
|
const cache = await bucket.caches.open(cacheName);
|
|
980
1030
|
return cache;
|
|
@@ -1040,42 +1090,39 @@ const exec = async (path, args, options) => {
|
|
|
1040
1090
|
await invoke('Exec.exec', path, args, options);
|
|
1041
1091
|
// TODO
|
|
1042
1092
|
return {
|
|
1043
|
-
|
|
1044
|
-
|
|
1093
|
+
event: {},
|
|
1094
|
+
type: 0
|
|
1045
1095
|
};
|
|
1046
1096
|
};
|
|
1047
1097
|
|
|
1048
1098
|
const Error$1 = 2;
|
|
1049
1099
|
|
|
1050
|
-
const
|
|
1100
|
+
const getNSISUpdateArgs = () => {
|
|
1051
1101
|
const args = ['--updated', '/S', '--force-run'];
|
|
1052
1102
|
return args;
|
|
1053
1103
|
};
|
|
1054
1104
|
|
|
1055
1105
|
const installAndRestart = async downloadPath => {
|
|
1056
1106
|
try {
|
|
1057
|
-
const args =
|
|
1107
|
+
const args = getNSISUpdateArgs();
|
|
1058
1108
|
const {
|
|
1059
|
-
|
|
1060
|
-
|
|
1109
|
+
event,
|
|
1110
|
+
type
|
|
1061
1111
|
} = await exec(downloadPath, args, {
|
|
1062
|
-
|
|
1063
|
-
|
|
1112
|
+
detached: true,
|
|
1113
|
+
stdio: 'inherit'
|
|
1064
1114
|
});
|
|
1065
1115
|
if (type === Error$1) {
|
|
1066
1116
|
throw new Error(`Child process error: ${event}`);
|
|
1067
1117
|
}
|
|
1068
1118
|
} catch (error) {
|
|
1069
|
-
throw new VError(error, `Failed to install
|
|
1119
|
+
throw new VError(error, `Failed to install NSIS update`);
|
|
1070
1120
|
}
|
|
1071
1121
|
};
|
|
1072
1122
|
|
|
1073
1123
|
const isCached = async (url, cache) => {
|
|
1074
1124
|
const match = await cache.match(url);
|
|
1075
|
-
|
|
1076
|
-
return true;
|
|
1077
|
-
}
|
|
1078
|
-
return false;
|
|
1125
|
+
return !!match;
|
|
1079
1126
|
};
|
|
1080
1127
|
|
|
1081
1128
|
const isOnline = () => {
|
|
@@ -1095,52 +1142,52 @@ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bu
|
|
|
1095
1142
|
try {
|
|
1096
1143
|
if (!isOnline()) {
|
|
1097
1144
|
return {
|
|
1098
|
-
|
|
1099
|
-
|
|
1145
|
+
error: undefined,
|
|
1146
|
+
updated: false
|
|
1100
1147
|
};
|
|
1101
1148
|
}
|
|
1102
1149
|
const info = await getLatestReleaseVersion(repository);
|
|
1103
1150
|
if (!info || !info.version) {
|
|
1104
1151
|
return {
|
|
1105
|
-
|
|
1106
|
-
|
|
1152
|
+
error: undefined,
|
|
1153
|
+
updated: false
|
|
1107
1154
|
};
|
|
1108
1155
|
}
|
|
1109
1156
|
const cache = await getCache(bucketName, cacheName);
|
|
1110
1157
|
if (!(await shouldUpdate(updateSetting, info.version))) {
|
|
1111
1158
|
return {
|
|
1112
|
-
|
|
1113
|
-
|
|
1159
|
+
error: undefined,
|
|
1160
|
+
updated: false
|
|
1114
1161
|
};
|
|
1115
1162
|
}
|
|
1116
1163
|
const downloadUrl = getUpdateUrl(repository, fileNameTemplate, info.version);
|
|
1117
1164
|
|
|
1118
1165
|
// @ts-ignore
|
|
1119
1166
|
await invoke('Layout.setUpdateState', {
|
|
1120
|
-
|
|
1121
|
-
|
|
1167
|
+
progress: 0,
|
|
1168
|
+
state: DownloadingUpdate
|
|
1122
1169
|
});
|
|
1123
1170
|
if (!(await isCached(downloadUrl, cache))) {
|
|
1124
1171
|
await downloadUpdateToCache(downloadUrl, cache);
|
|
1125
1172
|
}
|
|
1126
1173
|
// @ts-ignore
|
|
1127
1174
|
await invoke('Layout.setUpdateState', {
|
|
1128
|
-
|
|
1129
|
-
|
|
1175
|
+
progress: 1,
|
|
1176
|
+
state: DownloadedUpdate
|
|
1130
1177
|
});
|
|
1131
1178
|
const messageRestart = promptRestart();
|
|
1132
1179
|
const shouldRestart = await confirmPrompt(messageRestart);
|
|
1133
1180
|
if (!shouldRestart) {
|
|
1134
1181
|
return {
|
|
1135
|
-
|
|
1136
|
-
|
|
1182
|
+
error: undefined,
|
|
1183
|
+
updated: false
|
|
1137
1184
|
};
|
|
1138
1185
|
}
|
|
1139
1186
|
const response = await cache.match(downloadUrl);
|
|
1140
1187
|
if (!response) {
|
|
1141
1188
|
return {
|
|
1142
|
-
|
|
1143
|
-
|
|
1189
|
+
error: undefined,
|
|
1190
|
+
updated: false
|
|
1144
1191
|
};
|
|
1145
1192
|
}
|
|
1146
1193
|
const diskPath = await getDiskPath(downloadUrl);
|
|
@@ -1149,14 +1196,14 @@ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bu
|
|
|
1149
1196
|
}
|
|
1150
1197
|
await installAndRestart(diskPath);
|
|
1151
1198
|
return {
|
|
1152
|
-
|
|
1153
|
-
|
|
1199
|
+
error: undefined,
|
|
1200
|
+
updated: true
|
|
1154
1201
|
};
|
|
1155
1202
|
} catch (error) {
|
|
1156
1203
|
console.error(error);
|
|
1157
1204
|
return {
|
|
1158
|
-
|
|
1159
|
-
|
|
1205
|
+
error: undefined,
|
|
1206
|
+
updated: false
|
|
1160
1207
|
};
|
|
1161
1208
|
}
|
|
1162
1209
|
};
|
|
@@ -1176,8 +1223,8 @@ const checkForUpdates = async (updateSetting, repository) => {
|
|
|
1176
1223
|
const result = await requestLock(lockName, async lock => {
|
|
1177
1224
|
if (!lock) {
|
|
1178
1225
|
return {
|
|
1179
|
-
|
|
1180
|
-
|
|
1226
|
+
error: undefined,
|
|
1227
|
+
updated: false
|
|
1181
1228
|
};
|
|
1182
1229
|
}
|
|
1183
1230
|
const result = await doCheckForUpdates(updateSetting, repository, fileNameTemplate, bucketName, cacheName);
|
|
@@ -1187,12 +1234,12 @@ const checkForUpdates = async (updateSetting, repository) => {
|
|
|
1187
1234
|
};
|
|
1188
1235
|
|
|
1189
1236
|
const commandMap = {
|
|
1190
|
-
'Update.
|
|
1191
|
-
'Update.
|
|
1237
|
+
'Update.checkForUpdates': checkForUpdates,
|
|
1238
|
+
'Update.downloadToCache': downloadUpdateToCache
|
|
1192
1239
|
};
|
|
1193
1240
|
|
|
1194
1241
|
const listen = async () => {
|
|
1195
|
-
const rpc = await
|
|
1242
|
+
const rpc = await create$1({
|
|
1196
1243
|
commandMap: commandMap
|
|
1197
1244
|
});
|
|
1198
1245
|
set(rpc);
|