@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.17 → 1.0.0-beta.18

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.
@@ -1,211 +1,211 @@
1
- import './yuntu';
2
-
3
- class YunTuAdapter {
4
- constructor(options) {
5
- // 标志插件是否已初始化
6
- this.isInitialized = false;
7
- this.initializePlugin(options.pluginConfig);
8
- }
9
-
10
- async initializePlugin(pluginConfig) {
11
- try {
12
- const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
13
- ? JSON.stringify(pluginConfig)
14
- : '["localAuthPlugin","myPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin"]';
15
- await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
16
- this.isInitialized = true;
17
- this.plugins = JSON.parse(configToUse);
18
- console.log("Initialized plugins:", this.plugins);
19
- return this.plugins;
20
- } catch (error) {
21
- console.error("Plugin initialization failed:", error);
22
- this.isInitialized = false;
23
- return "Plugin initialization failed:" + error;
24
- }
25
- }
26
-
27
- // 其余代码保持不变
28
- async getPlatform() {
29
- return {
30
- platform: 'Yuntu'
31
- };
32
- }
33
-
34
- async getLocation(options) {
35
- return new Promise((resolve, reject) => {
36
-
37
- if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
38
- window.top.geolocation.getCurrentPosition(
39
- (res) => {
40
- console.log('YunTu: Location obtained', JSON.stringify(res));
41
- resolve(res); // 成功获取位置
42
- },
43
- (err) => {
44
- console.error('YunTu: Failed to obtain location', err);
45
- reject(err); // 获取位置失败
46
- },
47
- options
48
- );
49
- } else {
50
- const errorMessage = 'Geolocation is not initialized or not available';
51
- console.error('YunTu:', errorMessage);
52
- reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
53
- }
54
- });
55
- }
56
-
57
- async openLocation(options) {
58
- return new Promise((resolve, reject) => {
59
- if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
60
- console.log("1")
61
- window.top.geolocation.openLocation(
62
- (res) => {
63
- console.log('YunTu: Open location success', res);
64
- resolve(res); // 成功打开地图
65
- },
66
- (err) => {
67
- console.error('YunTu: Failed to open location', err);
68
- reject(err); // 打开地图失败
69
- },
70
- {
71
- latitude: options.latitude,
72
- longitude: options.longitude,
73
- type: options.type || 'amap' // 默认为高德地图
74
- }
75
- );
76
- } else {
77
- const errorMessage = 'Geolocation is not initialized or not available';
78
- console.error('YunTu:', errorMessage);
79
- reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
80
- }
81
- });
82
- }
83
-
84
- async scanCode(options) {
85
- return new Promise((resolve, reject) => {
86
- if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
87
- window.top.scanCode.startScan(
88
- (res) => {
89
- console.log('YunTu: Scan code success', res);
90
- resolve(res); // 成功获取扫码结果
91
- },
92
- (err) => {
93
- console.error('YunTu: Failed to scan code', err);
94
- reject(err); // 扫码失败
95
- },
96
- options // 传递给扫码方法的选项
97
- );
98
- } else {
99
- const errorMessage = 'ScanCode is not initialized or not available';
100
- console.error('YunTu:', errorMessage);
101
- reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
102
- }
103
- });
104
- }
105
-
106
- async localAuthPlugin(options) {
107
- return new Promise((resolve, reject) => {
108
- if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
109
- window.top.localAuthPlugin.auth(
110
- (res) => {
111
- console.log('YunTu: local auth success', res);
112
- resolve(res); // 成功获取认证结果
113
- },
114
- (err) => {
115
- console.error('YunTu: Failed to local auth', err);
116
- reject(err); // 认证失败
117
- },
118
- options // 传递给认证方法的选项
119
- );
120
- } else {
121
- const errorMessage = 'local auth is not initialized or not available';
122
- console.error('YunTu:', errorMessage);
123
- reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
124
- }
125
- });
126
- }
127
-
128
- async getAvailableBiometrics(options) {
129
- return new Promise((resolve, reject) => {
130
- if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
131
- window.top.localAuthPlugin.getAvailableBiometrics(
132
- (res) => {
133
- console.log('YunTu: Get Available Biometrics', res);
134
- resolve(res); // 成功获取生物认证列表
135
- },
136
- (err) => {
137
- console.error('YunTu: Failed Get Available Biometrics', err);
138
- reject(err); // 获取生物认证列表失败
139
- },
140
- options // 传递给认证方法的选项
141
- );
142
- } else {
143
- const errorMessage = 'local auth is not initialized or not available';
144
- console.error('YunTu:', errorMessage);
145
- reject(new Error(errorMessage));
146
- }
147
- });
148
- }
149
-
150
-
151
- async takePhoto(options) {
152
- console.log('YunTu: Taking photo with options', options);
153
-
154
- return new Promise((resolve, reject) => {
155
- if (window.top.imagePicker) {
156
- const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
157
- const pickerFunction = window.top.imagePicker[sourceType];
158
-
159
- if (typeof pickerFunction === 'function') {
160
- pickerFunction(
161
- (res) => {
162
- console.log('YunTu: Photo selection success', res);
163
- resolve(JSON.parse(res)); // 成功获取照片
164
- },
165
- (err) => {
166
- console.error('YunTu: Failed to select photo', err);
167
- reject(JSON.parse(err)); // 选择照片失败
168
- },
169
- options // 传递给选取照片方法的选项(如果有需要的话)
170
- );
171
- } else {
172
- const errorMessage = `${sourceType} function is not available in ImagePicker`;
173
- console.error('YunTu:', errorMessage);
174
- reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
175
- }
176
- } else {
177
- const errorMessage = 'ImagePicker is not initialized or not available';
178
- console.error('YunTu:', errorMessage);
179
- reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
180
- }
181
- });
182
- };
183
-
184
- async filePreview(options) {
185
- console.log('YunTu: File preview with options', options);
186
-
187
- return new Promise((resolve, reject) => {
188
- if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
189
- window.top.filePreview.openFile(
190
- (res) => {
191
- console.log('YunTu: File preview success', res);
192
- resolve(res); // Successfully previewed the file
193
- },
194
- (err) => {
195
- console.error('YunTu: File preview failed', err);
196
- reject(err); // Failed to preview the file
197
- },
198
- JSON.stringify(options) // Pass the options as a string
199
- );
200
- } else {
201
- const errorMessage = 'FilePreview is not initialized or not available';
202
- console.error('YunTu:', errorMessage);
203
- reject(new Error(errorMessage)); // FilePreview interface is not available
204
- }
205
- });
206
- }
207
-
208
-
209
- }
210
-
211
- export default YunTuAdapter;
1
+ import './yuntu';
2
+
3
+ class YunTuAdapter {
4
+ constructor(options) {
5
+ // 标志插件是否已初始化
6
+ this.isInitialized = false;
7
+ this.initializePlugin(options.pluginConfig);
8
+ }
9
+
10
+ async initializePlugin(pluginConfig) {
11
+ try {
12
+ const configToUse = Array.isArray(pluginConfig) && pluginConfig.length > 0
13
+ ? JSON.stringify(pluginConfig)
14
+ : '["localAuthPlugin","myPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin","imagePickerPlugin"]';
15
+ await yuntuConfig(configToUse); // 确保等待 yuntuConfig 执行完成
16
+ this.isInitialized = true;
17
+ this.plugins = JSON.parse(configToUse);
18
+ console.log("Initialized plugins:", this.plugins);
19
+ return this.plugins;
20
+ } catch (error) {
21
+ console.error("Plugin initialization failed:", error);
22
+ this.isInitialized = false;
23
+ return "Plugin initialization failed:" + error;
24
+ }
25
+ }
26
+
27
+ // 其余代码保持不变
28
+ async getPlatform() {
29
+ return {
30
+ platform: 'Yuntu'
31
+ };
32
+ }
33
+
34
+ async getLocation(options) {
35
+ return new Promise((resolve, reject) => {
36
+
37
+ if (window.top.geolocation && typeof window.top.geolocation.getCurrentPosition === 'function') {
38
+ window.top.geolocation.getCurrentPosition(
39
+ (res) => {
40
+ console.log('YunTu: Location obtained', JSON.stringify(res));
41
+ resolve(res); // 成功获取位置
42
+ },
43
+ (err) => {
44
+ console.error('YunTu: Failed to obtain location', err);
45
+ reject(err); // 获取位置失败
46
+ },
47
+ options
48
+ );
49
+ } else {
50
+ const errorMessage = 'Geolocation is not initialized or not available';
51
+ console.error('YunTu:', errorMessage);
52
+ reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
53
+ }
54
+ });
55
+ }
56
+
57
+ async openLocation(options) {
58
+ return new Promise((resolve, reject) => {
59
+ if (window.top.geolocation && typeof window.top.geolocation.openLocation === 'function') {
60
+ console.log("1")
61
+ window.top.geolocation.openLocation(
62
+ (res) => {
63
+ console.log('YunTu: Open location success', res);
64
+ resolve(res); // 成功打开地图
65
+ },
66
+ (err) => {
67
+ console.error('YunTu: Failed to open location', err);
68
+ reject(err); // 打开地图失败
69
+ },
70
+ {
71
+ latitude: options.latitude,
72
+ longitude: options.longitude,
73
+ type: options.type || 'amap' // 默认为高德地图
74
+ }
75
+ );
76
+ } else {
77
+ const errorMessage = 'Geolocation is not initialized or not available';
78
+ console.error('YunTu:', errorMessage);
79
+ reject(new Error(errorMessage)); // Geolocation 未初始化或不可用
80
+ }
81
+ });
82
+ }
83
+
84
+ async scanCode(options) {
85
+ return new Promise((resolve, reject) => {
86
+ if (window.top.scanCode && typeof window.top.scanCode.startScan === 'function') {
87
+ window.top.scanCode.startScan(
88
+ (res) => {
89
+ console.log('YunTu: Scan code success', res);
90
+ resolve(res); // 成功获取扫码结果
91
+ },
92
+ (err) => {
93
+ console.error('YunTu: Failed to scan code', err);
94
+ reject(err); // 扫码失败
95
+ },
96
+ options // 传递给扫码方法的选项
97
+ );
98
+ } else {
99
+ const errorMessage = 'ScanCode is not initialized or not available';
100
+ console.error('YunTu:', errorMessage);
101
+ reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
102
+ }
103
+ });
104
+ }
105
+
106
+ async localAuthPlugin(options) {
107
+ return new Promise((resolve, reject) => {
108
+ if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.auth === 'function') {
109
+ window.top.localAuthPlugin.auth(
110
+ (res) => {
111
+ console.log('YunTu: local auth success', res);
112
+ resolve(res); // 成功获取认证结果
113
+ },
114
+ (err) => {
115
+ console.error('YunTu: Failed to local auth', err);
116
+ reject(err); // 认证失败
117
+ },
118
+ options // 传递给认证方法的选项
119
+ );
120
+ } else {
121
+ const errorMessage = 'local auth is not initialized or not available';
122
+ console.error('YunTu:', errorMessage);
123
+ reject(new Error(errorMessage)); // ScanCode 未初始化或不可用
124
+ }
125
+ });
126
+ }
127
+
128
+ async getAvailableBiometrics(options) {
129
+ return new Promise((resolve, reject) => {
130
+ if (window.top.localAuthPlugin && typeof window.top.localAuthPlugin.getAvailableBiometrics === 'function') {
131
+ window.top.localAuthPlugin.getAvailableBiometrics(
132
+ (res) => {
133
+ console.log('YunTu: Get Available Biometrics', res);
134
+ resolve(res); // 成功获取生物认证列表
135
+ },
136
+ (err) => {
137
+ console.error('YunTu: Failed Get Available Biometrics', err);
138
+ reject(err); // 获取生物认证列表失败
139
+ },
140
+ options // 传递给认证方法的选项
141
+ );
142
+ } else {
143
+ const errorMessage = 'local auth is not initialized or not available';
144
+ console.error('YunTu:', errorMessage);
145
+ reject(new Error(errorMessage));
146
+ }
147
+ });
148
+ }
149
+
150
+
151
+ async takePhoto(options) {
152
+ console.log('YunTu: Taking photo with options', options);
153
+
154
+ return new Promise((resolve, reject) => {
155
+ if (window.top.imagePicker) {
156
+ const sourceType = options && options.sourceType === 'gallery' ? 'gallery' : 'camera';
157
+ const pickerFunction = window.top.imagePicker[sourceType];
158
+
159
+ if (typeof pickerFunction === 'function') {
160
+ pickerFunction(
161
+ (res) => {
162
+ console.log('YunTu: Photo selection success', res);
163
+ resolve(JSON.parse(res)); // 成功获取照片
164
+ },
165
+ (err) => {
166
+ console.error('YunTu: Failed to select photo', err);
167
+ reject(JSON.parse(err)); // 选择照片失败
168
+ },
169
+ options // 传递给选取照片方法的选项(如果有需要的话)
170
+ );
171
+ } else {
172
+ const errorMessage = `${sourceType} function is not available in ImagePicker`;
173
+ console.error('YunTu:', errorMessage);
174
+ reject(new Error(errorMessage)); // 相应的接口未初始化或不可用
175
+ }
176
+ } else {
177
+ const errorMessage = 'ImagePicker is not initialized or not available';
178
+ console.error('YunTu:', errorMessage);
179
+ reject(new Error(errorMessage)); // ImagePicker 未初始化或不可用
180
+ }
181
+ });
182
+ };
183
+
184
+ async filePreview(options) {
185
+ console.log('YunTu: File preview with options', options);
186
+
187
+ return new Promise((resolve, reject) => {
188
+ if (window.top.filePreview && typeof window.top.filePreview.openFile === 'function') {
189
+ window.top.filePreview.openFile(
190
+ (res) => {
191
+ console.log('YunTu: File preview success', res);
192
+ resolve(res); // Successfully previewed the file
193
+ },
194
+ (err) => {
195
+ console.error('YunTu: File preview failed', err);
196
+ reject(err); // Failed to preview the file
197
+ },
198
+ JSON.stringify(options) // Pass the options as a string
199
+ );
200
+ } else {
201
+ const errorMessage = 'FilePreview is not initialized or not available';
202
+ console.error('YunTu:', errorMessage);
203
+ reject(new Error(errorMessage)); // FilePreview interface is not available
204
+ }
205
+ });
206
+ }
207
+
208
+
209
+ }
210
+
211
+ export default YunTuAdapter;
package/src/sdk/yuntu.js CHANGED
@@ -1,55 +1,55 @@
1
- (function(global) {
2
- global.yuntu = {
3
- config: function (options) {
4
- global.flutter_inappwebview.callHandler(
5
- "yuntu",
6
- "init",
7
- options
8
- );
9
- },
10
- exec: function(plugin, action, successCallback, errorCallback, options) {
11
- global.flutter_inappwebview.callHandler(
12
- plugin,
13
- action,
14
- options
15
- ).then((result) => {
16
- successCallback(result);
17
- }).catch((error) => {
18
- errorCallback(error);
19
- });
20
- }
21
- };
22
-
23
- // 等待一个全局函数或变量加载完成
24
- function waitForGlobalVariableOrFunction(globalName, callHandler) {
25
- return new Promise((resolve, reject) => {
26
- var interval = 1000; // 每1000毫秒检查一次
27
- var timeout = 10000; // 设定最大等待时间 10 秒
28
- var elapsedTime = 0;
29
-
30
- var timer = setInterval(function () {
31
- elapsedTime += interval;
32
- if (global[globalName] && global[globalName][callHandler] !== undefined) {
33
- clearInterval(timer); // 停止定时器
34
- resolve(); // 执行回调函数,表示成功
35
- console.log("yuntu 插件加载成功");
36
- } else if (elapsedTime >= timeout) {
37
- clearInterval(timer); // 停止定时器
38
- console.log("yuntu 插件加载失败");
39
- reject(new Error(`Timeout: ${globalName}.${callHandler} not found within ${timeout}ms`));
40
- }
41
- }, interval);
42
- });
43
- }
44
-
45
- global.yuntuConfig = async function(options) {
46
- try {
47
- await waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler');
48
- global.yuntu.config(options);
49
- } catch (error) {
50
- console.error("yuntuConfig 初始化失败:", error);
51
- throw error; // 如果失败则抛出错误
52
- }
53
- };
54
-
55
- })(window);
1
+ (function(global) {
2
+ global.yuntu = {
3
+ config: function (options) {
4
+ global.flutter_inappwebview.callHandler(
5
+ "yuntu",
6
+ "init",
7
+ options
8
+ );
9
+ },
10
+ exec: function(plugin, action, successCallback, errorCallback, options) {
11
+ global.flutter_inappwebview.callHandler(
12
+ plugin,
13
+ action,
14
+ options
15
+ ).then((result) => {
16
+ successCallback(result);
17
+ }).catch((error) => {
18
+ errorCallback(error);
19
+ });
20
+ }
21
+ };
22
+
23
+ // 等待一个全局函数或变量加载完成
24
+ function waitForGlobalVariableOrFunction(globalName, callHandler) {
25
+ return new Promise((resolve, reject) => {
26
+ var interval = 1000; // 每1000毫秒检查一次
27
+ var timeout = 10000; // 设定最大等待时间 10 秒
28
+ var elapsedTime = 0;
29
+
30
+ var timer = setInterval(function () {
31
+ elapsedTime += interval;
32
+ if (global[globalName] && global[globalName][callHandler] !== undefined) {
33
+ clearInterval(timer); // 停止定时器
34
+ resolve(); // 执行回调函数,表示成功
35
+ console.log("yuntu 插件加载成功");
36
+ } else if (elapsedTime >= timeout) {
37
+ clearInterval(timer); // 停止定时器
38
+ console.log("yuntu 插件加载失败");
39
+ reject(new Error(`Timeout: ${globalName}.${callHandler} not found within ${timeout}ms`));
40
+ }
41
+ }, interval);
42
+ });
43
+ }
44
+
45
+ global.yuntuConfig = async function(options) {
46
+ try {
47
+ await waitForGlobalVariableOrFunction('flutter_inappwebview', 'callHandler');
48
+ global.yuntu.config(options);
49
+ } catch (error) {
50
+ console.error("yuntuConfig 初始化失败:", error);
51
+ throw error; // 如果失败则抛出错误
52
+ }
53
+ };
54
+
55
+ })(window);