@cpzxrobot/sdk 1.2.91 → 1.2.93

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/device_gateway.ts CHANGED
@@ -205,7 +205,7 @@ export class DeviceGateway extends Object {
205
205
  //获取设备详情
206
206
  //ID:点位ID,设备UUID,当type是device时,为设备ID(UUID);当type是datapoint时,为点位ID(number)
207
207
  show(id: any, type: "device"|"datapoint" = "datapoint"){
208
- this.context.showInDeviceManager(id,type);
208
+ this.context.platform.showInDeviceManager(id,type);
209
209
  }
210
210
 
211
211
  async watch(
@@ -157,7 +157,7 @@ class DeviceGateway extends Object {
157
157
  //获取设备详情
158
158
  //ID:点位ID,设备UUID,当type是device时,为设备ID(UUID);当type是datapoint时,为点位ID(number)
159
159
  show(id, type = "datapoint") {
160
- this.context.showInDeviceManager(id, type);
160
+ this.context.platform.showInDeviceManager(id, type);
161
161
  }
162
162
  async watch(id, fn) {
163
163
  var axios = await this.context.ready;
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Cpzxrobot = void 0;
27
27
  exports.default = default_1;
28
28
  const device_gateway_1 = require("./device_gateway");
29
+ const windows_platform_1 = require("./windows_platform");
29
30
  const user_gateway_1 = require("./user_gateway");
30
31
  const factory_gateway_1 = require("./factory_gateway");
31
32
  const transport_gateway_1 = require("./transport_gateway");
@@ -48,8 +49,10 @@ const quotation_gateway_1 = require("./quotation_gateway");
48
49
  const ai_gateway_1 = require("./ai_gateway");
49
50
  const construction_gateway_1 = require("./construction_gateway");
50
51
  const system_gateway_1 = require("./system_gateway");
52
+ const mobile_platform_1 = require("./mobile_platform");
53
+ const web_platform_1 = require("./web_platform");
51
54
  class Cpzxrobot {
52
- constructor(appCode) {
55
+ constructor(appCode, baseUrl, initSelectedFactory, initSelectedUnit) {
53
56
  this.pigfarm = new pigfarm_gateway_1.PigfarmGateway(this);
54
57
  this.chickenfarm = new chickenfarm_gateway_1.ChickenFarmGateway(this);
55
58
  this.hash = "shzx";
@@ -69,12 +72,13 @@ class Cpzxrobot {
69
72
  this.ai = new ai_gateway_1.AiGateway(this);
70
73
  this.construction = new construction_gateway_1.ConstructionGateway(this);
71
74
  this.system = new system_gateway_1.SystemGateway(this);
75
+ this.sseCallbacks = {};
72
76
  //获取当前浏览器的域名
73
77
  this.ready = new Promise((resolve, reject) => {
74
78
  this.resolveReady = resolve;
75
79
  this.rejectReady = reject;
76
80
  });
77
- this.getDomain();
81
+ this.getDomain(baseUrl, initSelectedFactory, initSelectedUnit);
78
82
  this.appCode = appCode;
79
83
  this.user = new user_gateway_1.UserGateway(this);
80
84
  this.factory = new factory_gateway_1.FactoryGateway(this);
@@ -99,362 +103,25 @@ class Cpzxrobot {
99
103
  }
100
104
  initAxios(baseURL) {
101
105
  if (this.mode !== "miniapp_in_app") {
102
- const fetchWithAuth = async (input, init) => {
103
- const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
104
- headers.set('Authorization', this.token);
105
- headers.set('Miniapp-Code', this.appCode);
106
- const response = await fetch(baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
107
- if (!response.ok) {
108
- throw new Error(`HTTP error! status: ${response.status}`);
109
- }
110
- return response;
111
- };
112
- const streamWithAuth = async (input, init, fn) => {
113
- const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
114
- headers.set('Authorization', this.token);
115
- headers.set('Miniapp-Code', this.appCode);
116
- const response = await fetch(baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
117
- var reader = response.body.getReader();
118
- const decoder = new TextDecoder("utf-8");
119
- let done = false;
120
- var buf = "";
121
- while (!done) {
122
- const { value, done } = await reader.read();
123
- if (done) {
124
- break;
125
- }
126
- const chunkValue = decoder.decode(value);
127
- //split value to lines
128
- // 将值拆分为行
129
- buf = buf + chunkValue;
130
- var i = buf.indexOf("\n");
131
- while (i > -1) {
132
- //find first \n
133
- var line = buf.substring(0, i);
134
- try {
135
- if (line === "[DONE]") {
136
- break;
137
- }
138
- else {
139
- // remove prefix 'data: '
140
- // 移除前缀 'data: '
141
- var data = JSON.parse(line.split(": ")[1]);
142
- //{"choices":[{"delta":{"content":" </"},"index":0}],"created":1741749068,"id":"chatcmpl-67ccb889154043f5874cbf3a64ec163e","model":"DeepSeek-R1","object":"chat.completion.chunk"}
143
- fn === null || fn === void 0 ? void 0 : fn.call(data);
144
- }
145
- }
146
- catch (e) {
147
- console.error("解析失败", e);
148
- }
149
- buf = buf.substring(i + 1);
150
- i = buf.indexOf("\n");
151
- }
152
- }
153
- ;
154
- return true;
155
- };
156
- const processQueryParams = (url, config) => {
157
- if (config && config.params) {
158
- const flattenParams = (params, prefix = '') => {
159
- const result = {};
160
- Object.keys(params).forEach(key => {
161
- const value = params[key];
162
- const fullKey = prefix ? `${prefix}[${key}]` : key;
163
- if (value && typeof value === 'object' && !Array.isArray(value)) {
164
- Object.assign(result, flattenParams(value, fullKey));
165
- }
166
- else if (value) {
167
- result[fullKey] = value.toString();
168
- }
169
- });
170
- return result;
171
- };
172
- const flattened = flattenParams(config.params);
173
- url += "?" + new URLSearchParams(flattened).toString();
174
- delete config.params;
175
- }
176
- return url;
177
- };
178
- const instance = {
179
- get: async (url, config) => {
180
- url = processQueryParams(url, config);
181
- const response = await fetchWithAuth(url, {
182
- method: 'GET',
183
- headers: config === null || config === void 0 ? void 0 : config.headers
184
- });
185
- return { data: await response.json() };
186
- },
187
- post: async (url, data, config) => {
188
- const response = await fetchWithAuth(url, {
189
- method: 'POST',
190
- headers: Object.assign({ 'Content-Type': 'application/json' }, config === null || config === void 0 ? void 0 : config.headers),
191
- body: JSON.stringify(data)
192
- });
193
- return { data: await response.json() };
194
- },
195
- getAndSave: async (url, config) => {
196
- var _a;
197
- url = processQueryParams(url, config);
198
- const response = await fetchWithAuth(url, {
199
- method: 'GET',
200
- headers: config === null || config === void 0 ? void 0 : config.headers
201
- });
202
- const blob = await response.blob();
203
- // 文件名解析逻辑
204
- const contentDisposition = response.headers.get('Content-Disposition');
205
- let filename = (_a = config === null || config === void 0 ? void 0 : config.fileName) !== null && _a !== void 0 ? _a : ""; // 默认文件名
206
- // 1. 优先使用响应头中的文件名
207
- if (filename == "") {
208
- if (contentDisposition) {
209
- const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
210
- if (utf8FilenameMatch) {
211
- filename = decodeURIComponent(utf8FilenameMatch[1]);
212
- }
213
- else {
214
- const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
215
- if (filenameMatch)
216
- filename = filenameMatch[1];
217
- }
218
- }
219
- else {
220
- filename = "file";
221
- }
222
- }
223
- await this.saveBlob(blob, filename);
224
- return { data: blob };
225
- },
226
- getAndPreview: async (url, config) => {
227
- url = processQueryParams(url, config);
228
- return instance.getAndSave(url, config);
229
- },
230
- upload: async (url, option) => {
231
- return new Promise((resolve, reject) => {
232
- const button = document.createElement("input");
233
- button.type = "file";
234
- button.style.display = "none";
235
- button.multiple = (option === null || option === void 0 ? void 0 : option.multiple) || false;
236
- document.body.appendChild(button);
237
- button.click(); // 手动触发点击
238
- button.onchange = async (e) => {
239
- const files = e.target.files;
240
- if (files && files.length > 0) {
241
- const formData = new FormData();
242
- if (option === null || option === void 0 ? void 0 : option.multiple) {
243
- for (let i = 0; i < files.length; i++) {
244
- formData.append("files[]", files[i]);
245
- }
246
- }
247
- else {
248
- formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", files[0]);
249
- }
250
- for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
251
- formData.append(key, option["data"][key]);
252
- }
253
- const response = await fetchWithAuth(url, {
254
- method: 'POST',
255
- body: formData
256
- });
257
- button.remove();
258
- resolve({ data: await response.json() });
259
- }
260
- else {
261
- button.remove();
262
- resolve({ data: { Error: "没有选择文件" } });
263
- }
264
- };
265
- });
266
- },
267
- getAsSse: (url, fn, config) => {
268
- return new Promise((resolve, reject) => {
269
- streamWithAuth(url, {
270
- method: 'GET',
271
- }, fn);
272
- });
273
- }
274
- };
275
106
  // @ts-ignore
276
107
  this.axios = instance;
277
108
  }
278
109
  }
279
110
  _saveBlobAsBase64(blob, filename) {
280
- var that = this;
281
- return new Promise((resolve, reject) => {
282
- const reader = new FileReader();
283
- reader.readAsDataURL(blob);
284
- reader.onloadend = async () => {
285
- // @ts-ignoreconst reader = new FileReader();
286
- const base64 = reader.result;
287
- // @ts-ignore
288
- await that.saveBase64(base64, filename);
289
- resolve();
290
- };
291
- reader.onerror = (err) => {
292
- reject(err);
293
- };
294
- });
111
+ return this.platform.saveBlob(blob, filename);
295
112
  }
296
113
  //获取当前浏览器的域名
297
- getDomain() {
114
+ getDomain(baseURL, initSelectedFactory, initSelectedUnit) {
298
115
  const domain = window.location.hostname;
299
116
  console.log("load domain ", domain);
300
117
  if (domain == "miniapp") {
301
118
  this.mode = "miniapp_in_app";
302
- // @ts-ignore
303
- this.axios = getAxiosFromMiniApp();
304
- this.platformReady = Promise.resolve(true);
305
- // @ts-ignore
306
- this._getSelectedFarmFromMiniApp = window.getSelectedFarmFromMiniApp;
307
- // @ts-ignore
308
- this._getSelectedUnitFromMiniApp = window.getSelectedUnitFromMiniApp;
309
- // @ts-ignore
310
- this._jumpToMiniApp = window.miniapp.open;
311
- // @ts-ignore
312
- this.scanQrcode = window.miniapp.scanQrcode;
313
- // @ts-ignore
314
- this.setTitle = window.miniapp.setTitle;
315
- // @ts-ignore
316
- this.saveBase64 = window.miniapp.saveBase64;
317
- // @ts-ignore
318
- this.vibrate = window.miniapp.vibrate;
319
- // @ts-ignore
320
- this.reloadGroup = window.miniapp.reloadGroup;
321
- this.saveBlob = this._saveBlobAsBase64;
322
- // @ts-ignore
323
- this.getGeo = window.miniapp.getGeo;
324
- // @ts-ignore
325
- this.setResult = window.miniapp.setResult;
326
- // @ts-ignore
327
- this.setResultAs = window.miniapp.setResultAs;
328
- // @ts-ignore
329
- this.setError = window.miniapp.setError;
330
- // @ts-ignore
331
- this.setProgress = window.miniapp.setProgress;
332
- // @ts-ignore
333
- this.showInDeviceManager = window.miniapp.showInDeviceManager;
119
+ this.platform = new windows_platform_1.WindwosMiniAppPlatform();
334
120
  }
335
121
  else if (domain == "appassets.androidplatform.net" || domain == "webc.cpzxrobot.com" ||
336
122
  this.isIosMiniApp(window.location)) {
337
123
  this.mode = "miniapp_in_app";
338
- const platform =
339
- // @ts-ignore
340
- window.flutter_inappwebview;
341
- var that = this;
342
- this._getSelectedFarmFromMiniApp = function () {
343
- return platform.callHandler("getSelectedFarmFromMiniApp");
344
- };
345
- this._getSelectedUnitFromMiniApp = function () {
346
- return platform.callHandler("getSelectedUnitFromMiniApp");
347
- };
348
- this._jumpToMiniApp = function (url) {
349
- return platform.callHandler("app.openMiniapp", url);
350
- };
351
- this.scanQrcode = function () {
352
- return platform.callHandler("app.scanQrcode");
353
- };
354
- this.getGeo = async function () {
355
- var result = await platform.callHandler("app.getGeo");
356
- if (result.error) {
357
- throw result.error;
358
- }
359
- return {
360
- lat: result.lat,
361
- lng: result.lng
362
- };
363
- };
364
- this.setTitle = function (title) {
365
- platform.callHandler("app.setTitle", title);
366
- };
367
- this.saveBlob = this._saveBlobAsBase64;
368
- this.saveBase64 = function (base64, filename) {
369
- return platform.callHandler("app.saveBase64", base64, filename);
370
- };
371
- this.vibrate = function (time) {
372
- return platform.callHandler("app.vibrate", time);
373
- };
374
- this.showInDeviceManager = function (deviceId, type) {
375
- return platform.callHandler("app.showInDeviceManager", deviceId, type);
376
- };
377
- this.reloadGroup = function (group) {
378
- return platform.callHandler("app.reloadGroup", group);
379
- };
380
- this.setResult = function (name, value) {
381
- return platform.callHandler("app.setResult", name, value);
382
- };
383
- this.setResultAs = function (name, value, type) {
384
- return platform.callHandler("app.setResultAs", name, value, type);
385
- };
386
- this.setError = function (message) {
387
- return platform.callHandler("app.setError", message);
388
- };
389
- this.setProgress = function (precentage) {
390
- return platform.callHandler("app.setProgress", precentage);
391
- };
392
- this.axios = {
393
- get: function (url, data) {
394
- return platform.callHandler("axios_get", url, data);
395
- },
396
- post: function (url, data) {
397
- return platform.callHandler("axios_post", url, data);
398
- },
399
- getAndSave: function (url, config) {
400
- return platform.callHandler("axios_getAndSave", url, config);
401
- },
402
- getAndPreview: function (url, config) {
403
- if (config == undefined) {
404
- config = {};
405
- }
406
- if (config.preview == undefined) {
407
- config.preview = true;
408
- }
409
- return platform.callHandler("axios_getAndSave", url, config);
410
- },
411
- upload: function (url, option) {
412
- return platform.callHandler("axios_upload", url, option);
413
- },
414
- getAsSse: async function (url, fn, config) {
415
- console.log("getAsSse", url, fn);
416
- var randomId = Math.random().toString(36).substring(2);
417
- that.sseCallbacks[randomId] = fn;
418
- await platform.callHandler("axios_getAsSse", url, config, randomId);
419
- delete that.sseCallbacks[randomId];
420
- },
421
- };
422
- if (
423
- // @ts-ignore
424
- window.flutter_inappwebview != null &&
425
- // @ts-ignore
426
- window.flutter_inappwebview.callHandler != null) {
427
- this.platformReady = Promise.resolve(true);
428
- }
429
- else {
430
- this.platformReady = new Promise((resolve, reject) => {
431
- window.addEventListener("flutterInAppWebViewPlatformReady", function () {
432
- console.log("flutter android/ios platform is ready");
433
- resolve(true);
434
- });
435
- setTimeout(() => {
436
- console.log("flutter android/ios platform is timeout");
437
- reject("timeout");
438
- }, 1500);
439
- });
440
- }
441
- window.addEventListener('message', (event) => {
442
- if (event.data == 'capturePort') {
443
- console.log("capturePort", event);
444
- if (event.ports[0] != null) {
445
- this.messagePort = event.ports[0];
446
- this.messagePort.onmessage = (event) => {
447
- if (event.data.id != undefined) {
448
- var callback = this.sseCallbacks[event.data.id];
449
- callback(event.data.data);
450
- }
451
- };
452
- }
453
- }
454
- else {
455
- console.log("message", event);
456
- }
457
- }, false);
124
+ this.platform = new mobile_platform_1.MobilePlatform();
458
125
  }
459
126
  else {
460
127
  if (this.isLocalDomain(domain)) {
@@ -464,67 +131,10 @@ class Cpzxrobot {
464
131
  else {
465
132
  this.mode = "miniapp_in_web";
466
133
  }
467
- this.setTitle = function (title) {
468
- document.title = title;
469
- };
470
- this.saveBase64 = function (base64, filename) {
471
- //decode base64 to blob
472
- const byteCharacters = atob(base64);
473
- const byteNumbers = new Array(byteCharacters.length);
474
- for (let i = 0; i < byteCharacters.length; i++) {
475
- byteNumbers[i] = byteCharacters.charCodeAt(i);
476
- }
477
- const byteArray = new Uint8Array(byteNumbers);
478
- const blob = new Blob([byteArray], {
479
- type: "application/octet-stream",
480
- });
481
- return this.saveBlob(blob, filename);
482
- };
483
- this.saveBlob = function (blob, filename) {
484
- return new Promise((resolve, reject) => {
485
- try {
486
- const url = URL.createObjectURL(blob);
487
- const a = document.createElement("a");
488
- a.href = url;
489
- a.download = filename;
490
- document.body.appendChild(a);
491
- a.click();
492
- setTimeout(() => {
493
- URL.revokeObjectURL(url);
494
- document.body.removeChild(a);
495
- resolve();
496
- }, 0);
497
- }
498
- catch (error) {
499
- reject(error);
500
- }
501
- });
502
- };
503
- this.getGeo = async function () {
504
- return new Promise((resolve, reject) => {
505
- if (navigator.geolocation) {
506
- navigator.geolocation.getCurrentPosition((position) => {
507
- const lat = position.coords.latitude; // 获取纬度
508
- const lng = position.coords.longitude; // 获取经度
509
- // 完成位置获取,解析 Promise
510
- resolve({ lat, lng });
511
- }, (error) => {
512
- console.log("获取位置信息失败:" + error.message);
513
- // 位置获取失败,拒绝 Promise
514
- reject(error);
515
- });
516
- }
517
- else {
518
- console.log("浏览器不支持获取位置信息");
519
- // 浏览器不支持位置服务,拒绝 Promise
520
- reject(new Error("浏览器不支持获取位置信息"));
521
- }
522
- });
523
- };
524
- this.showInDeviceManager = function (deviceId, type) {
525
- return this.axios.get(`/api/v1/${type}/share/` + deviceId);
526
- };
134
+ this.platform = new web_platform_1.WebPlatform(this.token, this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
527
135
  }
136
+ this.platformReady = this.platform.ready();
137
+ this.axios = this.platform.getAxiosFromMiniApp();
528
138
  }
529
139
  isIosMiniApp(location) {
530
140
  //hostname is 'localhost' and has search params starting with 'mode=ios'
@@ -548,7 +158,7 @@ class Cpzxrobot {
548
158
  }
549
159
  //打开其他小程序
550
160
  openMiniApp(url) {
551
- this._jumpToMiniApp(url);
161
+ this.platform.jumpToMiniApp(url);
552
162
  }
553
163
  setAuth(auth, args) {
554
164
  var logger = (msg, level) => {
@@ -725,7 +335,7 @@ function default_1(args = {
725
335
  // @ts-ignore
726
336
  var instance = window.single_cpzxrobot_instance;
727
337
  if (!instance) {
728
- instance = new Cpzxrobot(args.appCode);
338
+ instance = new Cpzxrobot(args.appCode, args.baseURL, args.selectedFarm, args.selectedUnit);
729
339
  // @ts-ignore
730
340
  window.single_cpzxrobot_instance = instance;
731
341
  instance.setAuth(args.devAuth, {
@@ -733,12 +343,6 @@ function default_1(args = {
733
343
  verbose: args.verbose,
734
344
  disableFactorySelector: (_b = args.disableFactorySelector) !== null && _b !== void 0 ? _b : false,
735
345
  });
736
- if (args.selectedFarm) {
737
- instance.user.selectedFarm = args.selectedFarm;
738
- }
739
- if (args.selectedUnit) {
740
- instance.user.selectedUnit = args.selectedUnit;
741
- }
742
346
  }
743
347
  return instance;
744
348
  }
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MobilePlatform = void 0;
4
+ class MobilePlatform {
5
+ constructor() {
6
+ this.sseCallbacks = {};
7
+ this.token = "";
8
+ this.appCode = "";
9
+ this.baseURL = "";
10
+ // @ts-ignore
11
+ this.platform = window.flutter_inappwebview;
12
+ window.addEventListener('message', (event) => {
13
+ if (event.data == 'capturePort') {
14
+ const port = event.ports[0];
15
+ if (port != null) {
16
+ port.onmessage = (event) => {
17
+ if (event.data.id != undefined) {
18
+ const callback = this.sseCallbacks[event.data.id];
19
+ callback === null || callback === void 0 ? void 0 : callback(event.data.data);
20
+ }
21
+ };
22
+ }
23
+ }
24
+ }, false);
25
+ }
26
+ setSelectedFarm(farm) {
27
+ throw new Error("Method not implemented.");
28
+ }
29
+ setSelectedUnit(unit) {
30
+ this.platform.callHandler("selectUnit", unit).then((_res) => {
31
+ var _a;
32
+ // @ts-ignore
33
+ (_a = window._notifyUnitChanged) === null || _a === void 0 ? void 0 : _a.call(window, unit);
34
+ });
35
+ }
36
+ ready() {
37
+ if (
38
+ // @ts-ignore
39
+ window.flutter_inappwebview != null &&
40
+ // @ts-ignore
41
+ window.flutter_inappwebview.callHandler != null) {
42
+ return Promise.resolve(true);
43
+ }
44
+ else {
45
+ return new Promise((resolve, reject) => {
46
+ window.addEventListener("flutterInAppWebViewPlatformReady", function () {
47
+ console.log("flutter android/ios platform is ready");
48
+ resolve(true);
49
+ });
50
+ setTimeout(() => {
51
+ console.log("flutter android/ios platform is timeout");
52
+ reject("timeout");
53
+ }, 1500);
54
+ });
55
+ }
56
+ }
57
+ getAxiosFromMiniApp() {
58
+ const that = this;
59
+ return {
60
+ get: function (url, data) {
61
+ return that.platform.callHandler("axios_get", url, data);
62
+ },
63
+ post: function (url, data) {
64
+ return that.platform.callHandler("axios_post", url, data);
65
+ },
66
+ getAndSave: function (url, config) {
67
+ return that.platform.callHandler("axios_getAndSave", url, config);
68
+ },
69
+ getAndPreview: function (url, config) {
70
+ if (config == undefined) {
71
+ config = {};
72
+ }
73
+ if (config.preview == undefined) {
74
+ config.preview = true;
75
+ }
76
+ return that.platform.callHandler("axios_getAndSave", url, config);
77
+ },
78
+ upload: function (url, option) {
79
+ return that.platform.callHandler("axios_upload", url, option);
80
+ },
81
+ getAsSse: async function (url, fn, config) {
82
+ var randomId = Math.random().toString(36).substring(2);
83
+ that.sseCallbacks[randomId] = fn;
84
+ console.log("getAsSse", url, fn, randomId);
85
+ await that.platform.callHandler("axios_getAsSse", url, config, randomId);
86
+ delete that.sseCallbacks[randomId];
87
+ },
88
+ };
89
+ }
90
+ async getSelectedFarmFromMiniApp() {
91
+ return this.platform.callHandler("getSelectedFarmFromMiniApp");
92
+ }
93
+ async getSelectedUnitFromMiniApp() {
94
+ return this.platform.callHandler("getSelectedUnitFromMiniApp");
95
+ }
96
+ async jumpToMiniApp(url) {
97
+ return this.platform.callHandler("app.openMiniapp", url);
98
+ }
99
+ async scanQrcode() {
100
+ return this.platform.callHandler("app.scanQrcode");
101
+ }
102
+ setTitle(title) {
103
+ this.platform.callHandler("app.setTitle", title);
104
+ }
105
+ async saveBase64(base64, filename) {
106
+ return this.platform.callHandler("app.saveBase64", base64, filename);
107
+ }
108
+ async saveBlob(blob, filename) {
109
+ const reader = new FileReader();
110
+ return new Promise((resolve, reject) => {
111
+ reader.readAsDataURL(blob);
112
+ reader.onloadend = async () => {
113
+ const base64 = reader.result;
114
+ await this.saveBase64(base64, filename);
115
+ resolve();
116
+ };
117
+ reader.onerror = (err) => {
118
+ reject(err);
119
+ };
120
+ });
121
+ }
122
+ vibrate(time) {
123
+ this.platform.callHandler("app.vibrate", time);
124
+ }
125
+ async showInDeviceManager(deviceId, type) {
126
+ return this.platform.callHandler("app.showInDeviceManager", deviceId, type);
127
+ }
128
+ reloadGroup(group) {
129
+ this.platform.callHandler("app.reloadGroup", group);
130
+ }
131
+ async getGeo() {
132
+ const result = await this.platform.callHandler("app.getGeo");
133
+ if (result.error) {
134
+ throw result.error;
135
+ }
136
+ return {
137
+ lat: result.lat,
138
+ lng: result.lng
139
+ };
140
+ }
141
+ setResult(name, value) {
142
+ this.platform.callHandler("app.setResult", name, value);
143
+ }
144
+ setResultAs(name, value, type) {
145
+ this.platform.callHandler("app.setResultAs", name, value, type);
146
+ }
147
+ setError(message) {
148
+ this.platform.callHandler("app.setError", message);
149
+ }
150
+ setProgress(precentage) {
151
+ this.platform.callHandler("app.setProgress", precentage);
152
+ }
153
+ }
154
+ exports.MobilePlatform = MobilePlatform;