@lvce-editor/update-worker 1.4.0 → 1.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.
@@ -837,6 +837,8 @@ const WebWorkerRpcClient = {
837
837
  create: create$1
838
838
  };
839
839
 
840
+ const Electron = 2;
841
+
840
842
  const RendererWorker = 1;
841
843
 
842
844
  const rpcs = Object.create(null);
@@ -903,26 +905,19 @@ const promptRestart = () => {
903
905
  return i18nString(UiStrings.DoYouWantToRestart);
904
906
  };
905
907
 
906
- // TODO avoid js prompt in elctron, since it crashes electron
907
-
908
908
  const confirmPrompt = async message => {
909
- // TODO
910
- return true;
909
+ const result = await invoke('ConfirmPrompt.prompt', message, {
910
+ // @ts-ignore
911
+ platform: Electron
912
+ });
913
+ return result;
911
914
  };
912
915
 
913
- const getBaseName = downloadUrl => {
914
- const lastSlashIndex = downloadUrl.lastIndexOf('/');
915
- return downloadUrl.slice(lastSlashIndex + 1);
916
- };
917
- const downloadToDisk = async (downloadUrl, response) => {
916
+ const downloadToDisk = async (diskPath, response) => {
918
917
  // @ts-ignore
919
- const cacheDir = await invoke('PlatformPaths.getCacheDir');
920
- const baseName = getBaseName(downloadUrl);
921
- const diskPath = `${cacheDir}/${baseName}`;
922
918
  const blob = await response.blob();
923
919
  // @ts-ignore
924
920
  await invoke('FileSystem.writeBlob', diskPath, blob);
925
- return diskPath;
926
921
  };
927
922
 
928
923
  const downloadUpdate = async updateUrl => {
@@ -945,6 +940,11 @@ const downloadUpdateToCache = async (downloadUrl, cache) => {
945
940
  await putInCache(downloadUrl, response, cache);
946
941
  };
947
942
 
943
+ const existsFile = uri => {
944
+ // @ts-ignore
945
+ return invoke('FileSystem.exists', uri);
946
+ };
947
+
948
948
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
949
949
 
950
950
  const cachedCaches = Object.create(null);
@@ -979,6 +979,18 @@ const getCache = (bucketName, cacheName) => {
979
979
  return cachedCaches[cacheName];
980
980
  };
981
981
 
982
+ const getBaseName = downloadUrl => {
983
+ const lastSlashIndex = downloadUrl.lastIndexOf('/');
984
+ return downloadUrl.slice(lastSlashIndex + 1);
985
+ };
986
+ const getDiskPath = async downloadUrl => {
987
+ // @ts-ignore
988
+ const cacheDir = await invoke('PlatformPaths.getCachePath');
989
+ const baseName = getBaseName(downloadUrl);
990
+ const diskPath = `${cacheDir}/auto-updater/${baseName}`;
991
+ return diskPath;
992
+ };
993
+
982
994
  const parseVersionFromUrl = (url, repository) => {
983
995
  if (!url.includes('releases/tag')) {
984
996
  if (url.endsWith('/releases')) {
@@ -1016,6 +1028,8 @@ const getUpdateUrl = (repository, version) => {
1016
1028
  };
1017
1029
 
1018
1030
  const exec = async (path, args, options) => {
1031
+ // @ts-ignore
1032
+ await invoke('Exec.exec', path, args, options);
1019
1033
  // TODO
1020
1034
  return {
1021
1035
  type: 0,
@@ -1060,8 +1074,8 @@ const shouldUpdate = async (updateSetting, version) => {
1060
1074
  if (updateSetting && updateSetting !== 'none') {
1061
1075
  return true;
1062
1076
  }
1063
- promptMessage(version);
1064
- const shouldUpdate = await confirmPrompt();
1077
+ const message = promptMessage(version);
1078
+ const shouldUpdate = await confirmPrompt(message);
1065
1079
  return shouldUpdate;
1066
1080
  };
1067
1081
 
@@ -1108,7 +1122,10 @@ const checkForUpdates = async (updateSetting, repository) => {
1108
1122
  error: undefined
1109
1123
  };
1110
1124
  }
1111
- const diskPath = await downloadToDisk(downloadUrl, response);
1125
+ const diskPath = await getDiskPath(downloadUrl);
1126
+ if (!(await existsFile(diskPath))) {
1127
+ await downloadToDisk(downloadUrl, response);
1128
+ }
1112
1129
  await installAndRestart(diskPath);
1113
1130
  return {
1114
1131
  updated: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/update-worker",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Update Worker",
5
5
  "repository": {
6
6
  "type": "git",