@lvce-editor/update-worker 1.3.0 → 1.5.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 +36 -2
- package/package.json +1 -1
package/dist/updateWorkerMain.js
CHANGED
|
@@ -910,6 +910,13 @@ const confirmPrompt = async message => {
|
|
|
910
910
|
return true;
|
|
911
911
|
};
|
|
912
912
|
|
|
913
|
+
const downloadToDisk = async (diskPath, response) => {
|
|
914
|
+
// @ts-ignore
|
|
915
|
+
const blob = await response.blob();
|
|
916
|
+
// @ts-ignore
|
|
917
|
+
await invoke('FileSystem.writeBlob', diskPath, blob);
|
|
918
|
+
};
|
|
919
|
+
|
|
913
920
|
const downloadUpdate = async updateUrl => {
|
|
914
921
|
const response = await fetch(updateUrl, {
|
|
915
922
|
priority: 'low',
|
|
@@ -930,6 +937,11 @@ const downloadUpdateToCache = async (downloadUrl, cache) => {
|
|
|
930
937
|
await putInCache(downloadUrl, response, cache);
|
|
931
938
|
};
|
|
932
939
|
|
|
940
|
+
const existsFile = uri => {
|
|
941
|
+
// @ts-ignore
|
|
942
|
+
return invoke('FileSystem.exists', uri);
|
|
943
|
+
};
|
|
944
|
+
|
|
933
945
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
934
946
|
|
|
935
947
|
const cachedCaches = Object.create(null);
|
|
@@ -964,6 +976,18 @@ const getCache = (bucketName, cacheName) => {
|
|
|
964
976
|
return cachedCaches[cacheName];
|
|
965
977
|
};
|
|
966
978
|
|
|
979
|
+
const getBaseName = downloadUrl => {
|
|
980
|
+
const lastSlashIndex = downloadUrl.lastIndexOf('/');
|
|
981
|
+
return downloadUrl.slice(lastSlashIndex + 1);
|
|
982
|
+
};
|
|
983
|
+
const getDiskPath = async downloadUrl => {
|
|
984
|
+
// @ts-ignore
|
|
985
|
+
const cacheDir = await invoke('PlatformPaths.getCachePath');
|
|
986
|
+
const baseName = getBaseName(downloadUrl);
|
|
987
|
+
const diskPath = `${cacheDir}/${baseName}`;
|
|
988
|
+
return diskPath;
|
|
989
|
+
};
|
|
990
|
+
|
|
967
991
|
const parseVersionFromUrl = (url, repository) => {
|
|
968
992
|
if (!url.includes('releases/tag')) {
|
|
969
993
|
if (url.endsWith('/releases')) {
|
|
@@ -1086,8 +1110,18 @@ const checkForUpdates = async (updateSetting, repository) => {
|
|
|
1086
1110
|
error: undefined
|
|
1087
1111
|
};
|
|
1088
1112
|
}
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1113
|
+
const response = await cache.match(downloadUrl);
|
|
1114
|
+
if (!response) {
|
|
1115
|
+
return {
|
|
1116
|
+
updated: false,
|
|
1117
|
+
error: undefined
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
const diskPath = await getDiskPath(downloadUrl);
|
|
1121
|
+
if (!(await existsFile(diskPath))) {
|
|
1122
|
+
await downloadToDisk(downloadUrl, response);
|
|
1123
|
+
}
|
|
1124
|
+
await installAndRestart(diskPath);
|
|
1091
1125
|
return {
|
|
1092
1126
|
updated: true,
|
|
1093
1127
|
error: undefined
|