-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
211 lines (178 loc) · 5.35 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
const moby_response = document.querySelector("#response");
const icon = document.querySelector("#myimage");
const aboutInfo = document.querySelector("#about");
let token = undefined;
function close_app() {
console.log("Close app");
moby.miniapp.close("close");
}
function pop_app() {
console.log("Pop App");
moby.miniapp.pop(false, "pop");
}
function get_apps() {
console.log("Get installed apps");
moby_response.innerText = "";
moby.miniapp.get_installed_apps()
.then(rv => {
console.log("done");
token = rv;
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error.description;
});
}
function share_link() {
console.log("share link");
moby.share.link('http://google.com')
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function share_text() {
console.log("share text");
moby.share.text('this is text to share')
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function get_firebase_token() {
console.log("get_firebase_token");
moby.firebase.get_token()
.then(rv => {
console.log("done");
token = rv;
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function get_miniapp_info() {
console.log("get_miniapp_info");
moby.info.miniapp()
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function get_mobile_info() {
console.log("get_mobile_info");
moby.info.app()
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function scan_qr() {
console.log("scan_qr");
moby.camera.scan_qr()
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function scan_card() {
console.log("scan_card");
moby.camera.scan_emv()
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function get_geo() {
console.log("get_geo");
moby.geo.get_position()
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
async function show_icon() {
console.log("Show icon");
const miniapp = await moby.info.miniapp();
moby.miniapp.get_app_icon(miniapp.id, 'menu')
.then(rv => {
console.log("done");
var b64encoded = btoa(String.fromCharCode.apply(null, rv));
var datapng = "data:image/png;base64," + b64encoded;
icon.src = datapng;
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
async function open_external_miniapp() {
console.log("open_external_miniapp");
moby.miniapp.open_url("https://landingpage3.bubbleapps.io", "hello from boot")
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
async function show_external_miniapp() {
console.log("show_external_miniapp");
moby.miniapp.show_url("https://landingpage3.bubbleapps.io", "hello from boot")
.then(rv => {
console.log("done");
moby_response.innerText = JSON.stringify(rv);
})
.catch(error => {
console.log("ooops");
moby_response.innerText = error;
});
}
function get_ntf() {
console.log("get_ntf");
const ntf = moby.jsbridge.get_notifications();
moby_response.innerText = JSON.stringify(ntf);
}
async function about() {
const os = moby.jsbridge.getOSType();
if (os === 0 || os === 3) {
aboutInfo.innerText = 'unknown miniapp';
return;
}
// get_ntf();
const miniapp = await moby.info.miniapp();
aboutInfo.innerText = (miniapp.name + ' v' + miniapp.version + '(id: ' + miniapp.id + ')');
}
about();