diff --git a/main.js b/main.js index 1358051..3d24d27 100644 --- a/main.js +++ b/main.js @@ -1,136 +1,129 @@ +"ui"; + storage = storages.create("mower-ng helper"); -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:58000"); +const config_items = { + wx: 10, + wy: 10, + http_proto: "http", + host: "127.0.0.1", + port: "58000", + auto_close: false, +}; -rawInput( - "连接地址(要写http://或https://,不写token)", - `${http_proto}://${host}`, - (url) => { - [http_proto, host] = url.split("://"); - storage.put("http_proto", http_proto); - storage.put("host", host); - } -); +config = {}; -w = floaty.rawWindow( - - - - - - - - - - - -); -w.setSize(-2, -2); -w.exitOnClose(); - -w.setPosition(wx, wy); - -w.container.setOnTouchListener((view, event) => { - switch (event.getAction()) { - case event.ACTION_DOWN: - X = event.getRawX(); - Y = event.getRawY(); - return true; - case event.ACTION_MOVE: - dx = event.getRawX() - X; - dy = event.getRawY() - Y; - w.setPosition(wx + dx, wy + dy); - return true; - case event.ACTION_UP: - wx += dx; - wy += dy; - storage.put("wx", wx); - storage.put("wy", wy); - return true; - } -}); - -w.exit.click(() => { - exit(); -}); - -w.logo.click(() => { - ui.run(() => { - visibility = w.log.visibility == 8 ? 0 : 8; - w.log.visibility = visibility; - w.container.alpha = w.log.visibility == 8 ? 0.6 : 0.8; +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`; + }, + }, +}); + +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(); +} + +w = null; + +ui.layout( + + + + + + + + + + + + + + + + + + + + + + + + +