@lvce-editor/update-worker 1.9.0 → 2.1.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.
@@ -841,6 +841,9 @@ const Electron = 2;
841
841
 
842
842
  const RendererWorker = 1;
843
843
 
844
+ const DownloadingUpdate = 2;
845
+ const DownloadedUpdate = 3;
846
+
844
847
  const rpcs = Object.create(null);
845
848
  const set$1 = (id, rpc) => {
846
849
  rpcs[id] = rpc;
@@ -909,8 +912,16 @@ const confirmPrompt = async message => {
909
912
  return result;
910
913
  };
911
914
 
915
+ const getParentPath = path => {
916
+ const slashIndex = path.lastIndexOf('/');
917
+ if (slashIndex === -1) {
918
+ return '';
919
+ }
920
+ return path.slice(0, slashIndex);
921
+ };
912
922
  const downloadToDisk = async (diskPath, response) => {
913
- // @ts-ignore
923
+ const parentPath = getParentPath(diskPath);
924
+ await invoke('FileSystem.mkdir', parentPath);
914
925
  const blob = await response.blob();
915
926
  // @ts-ignore
916
927
  await invoke('FileSystem.writeBlob', diskPath, blob);
@@ -979,9 +990,10 @@ const getBaseName = downloadUrl => {
979
990
  const lastSlashIndex = downloadUrl.lastIndexOf('/');
980
991
  return downloadUrl.slice(lastSlashIndex + 1);
981
992
  };
993
+
982
994
  const getDiskPath = async downloadUrl => {
983
995
  // @ts-ignore
984
- const cacheDir = await invoke('PlatformPaths.getCachePath');
996
+ const cacheDir = await invoke('PlatformPaths.getCacheUri');
985
997
  const baseName = getBaseName(downloadUrl);
986
998
  const diskPath = `${cacheDir}/auto-updater/${baseName}`;
987
999
  return diskPath;
@@ -1105,12 +1117,17 @@ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bu
1105
1117
 
1106
1118
  // @ts-ignore
1107
1119
  await invoke('Layout.setUpdateState', {
1108
- state: 'downloading',
1120
+ state: DownloadingUpdate,
1109
1121
  progress: 0
1110
1122
  });
1111
1123
  if (!(await isCached(downloadUrl, cache))) {
1112
1124
  await downloadUpdateToCache(downloadUrl, cache);
1113
1125
  }
1126
+ // @ts-ignore
1127
+ await invoke('Layout.setUpdateState', {
1128
+ state: DownloadedUpdate,
1129
+ progress: 1
1130
+ });
1114
1131
  const messageRestart = promptRestart();
1115
1132
  const shouldRestart = await confirmPrompt(messageRestart);
1116
1133
  if (!shouldRestart) {
@@ -1128,7 +1145,7 @@ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bu
1128
1145
  }
1129
1146
  const diskPath = await getDiskPath(downloadUrl);
1130
1147
  if (!(await existsFile(diskPath))) {
1131
- await downloadToDisk(downloadUrl, response);
1148
+ await downloadToDisk(diskPath, response);
1132
1149
  }
1133
1150
  await installAndRestart(diskPath);
1134
1151
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/update-worker",
3
- "version": "1.9.0",
3
+ "version": "2.1.0",
4
4
  "description": "Update Worker",
5
5
  "repository": {
6
6
  "type": "git",