diff --git a/main.js b/main.js index 6b7dded..1358051 100644 --- a/main.js +++ b/main.js @@ -1,129 +1,136 @@ -"ui"; - 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, -}; +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"); -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`; - }, - }, -}); - -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( - - - - - - - - - - - - - - - - - - - - - - - - -