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