@etsoo/appscript 1.4.19 → 1.4.21

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.
@@ -271,6 +271,13 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
271
271
  */
272
272
  detectIP(callback?: IDetectIPCallback): void;
273
273
  private detectIPCallbacks;
274
+ /**
275
+ * Download file
276
+ * @param stream File stream
277
+ * @param filename File name
278
+ * @param callback callback
279
+ */
280
+ download(stream: ReadableStream, filename?: string, callback?: (success: boolean | undefined) => void): Promise<void>;
274
281
  /**
275
282
  * Encrypt message
276
283
  * @param message Message
@@ -703,6 +703,35 @@ class CoreApp {
703
703
  var _a;
704
704
  (_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
705
705
  }
706
+ /**
707
+ * Download file
708
+ * @param stream File stream
709
+ * @param filename File name
710
+ * @param callback callback
711
+ */
712
+ async download(stream, filename, callback) {
713
+ const downloadFile = async () => {
714
+ let success = await shared_1.DomUtils.downloadFile(stream, filename, BridgeUtils_1.BridgeUtils.host == null);
715
+ if (success == null) {
716
+ success = await shared_1.DomUtils.downloadFile(stream, filename, false);
717
+ }
718
+ if (callback) {
719
+ callback(success);
720
+ }
721
+ else if (success)
722
+ this.notifier.message(notificationbase_1.NotificationMessageType.Success, this.get('fileDownloaded'));
723
+ };
724
+ // https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/isActive
725
+ if ('userActivation' in navigator &&
726
+ !navigator.userActivation.isActive) {
727
+ this.notifier.alert(this.get('reactivateTip'), async () => {
728
+ await downloadFile();
729
+ });
730
+ }
731
+ else {
732
+ await downloadFile();
733
+ }
734
+ }
706
735
  /**
707
736
  * Encrypt message
708
737
  * @param message Message
@@ -209,6 +209,13 @@ export interface IApp {
209
209
  * @param callback Callback will be called when the IP is ready
210
210
  */
211
211
  detectIP(callback?: IDetectIPCallback): void;
212
+ /**
213
+ * Download file
214
+ * @param stream File stream
215
+ * @param filename File name
216
+ * @param callback callback
217
+ */
218
+ download(stream: ReadableStream, filename?: string, callback?: (success: boolean | undefined) => void): Promise<void>;
212
219
  /**
213
220
  * Encrypt message
214
221
  * @param message Message
@@ -53,6 +53,16 @@ export declare enum ProductWeightUnit {
53
53
  */
54
54
  TON = 49
55
55
  }
56
+ /**
57
+ * Product other units
58
+ */
59
+ export declare enum ProductOtherUnit {
60
+ /**
61
+ * Cubic meter
62
+ * 立方米
63
+ */
64
+ M3 = 50
65
+ }
56
66
  /**
57
67
  * Product units enum
58
68
  * Repeat options take range 10 - 39
@@ -60,6 +70,7 @@ export declare enum ProductWeightUnit {
60
70
  */
61
71
  export declare const ProductUnit: {
62
72
  [x: number]: string;
73
+ M3: ProductOtherUnit.M3;
63
74
  GRAM: ProductWeightUnit.GRAM;
64
75
  JIN: ProductWeightUnit.JIN;
65
76
  KILOGRAM: ProductWeightUnit.KILOGRAM;
@@ -79,7 +90,7 @@ export declare const ProductUnit: {
79
90
  PC: ProductBaseUnit.PC;
80
91
  SET: ProductBaseUnit.SET;
81
92
  };
82
- export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | ProductWeightUnit;
93
+ export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | ProductWeightUnit | ProductOtherUnit;
83
94
  /**
84
95
  * Product asset units enum
85
96
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetUnits = exports.ProductUnit = exports.ProductWeightUnit = exports.ProductBaseUnit = void 0;
3
+ exports.AssetUnits = exports.ProductUnit = exports.ProductOtherUnit = exports.ProductWeightUnit = exports.ProductBaseUnit = void 0;
4
4
  const RepeatOption_1 = require("./RepeatOption");
5
5
  /**
6
6
  * Product base units
@@ -59,6 +59,17 @@ var ProductWeightUnit;
59
59
  */
60
60
  ProductWeightUnit[ProductWeightUnit["TON"] = 49] = "TON";
61
61
  })(ProductWeightUnit || (exports.ProductWeightUnit = ProductWeightUnit = {}));
62
+ /**
63
+ * Product other units
64
+ */
65
+ var ProductOtherUnit;
66
+ (function (ProductOtherUnit) {
67
+ /**
68
+ * Cubic meter
69
+ * 立方米
70
+ */
71
+ ProductOtherUnit[ProductOtherUnit["M3"] = 50] = "M3";
72
+ })(ProductOtherUnit || (exports.ProductOtherUnit = ProductOtherUnit = {}));
62
73
  /**
63
74
  * Product units enum
64
75
  * Repeat options take range 10 - 39
@@ -68,7 +79,8 @@ exports.ProductUnit = {
68
79
  ...ProductBaseUnit,
69
80
  ...RepeatOption_1.RepeatOption,
70
81
  ...ProductAssetUnit,
71
- ...ProductWeightUnit
82
+ ...ProductWeightUnit,
83
+ ...ProductOtherUnit
72
84
  };
73
85
  /**
74
86
  * Product asset units enum
@@ -219,6 +219,7 @@
219
219
  "unitKILOGRAM": "Kg",
220
220
  "unitTIME": "Time",
221
221
  "unitTON": "Ton",
222
+ "unitM3": "m3",
222
223
  "update": "Update",
223
224
  "updateReady": "Update ready",
224
225
  "updateTime": "Update time",
@@ -219,6 +219,7 @@
219
219
  "unitKILOGRAM": "公斤",
220
220
  "unitTIME": "次",
221
221
  "unitTON": "吨",
222
+ "unitM3": "立方米",
222
223
  "update": "更新",
223
224
  "updateReady": "更新就绪",
224
225
  "updateTime": "更新时间",
@@ -218,6 +218,8 @@
218
218
  "unitJIN": "斤",
219
219
  "unitKILOGRAM": "公斤",
220
220
  "unitTIME": "次",
221
+ "unitTON": "噸",
222
+ "unitM3": "立方米",
221
223
  "update": "更新",
222
224
  "updateReady": "更新就緒",
223
225
  "updateTime": "更新時間",
@@ -271,6 +271,13 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
271
271
  */
272
272
  detectIP(callback?: IDetectIPCallback): void;
273
273
  private detectIPCallbacks;
274
+ /**
275
+ * Download file
276
+ * @param stream File stream
277
+ * @param filename File name
278
+ * @param callback callback
279
+ */
280
+ download(stream: ReadableStream, filename?: string, callback?: (success: boolean | undefined) => void): Promise<void>;
274
281
  /**
275
282
  * Encrypt message
276
283
  * @param message Message
@@ -677,6 +677,35 @@ export class CoreApp {
677
677
  var _a;
678
678
  (_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
679
679
  }
680
+ /**
681
+ * Download file
682
+ * @param stream File stream
683
+ * @param filename File name
684
+ * @param callback callback
685
+ */
686
+ async download(stream, filename, callback) {
687
+ const downloadFile = async () => {
688
+ let success = await DomUtils.downloadFile(stream, filename, BridgeUtils.host == null);
689
+ if (success == null) {
690
+ success = await DomUtils.downloadFile(stream, filename, false);
691
+ }
692
+ if (callback) {
693
+ callback(success);
694
+ }
695
+ else if (success)
696
+ this.notifier.message(NotificationMessageType.Success, this.get('fileDownloaded'));
697
+ };
698
+ // https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/isActive
699
+ if ('userActivation' in navigator &&
700
+ !navigator.userActivation.isActive) {
701
+ this.notifier.alert(this.get('reactivateTip'), async () => {
702
+ await downloadFile();
703
+ });
704
+ }
705
+ else {
706
+ await downloadFile();
707
+ }
708
+ }
680
709
  /**
681
710
  * Encrypt message
682
711
  * @param message Message
@@ -209,6 +209,13 @@ export interface IApp {
209
209
  * @param callback Callback will be called when the IP is ready
210
210
  */
211
211
  detectIP(callback?: IDetectIPCallback): void;
212
+ /**
213
+ * Download file
214
+ * @param stream File stream
215
+ * @param filename File name
216
+ * @param callback callback
217
+ */
218
+ download(stream: ReadableStream, filename?: string, callback?: (success: boolean | undefined) => void): Promise<void>;
212
219
  /**
213
220
  * Encrypt message
214
221
  * @param message Message
@@ -53,6 +53,16 @@ export declare enum ProductWeightUnit {
53
53
  */
54
54
  TON = 49
55
55
  }
56
+ /**
57
+ * Product other units
58
+ */
59
+ export declare enum ProductOtherUnit {
60
+ /**
61
+ * Cubic meter
62
+ * 立方米
63
+ */
64
+ M3 = 50
65
+ }
56
66
  /**
57
67
  * Product units enum
58
68
  * Repeat options take range 10 - 39
@@ -60,6 +70,7 @@ export declare enum ProductWeightUnit {
60
70
  */
61
71
  export declare const ProductUnit: {
62
72
  [x: number]: string;
73
+ M3: ProductOtherUnit.M3;
63
74
  GRAM: ProductWeightUnit.GRAM;
64
75
  JIN: ProductWeightUnit.JIN;
65
76
  KILOGRAM: ProductWeightUnit.KILOGRAM;
@@ -79,7 +90,7 @@ export declare const ProductUnit: {
79
90
  PC: ProductBaseUnit.PC;
80
91
  SET: ProductBaseUnit.SET;
81
92
  };
82
- export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | ProductWeightUnit;
93
+ export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | ProductWeightUnit | ProductOtherUnit;
83
94
  /**
84
95
  * Product asset units enum
85
96
  */
@@ -56,6 +56,17 @@ export var ProductWeightUnit;
56
56
  */
57
57
  ProductWeightUnit[ProductWeightUnit["TON"] = 49] = "TON";
58
58
  })(ProductWeightUnit || (ProductWeightUnit = {}));
59
+ /**
60
+ * Product other units
61
+ */
62
+ export var ProductOtherUnit;
63
+ (function (ProductOtherUnit) {
64
+ /**
65
+ * Cubic meter
66
+ * 立方米
67
+ */
68
+ ProductOtherUnit[ProductOtherUnit["M3"] = 50] = "M3";
69
+ })(ProductOtherUnit || (ProductOtherUnit = {}));
59
70
  /**
60
71
  * Product units enum
61
72
  * Repeat options take range 10 - 39
@@ -65,7 +76,8 @@ export const ProductUnit = {
65
76
  ...ProductBaseUnit,
66
77
  ...RepeatOption,
67
78
  ...ProductAssetUnit,
68
- ...ProductWeightUnit
79
+ ...ProductWeightUnit,
80
+ ...ProductOtherUnit
69
81
  };
70
82
  /**
71
83
  * Product asset units enum
@@ -219,6 +219,7 @@
219
219
  "unitKILOGRAM": "Kg",
220
220
  "unitTIME": "Time",
221
221
  "unitTON": "Ton",
222
+ "unitM3": "m3",
222
223
  "update": "Update",
223
224
  "updateReady": "Update ready",
224
225
  "updateTime": "Update time",
@@ -219,6 +219,7 @@
219
219
  "unitKILOGRAM": "公斤",
220
220
  "unitTIME": "次",
221
221
  "unitTON": "吨",
222
+ "unitM3": "立方米",
222
223
  "update": "更新",
223
224
  "updateReady": "更新就绪",
224
225
  "updateTime": "更新时间",
@@ -218,6 +218,8 @@
218
218
  "unitJIN": "斤",
219
219
  "unitKILOGRAM": "公斤",
220
220
  "unitTIME": "次",
221
+ "unitTON": "噸",
222
+ "unitM3": "立方米",
221
223
  "update": "更新",
222
224
  "updateReady": "更新就緒",
223
225
  "updateTime": "更新時間",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.19",
3
+ "version": "1.4.21",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.25",
56
56
  "@etsoo/restclient": "^1.0.88",
57
- "@etsoo/shared": "^1.2.5",
57
+ "@etsoo/shared": "^1.2.7",
58
58
  "crypto-js": "^4.1.1"
59
59
  },
60
60
  "devDependencies": {
@@ -63,8 +63,8 @@
63
63
  "@babel/plugin-transform-runtime": "^7.22.5",
64
64
  "@babel/preset-env": "^7.22.5",
65
65
  "@babel/runtime-corejs3": "^7.22.5",
66
- "@types/jest": "^29.5.2",
67
66
  "@types/crypto-js": "^4.1.1",
67
+ "@types/jest": "^29.5.2",
68
68
  "jest": "^29.5.0",
69
69
  "jest-environment-jsdom": "^29.5.0",
70
70
  "ts-jest": "^29.1.0",
@@ -958,6 +958,49 @@ export abstract class CoreApp<
958
958
  this.ipDetectCallbacks?.forEach((f) => f());
959
959
  }
960
960
 
961
+ /**
962
+ * Download file
963
+ * @param stream File stream
964
+ * @param filename File name
965
+ * @param callback callback
966
+ */
967
+ async download(
968
+ stream: ReadableStream,
969
+ filename?: string,
970
+ callback?: (success: boolean | undefined) => void
971
+ ) {
972
+ const downloadFile = async () => {
973
+ let success = await DomUtils.downloadFile(
974
+ stream,
975
+ filename,
976
+ BridgeUtils.host == null
977
+ );
978
+ if (success == null) {
979
+ success = await DomUtils.downloadFile(stream, filename, false);
980
+ }
981
+
982
+ if (callback) {
983
+ callback(success);
984
+ } else if (success)
985
+ this.notifier.message(
986
+ NotificationMessageType.Success,
987
+ this.get('fileDownloaded')!
988
+ );
989
+ };
990
+
991
+ // https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/isActive
992
+ if (
993
+ 'userActivation' in navigator &&
994
+ !(navigator.userActivation as any).isActive
995
+ ) {
996
+ this.notifier.alert(this.get('reactivateTip')!, async () => {
997
+ await downloadFile();
998
+ });
999
+ } else {
1000
+ await downloadFile();
1001
+ }
1002
+ }
1003
+
961
1004
  /**
962
1005
  * Encrypt message
963
1006
  * @param message Message
package/src/app/IApp.ts CHANGED
@@ -280,6 +280,18 @@ export interface IApp {
280
280
  */
281
281
  detectIP(callback?: IDetectIPCallback): void;
282
282
 
283
+ /**
284
+ * Download file
285
+ * @param stream File stream
286
+ * @param filename File name
287
+ * @param callback callback
288
+ */
289
+ download(
290
+ stream: ReadableStream,
291
+ filename?: string,
292
+ callback?: (success: boolean | undefined) => void
293
+ ): Promise<void>;
294
+
283
295
  /**
284
296
  * Encrypt message
285
297
  * @param message Message
@@ -62,6 +62,17 @@ export enum ProductWeightUnit {
62
62
  TON = 49
63
63
  }
64
64
 
65
+ /**
66
+ * Product other units
67
+ */
68
+ export enum ProductOtherUnit {
69
+ /**
70
+ * Cubic meter
71
+ * 立方米
72
+ */
73
+ M3 = 50
74
+ }
75
+
65
76
  /**
66
77
  * Product units enum
67
78
  * Repeat options take range 10 - 39
@@ -71,13 +82,15 @@ export const ProductUnit = {
71
82
  ...ProductBaseUnit,
72
83
  ...RepeatOption,
73
84
  ...ProductAssetUnit,
74
- ...ProductWeightUnit
85
+ ...ProductWeightUnit,
86
+ ...ProductOtherUnit
75
87
  };
76
88
  export type ProductUnit =
77
89
  | ProductBaseUnit
78
90
  | RepeatOption
79
91
  | ProductAssetUnit
80
- | ProductWeightUnit;
92
+ | ProductWeightUnit
93
+ | ProductOtherUnit;
81
94
 
82
95
  /**
83
96
  * Product asset units enum
package/src/i18n/en.json CHANGED
@@ -219,6 +219,7 @@
219
219
  "unitKILOGRAM": "Kg",
220
220
  "unitTIME": "Time",
221
221
  "unitTON": "Ton",
222
+ "unitM3": "m3",
222
223
  "update": "Update",
223
224
  "updateReady": "Update ready",
224
225
  "updateTime": "Update time",
@@ -219,6 +219,7 @@
219
219
  "unitKILOGRAM": "公斤",
220
220
  "unitTIME": "次",
221
221
  "unitTON": "吨",
222
+ "unitM3": "立方米",
222
223
  "update": "更新",
223
224
  "updateReady": "更新就绪",
224
225
  "updateTime": "更新时间",
@@ -218,6 +218,8 @@
218
218
  "unitJIN": "斤",
219
219
  "unitKILOGRAM": "公斤",
220
220
  "unitTIME": "次",
221
+ "unitTON": "噸",
222
+ "unitM3": "立方米",
221
223
  "update": "更新",
222
224
  "updateReady": "更新就緒",
223
225
  "updateTime": "更新時間",