@kosdev-code/kos-ui-sdk 3.0.23 → 3.0.24

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/index.js CHANGED
@@ -11375,6 +11375,8 @@ let UsbUpdateContainerModelImpl = class {
11375
11375
  updateActiveUpdate(update) {
11376
11376
  this._activeUpdate = update;
11377
11377
  }
11378
+ _isSearching = false;
11379
+ _hasSearched = false;
11378
11380
  // -------------------LIFECYCLE----------------------------
11379
11381
  get isUsbInserted() {
11380
11382
  return this.storageService.isStorageInserted;
@@ -11382,27 +11384,43 @@ let UsbUpdateContainerModelImpl = class {
11382
11384
  get hasAvailableUpdates() {
11383
11385
  return this._models.data.length > 0;
11384
11386
  }
11387
+ get isSearchingUpdates() {
11388
+ return this._isSearching;
11389
+ }
11390
+ get noAvailableUpdates() {
11391
+ return this.isUsbInserted && this._hasSearched && !this._isSearching && this._models.data.length === 0;
11392
+ }
11385
11393
  async syncAvailableUpdates() {
11386
- const updates = await getAvailableUpdates();
11387
11394
  kosAction(() => {
11388
- const allKeys = updates.map(
11389
- (update) => `${update.deviceId}-${update.manifestId}`
11390
- );
11391
- this._models.data.filter((model) => !allKeys.includes(model.id)).forEach((model) => this.removeModel(model.id));
11392
- updates.forEach((update) => {
11393
- const modelId = `${update.deviceId}-${update.manifestId}`;
11394
- const model = UsbUpdate.instance(modelId).forceUpdate.options({
11395
- ...update,
11396
- createTime: new Date(update.createTime)
11397
- }).build();
11398
- this.addModel(model);
11399
- });
11400
- if (this.data.length === 1) {
11401
- this.updateActiveUpdate(this.data[0]);
11402
- } else {
11403
- this.clearActiveUpdate();
11404
- }
11395
+ this._isSearching = true;
11405
11396
  });
11397
+ try {
11398
+ const updates = await getAvailableUpdates();
11399
+ kosAction(() => {
11400
+ const allKeys = updates.map(
11401
+ (update) => `${update.deviceId}-${update.manifestId}`
11402
+ );
11403
+ this._models.data.filter((model) => !allKeys.includes(model.id)).forEach((model) => this.removeModel(model.id));
11404
+ updates.forEach((update) => {
11405
+ const modelId = `${update.deviceId}-${update.manifestId}`;
11406
+ const model = UsbUpdate.instance(modelId).forceUpdate.options({
11407
+ ...update,
11408
+ createTime: new Date(update.createTime)
11409
+ }).build();
11410
+ this.addModel(model);
11411
+ });
11412
+ if (this.data.length === 1) {
11413
+ this.updateActiveUpdate(this.data[0]);
11414
+ } else {
11415
+ this.clearActiveUpdate();
11416
+ }
11417
+ });
11418
+ } finally {
11419
+ kosAction(() => {
11420
+ this._isSearching = false;
11421
+ this._hasSearched = true;
11422
+ });
11423
+ }
11406
11424
  }
11407
11425
  usbInsertedEffect() {
11408
11426
  if (this.isUsbInserted) {
@@ -11410,6 +11428,10 @@ let UsbUpdateContainerModelImpl = class {
11410
11428
  } else {
11411
11429
  this._models.clear();
11412
11430
  this.clearActiveUpdate();
11431
+ kosAction(() => {
11432
+ this._hasSearched = false;
11433
+ this._isSearching = false;
11434
+ });
11413
11435
  }
11414
11436
  }
11415
11437
  async init() {
@@ -11433,7 +11455,12 @@ __decorateClass$9([
11433
11455
  kosChild
11434
11456
  ], UsbUpdateContainerModelImpl.prototype, "_models", 2);
11435
11457
  __decorateClass$9([
11436
- kosModelEffect({ dependencies: (model) => [model.isUsbInserted] })
11458
+ kosModelEffect({
11459
+ dependencies: (model) => [
11460
+ model.isUsbInserted,
11461
+ model.storageService.data.length
11462
+ ]
11463
+ })
11437
11464
  ], UsbUpdateContainerModelImpl.prototype, "usbInsertedEffect", 1);
11438
11465
  UsbUpdateContainerModelImpl = __decorateClass$9([
11439
11466
  kosModel(MODEL_TYPE$8)
@@ -14629,17 +14656,28 @@ const useUsbUpdateContainer = () => {
14629
14656
  const [inserted, setInserted] = useState(false);
14630
14657
  const [updateAvailable, setUpdateAvailable] = useState(false);
14631
14658
  const [updates, setUpdates] = useState([]);
14659
+ const [isSearching, setIsSearching] = useState(false);
14660
+ const [noUpdates, setNoUpdates] = useState(false);
14632
14661
  useEffect(() => {
14633
14662
  const disposer = kosAutoEffect(() => {
14634
14663
  setInserted(result.model?.isUsbInserted ?? false);
14635
14664
  setUpdateAvailable(result.model?.hasAvailableUpdates ?? false);
14636
14665
  setUpdates(result.model?.data ?? []);
14666
+ setIsSearching(result.model?.isSearchingUpdates ?? false);
14667
+ setNoUpdates(result.model?.noAvailableUpdates ?? false);
14637
14668
  });
14638
14669
  return () => {
14639
14670
  disposer();
14640
14671
  };
14641
14672
  }, [result.model]);
14642
- return { ...result, inserted, updateAvailable, updates };
14673
+ return {
14674
+ ...result,
14675
+ inserted,
14676
+ updateAvailable,
14677
+ updates,
14678
+ isSearching,
14679
+ noUpdates
14680
+ };
14643
14681
  };
14644
14682
  function withUsbUpdateContainer(WrappedComponent) {
14645
14683
  return (props) => {