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( - - - - -