@doubao-apps/taro-runtime 0.0.31 → 0.0.32

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.
@@ -7,7 +7,7 @@ export { connectSocket, onSocketOpen, onSocketMessage, onSocketError, onSocketCl
7
7
  export { exitMiniProgram, navigateBack, navigateTo, getCurrentPages, reLaunch, redirectTo } from './router/index.js';
8
8
  export { setStorage, setStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, clearStorage, clearStorageSync, getStorageInfo, getStorageInfoSync } from './storage/index.js';
9
9
  export * from './system/index.js';
10
- export { getLocation } from './location/index.js';
10
+ export * from './location/index.js';
11
11
  export { disableAlertBeforeUnload, enableAlertBeforeUnload, hideLoading, hideToast, showActionSheet, showLoading, showModal } from './interaction/index.js';
12
12
  export { showToast } from './show-toast/index.js';
13
13
  export { createMapContext } from './map/index.js';
package/dist/api/index.js CHANGED
@@ -7,7 +7,7 @@ export { connectSocket, onSocketOpen, onSocketMessage, onSocketError, onSocketCl
7
7
  export { exitMiniProgram, navigateBack, navigateTo, getCurrentPages, reLaunch, redirectTo } from './router/index.js';
8
8
  export { setStorage, setStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, clearStorage, clearStorageSync, getStorageInfo, getStorageInfoSync } from './storage/index.js';
9
9
  export * from './system/index.js';
10
- export { getLocation } from './location/index.js';
10
+ export * from './location/index.js';
11
11
  export { disableAlertBeforeUnload, enableAlertBeforeUnload, hideLoading, hideToast, showActionSheet, showLoading, showModal } from './interaction/index.js';
12
12
  export { showToast } from './show-toast/index.js';
13
13
  export { createMapContext } from './map/index.js';
@@ -1,10 +1,32 @@
1
+ import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
1
2
  import type { GetLocationParams } from '@byted-doubao-apps/framework/api';
2
- import type { getLocation as taroGetLocation } from '@tarojs/taro';
3
- type TaroGetLocationOption = Parameters<typeof taroGetLocation>[0];
4
- type TaroGetLocationResult = Awaited<ReturnType<typeof taroGetLocation>>;
3
+ import type Taro from '@tarojs/taro';
4
+ type TaroGetLocationOption = Parameters<typeof Taro.getLocation>[0];
5
+ type TaroGetLocationResult = Awaited<ReturnType<typeof Taro.getLocation>>;
6
+ type TaroChooseLocationOption = Parameters<typeof Taro.chooseLocation>[0];
7
+ type TaroChooseLocationResult = Awaited<ReturnType<typeof Taro.chooseLocation>>;
8
+ type TaroOpenLocationOption = Parameters<typeof Taro.openLocation>[0];
9
+ type TaroOpenLocationResult = Awaited<ReturnType<typeof Taro.openLocation>>;
10
+ type TaroStartLocationUpdateOption = Parameters<typeof Taro.startLocationUpdate>[0];
11
+ type TaroStartLocationUpdateResult = TaroGeneral.CallbackResult;
12
+ type TaroStopLocationUpdateOption = Parameters<typeof Taro.stopLocationUpdate>[0];
13
+ type TaroStopLocationUpdateResult = TaroGeneral.CallbackResult;
14
+ type TaroLocationChangeCallback = Parameters<typeof Taro.onLocationChange>[0];
15
+ type TaroLocationChangeErrorCallback = Parameters<typeof Taro.onLocationChangeError>[0];
5
16
  type RuntimeGetLocationOption = TaroGetLocationOption & Partial<Pick<GetLocationParams, 'source' | 'mode' | 'timeoutMs' | 'maxCacheMs'>> & {
6
17
  cacheTimeout?: number;
7
18
  };
19
+ type RuntimeChooseLocationOption = TaroChooseLocationOption & Partial<Pick<appFrameworkApi.ChooseLocationParams, 'latitude' | 'longitude'>>;
20
+ type RuntimeOpenLocationOption = TaroOpenLocationOption & appFrameworkApi.OpenLocationParams;
21
+ type RuntimeStartLocationUpdateOption = TaroStartLocationUpdateOption & Partial<Pick<appFrameworkApi.StartLocationUpdateParams, 'type'>>;
8
22
  export declare function getLocation(option?: RuntimeGetLocationOption): Promise<TaroGetLocationResult>;
23
+ export declare function chooseLocation(option?: RuntimeChooseLocationOption): Promise<TaroChooseLocationResult>;
24
+ export declare function openLocation(option: RuntimeOpenLocationOption): Promise<TaroOpenLocationResult>;
25
+ export declare function startLocationUpdate(option?: RuntimeStartLocationUpdateOption): Promise<TaroStartLocationUpdateResult>;
26
+ export declare function stopLocationUpdate(option?: TaroStopLocationUpdateOption): Promise<TaroStopLocationUpdateResult>;
27
+ export declare function onLocationChange(callback: TaroLocationChangeCallback): void;
28
+ export declare function offLocationChange(callback?: TaroLocationChangeCallback): void;
29
+ export declare function onLocationChangeError(callback: TaroLocationChangeErrorCallback): void;
30
+ export declare function offLocationChangeError(callback?: TaroLocationChangeErrorCallback): void;
9
31
  export {};
10
32
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,7 @@
1
- import { getLocation as appGetLocation } from '@byted-doubao-apps/framework/api';
2
- import { buildOkCallbackResult, runTaroApi } from '../utils.js';
1
+ import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
+ import { buildOkCallbackResult, runCallbackApi, runTaroApi } from '../utils.js';
3
+ const locationChangeCallbacks = new Map();
4
+ const locationChangeErrorCallbacks = new Map();
3
5
  function resolveMode(option) {
4
6
  if (typeof option.mode === 'number') {
5
7
  return option.mode;
@@ -70,8 +72,104 @@ function buildSuccessResult(response) {
70
72
  }
71
73
  export async function getLocation(option = {}) {
72
74
  return runTaroApi('getLocation', option, async () => {
73
- const response = await appGetLocation(buildFrameworkParams(option));
75
+ const response = await appFrameworkApi.getLocation(buildFrameworkParams(option));
74
76
  return buildSuccessResult(response);
75
77
  });
76
78
  }
79
+ export async function chooseLocation(option = {}) {
80
+ return runTaroApi('chooseLocation', option, async () => {
81
+ const result = await appFrameworkApi.chooseLocation({
82
+ latitude: option.latitude,
83
+ longitude: option.longitude
84
+ });
85
+ return {
86
+ latitude: result.latitude,
87
+ longitude: result.longitude,
88
+ name: result.name,
89
+ address: result.address,
90
+ ...buildOkCallbackResult('chooseLocation')
91
+ };
92
+ });
93
+ }
94
+ export async function openLocation(option) {
95
+ return runCallbackApi('openLocation', option, () => appFrameworkApi.openLocation({
96
+ name: option.name,
97
+ address: option.address,
98
+ scale: option.scale,
99
+ longitude: option.longitude,
100
+ latitude: option.latitude
101
+ }));
102
+ }
103
+ export async function startLocationUpdate(option) {
104
+ return runCallbackApi('startLocationUpdate', option, () => appFrameworkApi.startLocationUpdate({
105
+ type: option?.type
106
+ }));
107
+ }
108
+ export async function stopLocationUpdate(option) {
109
+ return runCallbackApi('stopLocationUpdate', option, () => appFrameworkApi.stopLocationUpdate({}));
110
+ }
111
+ export function onLocationChange(callback) {
112
+ if (typeof callback !== 'function' || locationChangeCallbacks.has(callback)) {
113
+ return;
114
+ }
115
+ const appCallback = (event) => {
116
+ callback({
117
+ latitude: event.latitude,
118
+ longitude: event.longitude,
119
+ speed: event.speed,
120
+ accuracy: event.accuracy,
121
+ altitude: event.altitude,
122
+ verticalAccuracy: event.verticalAccuracy,
123
+ horizontalAccuracy: event.horizontalAccuracy,
124
+ city: event.city
125
+ });
126
+ };
127
+ appFrameworkApi.onLocationChange(appCallback);
128
+ locationChangeCallbacks.set(callback, () => appFrameworkApi.offLocationChange(appCallback));
129
+ }
130
+ export function offLocationChange(callback) {
131
+ if (typeof callback === 'function') {
132
+ const unregister = locationChangeCallbacks.get(callback);
133
+ if (!unregister) {
134
+ return;
135
+ }
136
+ unregister();
137
+ locationChangeCallbacks.delete(callback);
138
+ return;
139
+ }
140
+ if (callback !== undefined) {
141
+ return;
142
+ }
143
+ locationChangeCallbacks.forEach((unregister) => unregister());
144
+ locationChangeCallbacks.clear();
145
+ }
146
+ export function onLocationChangeError(callback) {
147
+ if (typeof callback !== 'function' || locationChangeErrorCallbacks.has(callback)) {
148
+ return;
149
+ }
150
+ const appCallback = (event) => {
151
+ callback({
152
+ errMsg: event.errMsg,
153
+ errCode: event.errCode
154
+ });
155
+ };
156
+ appFrameworkApi.onLocationChangeError(appCallback);
157
+ locationChangeErrorCallbacks.set(callback, () => appFrameworkApi.offLocationChangeError(appCallback));
158
+ }
159
+ export function offLocationChangeError(callback) {
160
+ if (typeof callback === 'function') {
161
+ const unregister = locationChangeErrorCallbacks.get(callback);
162
+ if (!unregister) {
163
+ return;
164
+ }
165
+ unregister();
166
+ locationChangeErrorCallbacks.delete(callback);
167
+ return;
168
+ }
169
+ if (callback !== undefined) {
170
+ return;
171
+ }
172
+ locationChangeErrorCallbacks.forEach((unregister) => unregister());
173
+ locationChangeErrorCallbacks.clear();
174
+ }
77
175
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { getAppBaseInfoSync, getMenuButtonBoundingClientRect as appGetMenuButtonBoundingClientRect, getSystemSetting as appGetSystemSetting, getWindowInfoSync, makePhoneCall as appMakePhoneCall, getNetworkType as appGetNetworkType, onNetworkStatusChange as appOnNetworkStatusChange, getScreenBrightness as appGetScreenBrightness, setClipboardData as appSetClipboardData, onKeyboardHeightChange as appOnKeyboardHeightChange } from '@byted-doubao-apps/framework/api';
1
+ import { getAppBaseInfoSync, getDeviceInfoSync as appGetDeviceInfoSync, getMenuButtonBoundingClientRect as appGetMenuButtonBoundingClientRect, getSystemSetting as appGetSystemSetting, getWindowInfoSync, makePhoneCall as appMakePhoneCall, getNetworkType as appGetNetworkType, onNetworkStatusChange as appOnNetworkStatusChange, getScreenBrightness as appGetScreenBrightness, setClipboardData as appSetClipboardData, onKeyboardHeightChange as appOnKeyboardHeightChange } from '@byted-doubao-apps/framework/api';
2
2
  import { buildFailCallbackResult, emitFailure, runCallbackApi, runTaroApi } from '../utils.js';
3
3
  const networkStatusChangeCallbacks = new Map();
4
4
  function buildVibrateShortParams(option) {
@@ -40,14 +40,16 @@ export function getAppAuthorizeSetting() {
40
40
  };
41
41
  }
42
42
  export function getDeviceInfo() {
43
+ const result = appGetDeviceInfoSync();
43
44
  return {
44
- deviceAbi: '',
45
- benchmarkLevel: -1,
46
- brand: '',
47
- model: '',
48
- system: '',
49
- platform: '',
50
- CPUType: ''
45
+ abi: result.abi,
46
+ deviceAbi: result.deviceAbi ?? '',
47
+ benchmarkLevel: result.benchmarkLevel,
48
+ brand: result.brand,
49
+ model: result.model,
50
+ system: result.system,
51
+ platform: result.platform,
52
+ CPUType: result.cpuType ?? ''
51
53
  };
52
54
  }
53
55
  export function getAppBaseInfo() {
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "access": "public",
38
38
  "registry": "https://registry.npmjs.org/"
39
39
  },
40
- "version": "0.0.31",
40
+ "version": "0.0.32",
41
41
  "scripts": {
42
42
  "dev": "npm run build -- -w",
43
43
  "build": "rimraf dist bundle && tsc -p tsconfig.build.json",