@lvce-editor/update-worker 1.7.0 → 1.9.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 => {
@@ -1021,8 +1017,8 @@ const getLatestReleaseVersion = async repository => {
1021
1017
  }
1022
1018
  };
1023
1019
 
1024
- const getUpdateUrl = (repository, version) => {
1025
- const fileName = `Lvce-Setup-v${version}-x64.exe`;
1020
+ const getUpdateUrl = (repository, fileNameTemplate, version) => {
1021
+ const fileName = fileNameTemplate.replace('${version}', version);
1026
1022
  const url = `https://github.com/${repository}/releases/download/v${version}/${fileName}`;
1027
1023
  return url;
1028
1024
  };
@@ -1083,7 +1079,7 @@ const shouldUpdate = async (updateSetting, version) => {
1083
1079
  return shouldUpdate;
1084
1080
  };
1085
1081
 
1086
- const checkForUpdates = async (updateSetting, repository) => {
1082
+ const doCheckForUpdates = async (updateSetting, repository, fileNameTemplate, bucketName, cacheName) => {
1087
1083
  try {
1088
1084
  if (!isOnline()) {
1089
1085
  return {
@@ -1091,8 +1087,6 @@ const checkForUpdates = async (updateSetting, repository) => {
1091
1087
  error: undefined
1092
1088
  };
1093
1089
  }
1094
- const bucketName = 'electron-updates';
1095
- const cacheName = 'electron-updates';
1096
1090
  const info = await getLatestReleaseVersion(repository);
1097
1091
  if (!info || !info.version) {
1098
1092
  return {
@@ -1107,7 +1101,7 @@ const checkForUpdates = async (updateSetting, repository) => {
1107
1101
  error: undefined
1108
1102
  };
1109
1103
  }
1110
- const downloadUrl = getUpdateUrl(repository, info.version);
1104
+ const downloadUrl = getUpdateUrl(repository, fileNameTemplate, info.version);
1111
1105
 
1112
1106
  // @ts-ignore
1113
1107
  await invoke('Layout.setUpdateState', {
@@ -1150,6 +1144,31 @@ const checkForUpdates = async (updateSetting, repository) => {
1150
1144
  }
1151
1145
  };
1152
1146
 
1147
+ const requestLock = async (lockName, callback) => {
1148
+ const result = await navigator.locks.request(lockName, {
1149
+ ifAvailable: true
1150
+ }, callback);
1151
+ return result;
1152
+ };
1153
+
1154
+ const checkForUpdates = async (updateSetting, repository) => {
1155
+ const lockName = 'electron-updates';
1156
+ const bucketName = 'electron-updates';
1157
+ const cacheName = 'electron-updates';
1158
+ const fileNameTemplate = `Lvce-Setup-v\${version}-x64.exe`;
1159
+ const result = await requestLock(lockName, async lock => {
1160
+ if (!lock) {
1161
+ return {
1162
+ updated: false,
1163
+ error: undefined
1164
+ };
1165
+ }
1166
+ const result = await doCheckForUpdates(updateSetting, repository, fileNameTemplate, bucketName, cacheName);
1167
+ return result;
1168
+ });
1169
+ return result;
1170
+ };
1171
+
1153
1172
  const commandMap = {
1154
1173
  'Update.downloadToCache': downloadUpdateToCache,
1155
1174
  'Update.checkForUpdates': checkForUpdates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/update-worker",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Update Worker",
5
5
  "repository": {
6
6
  "type": "git",