diff --git a/main.js b/main.js
index 6b7dded..ab771de 100644
--- a/main.js
+++ b/main.js
@@ -2,48 +2,19 @@
storage = storages.create("mower-ng helper");
-const config_items = {
- wx: 10,
- wy: 10,
- http_proto: "http",
- host: "127.0.0.1",
- port: "58000",
- auto_close: false,
-};
-
-config = {};
-
-Object.entries(config_items).forEach(([key, value]) => {
- config[key + "_"] = storage.get(key, value);
- Object.defineProperty(config, key, {
- get() {
- return this[key + "_"];
- },
- set(new_value) {
- this[key + "_"] = new_value;
- storage.put(key, new_value);
- },
- });
-});
-Object.defineProperties(config, {
- scheduler_url: {
- get() {
- return `${this.http_proto}://${this.host}:${this.port}/scheduler`;
- },
- },
- ws_url: {
- get() {
- ws_proto = this.http_proto == "https" ? "wss" : "ws";
- return `${ws_proto}://${this.host}:${this.port}/ws`;
- },
- },
-});
+wx = storage.get("wx", 10);
+wy = storage.get("wy", 10);
+http_proto = storage.get("http_proto", "http");
+host = storage.get("host", "127.0.0.1");
+port = storage.get("port", "58000");
function save_config() {
- config.http_proto = ui.proto.getText();
- config.host = ui.host.getText();
- config.port = ui.port.getText();
- config.auto_close = ui.auto_close.isChecked();
+ http_proto = ui.proto.getText();
+ host = ui.host.getText();
+ port = ui.port.getText();
+ storage.put("http_proto", http_proto);
+ storage.put("host", host);
+ storage.put("port", port);
}
w = null;
@@ -54,7 +25,7 @@ ui.layout(
-
+
@@ -69,20 +40,16 @@ ui.layout(
-
-
-
-
-
-
+
+
+
);
-ui.proto.setText(config.http_proto);
-ui.host.setText(config.host);
-ui.port.setText(config.port);
-ui.auto_close.setChecked(config.auto_close);
+ui.proto.setText(http_proto);
+ui.host.setText(host);
+ui.port.setText(port);
function toggle_ui(running) {
group_waiting = [ui.proto, ui.host, ui.port, ui.start];
@@ -105,6 +72,7 @@ function toggle_ui(running) {
toggle_ui(false);
ws = null;
+ws_proto = http_proto == "https" ? "wss" : "ws";
reg = /^[0-9].*/;
log = [];
@@ -141,7 +109,9 @@ function time_diff(diff) {
function update_tasks() {
if (w) {
- request = new Request.Builder().url(config.scheduler_url).build();
+ request = new Request.Builder()
+ .url(`${http_proto}://${host}:${port}/scheduler`)
+ .build();
response = client.newCall(request).execute();
scheduler = JSON.parse(response.body().string());
setTimeout(update_tasks, 5000);
@@ -160,7 +130,6 @@ function stop_floaty() {
w.close();
w = null;
}
- scheduler = { idle: false, next_time: null };
stop_ws();
clearInterval(w_timer);
toggle_ui(false);
@@ -221,7 +190,7 @@ ui.start.click(() => {
);
w.setSize(-2, -2);
- w.setPosition(config.wx, config.wy);
+ w.setPosition(wx, wy);
w.container.setOnTouchListener((view, event) => {
switch (event.getAction()) {
@@ -232,11 +201,13 @@ ui.start.click(() => {
case event.ACTION_MOVE:
dx = event.getRawX() - X;
dy = event.getRawY() - Y;
- w.setPosition(config.wx + dx, config.wy + dy);
+ w.setPosition(wx + dx, wy + dy);
return true;
case event.ACTION_UP:
- config.wx += dx;
- config.wy += dy;
+ wx += dx;
+ wy += dy;
+ storage.put("wx", wx);
+ storage.put("wy", wy);
return true;
}
});
@@ -249,7 +220,9 @@ ui.start.click(() => {
stop_ws();
return;
}
- request = new Request.Builder().url(config.ws_url).build();
+ request = new Request.Builder()
+ .url(`${ws_proto}://${host}:${port}/ws`)
+ .build();
ws = client.newWebSocket(
request,
new okhttp3.WebSocketListener({
@@ -280,17 +253,13 @@ ui.start.click(() => {
w_timer = setInterval(() => {
if (scheduler.idle && scheduler.next_time) {
- task_time = new Date(scheduler.next_time);
+ task_time = new Date(scheduler.next_time.substring(0, 19));
next_time = format_time(task_time);
remain_time = time_diff(task_time.getTime() - Date.now());
} else {
next_time = no_time;
remain_time = no_time;
}
- if (config.auto_close && remain_time == no_time) {
- stop_floaty();
- return;
- }
ui.run(() => {
w.next.setText(`下次任务:${next_time}`);
w.remain.setText(`剩余时间:${remain_time}`);
@@ -298,14 +267,7 @@ ui.start.click(() => {
}, 1000);
threads.start(() => {
- try {
- update_tasks();
- } catch {
- ui.run(() => {
- stop_floaty();
- alert("网络连接错误", "请检查设置填写是否正确!");
- });
- }
+ update_tasks();
});
});
diff --git a/project.json b/project.json
index 49ba9b2..b841139 100644
--- a/project.json
+++ b/project.json
@@ -16,5 +16,5 @@
"packageName": "vip.zhaozuohong.mowernghelper",
"scripts": {},
"versionCode": 2,
- "versionName": "1.3.0"
+ "versionName": "1.1.0"
}