@lvce-editor/update-worker 1.6.0 → 1.8.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.
@@ -1070,6 +1070,10 @@ const isCached = async (url, cache) => {
1070
1070
  return false;
1071
1071
  };
1072
1072
 
1073
+ const isOnline = () => {
1074
+ return navigator.onLine;
1075
+ };
1076
+
1073
1077
  const shouldUpdate = async (updateSetting, version) => {
1074
1078
  if (updateSetting && updateSetting !== 'none') {
1075
1079
  return true;
@@ -1079,10 +1083,14 @@ const shouldUpdate = async (updateSetting, version) => {
1079
1083
  return shouldUpdate;
1080
1084
  };
1081
1085
 
1082
- const checkForUpdates = async (updateSetting, repository) => {
1086
+ const doCheckForUpdates = async (updateSetting, repository, bucketName, cacheName) => {
1083
1087
  try {
1084
- const bucketName = 'electron-updates';
1085
- const cacheName = 'electron-updates';
1088
+ if (!isOnline()) {
1089
+ return {
1090
+ updated: false,
1091
+ error: undefined
1092
+ };
1093
+ }
1086
1094
  const info = await getLatestReleaseVersion(repository);
1087
1095
  if (!info || !info.version) {
1088
1096
  return {
@@ -1140,6 +1148,30 @@ const checkForUpdates = async (updateSetting, repository) => {
1140
1148
  }
1141
1149
  };
1142
1150
 
1151
+ const requestLock = async (lockName, callback) => {
1152
+ const result = await navigator.locks.request(lockName, {
1153
+ ifAvailable: true
1154
+ }, callback);
1155
+ return result;
1156
+ };
1157
+
1158
+ const checkForUpdates = async (updateSetting, repository) => {
1159
+ const lockName = 'electron-updates';
1160
+ const bucketName = 'electron-updates';
1161
+ const cacheName = 'electron-updates';
1162
+ const result = await requestLock(lockName, async lock => {
1163
+ if (!lock) {
1164
+ return {
1165
+ updated: false,
1166
+ error: undefined
1167
+ };
1168
+ }
1169
+ const result = await doCheckForUpdates(updateSetting, repository, bucketName, cacheName);
1170
+ return result;
1171
+ });
1172
+ return result;
1173
+ };
1174
+
1143
1175
  const commandMap = {
1144
1176
  'Update.downloadToCache': downloadUpdateToCache,
1145
1177
  'Update.checkForUpdates': checkForUpdates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/update-worker",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Update Worker",
5
5
  "repository": {
6
6
  "type": "git",