@lvce-editor/update-worker 1.8.0 → 2.0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Update Worker
2
2
 
3
- Webworker for the menu functionality in LVCE Editor.
3
+ Webworker for the update functionality in LVCE Editor.
4
4
 
5
5
  ## Contributing
6
6
 
@@ -889,20 +889,16 @@ const i18nString = (key, placeholders = emptyObject) => {
889
889
  return key.replaceAll(RE_PLACEHOLDER, replacer);
890
890
  };
891
891
 
892
- /**
893
- * @enum {string}
894
- */
895
- const UiStrings = {
896
- DoYouWantToUpdate: 'Do you want to update to version {PH1}?',
897
- DoYouWantToRestart: 'The Update has been downloaded. Do you want to restart now?'
898
- };
892
+ const DoYouWantToUpdate = 'Do you want to update to version {PH1}?';
893
+ const DoYouWantToRestart = 'The Update has been downloaded. Do you want to restart now?';
894
+
899
895
  const promptMessage = version => {
900
- return i18nString(UiStrings.DoYouWantToUpdate, {
896
+ return i18nString(DoYouWantToUpdate, {
901
897
  PH1: version
902
898
  });
903
899
  };
904
900
  const promptRestart = () => {
905
- return i18nString(UiStrings.DoYouWantToRestart);
901
+ return i18nString(DoYouWantToRestart);
906
902
  };
907
903
 
908
904
  const confirmPrompt = async message => {
@@ -913,8 +909,16 @@ const confirmPrompt = async message => {
913
909
  return result;
914
910
  };
915
911
 
912
+ const getParentPath = path => {
913
+ const slashIndex = path.lastIndexOf('/');
914
+ if (slashIndex === -1) {
915
+ return '';
916
+ }
917
+ return path.slice(0, slashIndex);
918
+ };
916
919
  const downloadToDisk = async (diskPath, response) => {
917
- // @ts-ignore
920
+ const parentPath = getParentPath(diskPath);
921
+ await invoke('FileSystem.mkdir', parentPath);
918
922
  const blob = await response.blob();
919
923
  // @ts-ignore
920
924
  await invoke('FileSystem.writeBlob', diskPath, blob);
@@ -983,9 +987,10 @@ const getBaseName = downloadUrl => {
983
987
  const lastSlashIndex = downloadUrl.lastIndexOf('/');
984
988
  return downloadUrl.slice(lastSlashIndex + 1);
985
989
  };
990
+
986
991
  const getDiskPath = async downloadUrl => {
987
992
  // @ts-ignore
988
- const cacheDir = await invoke('PlatformPaths.getCachePath');
993
+ const cacheDir = await invoke('PlatformPaths.getCacheUri');
989
994
  const baseName = getBaseName(downloadUrl);
990
995
  const diskPath = `${cacheDir}/auto-updater/${baseName}`;
991
996
  return diskPath;
@@ -1021,8 +1026,8 @@ const getLatestReleaseVersion = async repository => {
1021
1026
  }
1022
1027
  };
1023
1028
 
1024
- const getUpdateUrl = (repository, version) => {
1025
- const fileName = `Lvce-Setup-v${version}-x64.exe`;
1029
+ const getUpdateUrl = (repository, fileNameTemplate, version) => {
1030
+ const fileName = fileNameTemplate.replace('${version}', version);
1026
1031
  const url = `https://github.com/${repository}/releases/download/v${version}/${fileName}`;
1027
1032
  return url;
1028
1033
  };
@@ -1083,7 +1088,7 @@ const shouldUpdate = async (updateSetting, version) => {
1083
1088
  return shouldUpdate;
1084
1089
  };
1085
1090
 
1086
- const doCheckForUpdates = async (updateSetting, repository, bucketName, cacheName) => {
1091
+ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bucketName, cacheName) => {
1087
1092
  try {
1088
1093
  if (!isOnline()) {
1089
1094
  return {
@@ -1105,7 +1110,7 @@ const doCheckForUpdates = async (updateSetting, repository, bucketName, cacheNam
1105
1110
  error: undefined
1106
1111
  };
1107
1112
  }
1108
- const downloadUrl = getUpdateUrl(repository, info.version);
1113
+ const downloadUrl = getUpdateUrl(repository, fileNameTemplate, info.version);
1109
1114
 
1110
1115
  // @ts-ignore
1111
1116
  await invoke('Layout.setUpdateState', {
@@ -1132,7 +1137,7 @@ const doCheckForUpdates = async (updateSetting, repository, bucketName, cacheNam
1132
1137
  }
1133
1138
  const diskPath = await getDiskPath(downloadUrl);
1134
1139
  if (!(await existsFile(diskPath))) {
1135
- await downloadToDisk(downloadUrl, response);
1140
+ await downloadToDisk(diskPath, response);
1136
1141
  }
1137
1142
  await installAndRestart(diskPath);
1138
1143
  return {
@@ -1159,6 +1164,7 @@ const checkForUpdates = async (updateSetting, repository) => {
1159
1164
  const lockName = 'electron-updates';
1160
1165
  const bucketName = 'electron-updates';
1161
1166
  const cacheName = 'electron-updates';
1167
+ const fileNameTemplate = `Lvce-Setup-v\${version}-x64.exe`;
1162
1168
  const result = await requestLock(lockName, async lock => {
1163
1169
  if (!lock) {
1164
1170
  return {
@@ -1166,7 +1172,7 @@ const checkForUpdates = async (updateSetting, repository) => {
1166
1172
  error: undefined
1167
1173
  };
1168
1174
  }
1169
- const result = await doCheckForUpdates(updateSetting, repository, bucketName, cacheName);
1175
+ const result = await doCheckForUpdates(updateSetting, repository, fileNameTemplate, bucketName, cacheName);
1170
1176
  return result;
1171
1177
  });
1172
1178
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/update-worker",
3
- "version": "1.8.0",
3
+ "version": "2.0.0",
4
4
  "description": "Update Worker",
5
5
  "repository": {
6
6
  "type": "git",