-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (50 loc) · 1.54 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
import "./lib/zepp/device-polyfill.js";
import { MessageBuilder } from "./lib/zepp/message.js";
import { registerBackHandler } from "./utils/navigation.js";
import { APP_ID } from "./configuration.js";
App({
globalData: {
messageBuilder: null,
preserveData: null,
transitioning: null,
},
onCreate(options) {
console.log('app on create invoke');
// Get App ID
let appId;
if (APP_ID != null) {
appId = APP_ID;
} else {
if (!hmApp.packageInfo) {
throw new Error('Set appId, appId needs to be the same as the configuration in app.json');
}
console.log("calling packageinfo, may crash..");
appId = hmApp.packageInfo().appId;
}
console.log("app id: " + appId);
this.globalData.messageBuilder = new MessageBuilder({ appId });
this.globalData.messageBuilder.connect();
// Set up navigation handler
this.globalData.transitioning = false;
// this.globalData.preserveData = {
// data: null,
// stack: [],
// };
registerBackHandler();
// Keep screen on (600 = 20 minutes)
hmSetting.setBrightScreen(1200);
console.log("uwu init");
},
onDestroy(options) {
console.log('app on destroy invoke');
// Disconnect messageBuilder
this.globalData.messageBuilder.disConnect();
// Destroy global data
this.globalData.messageBuilder = null;
this.globalData.preserveData = null;
this.globalData.transitioning = null;
// Cancel setBrightScreen
hmSetting.setBrightScreenCancel();
console.log("owo deinit");
}
})