diff --git a/applications/armored-chat/armored_chat.js b/applications/armored-chat/armored_chat.js index d750dad..888eb09 100644 --- a/applications/armored-chat/armored_chat.js +++ b/applications/armored-chat/armored_chat.js @@ -33,7 +33,8 @@ ac_tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); app_button = ac_tablet.addButton({ - icon: Script.resolvePath("./img/icon.png"), + icon: Script.resolvePath("./img/icon_white.png"), + activeIcon: Script.resolvePath("./img/icon_black.png"), text: "CHAT", isActive: app_is_visible, }); @@ -69,7 +70,6 @@ visible: app_is_visible, // FIXME Invalid? presentationMode: Desktop.PresentationMode.VIRTUAL, }); - chat_overlay_window.visible = app_is_visible; // The "visible" field in the Desktop.createWindow does not seem to work. Force set it to false chat_overlay_window.closed.connect(toggleMainChatWindow); chat_overlay_window.sendToQml({ url: Script.resolvePath("./index.html") }); @@ -111,7 +111,13 @@ // Save message to our history let saved_message = message; delete saved_message.position; - message_history.push(message); + + saved_message.timeString = new Date().toLocaleTimeString(undefined, { hour12: false }); + saved_message.dateString = new Date().toLocaleDateString(undefined, { + month: "long", + day: "numeric", + }); + message_history.push(saved_message); if (message_history.length > settings.max_history) message_history.shift(); Settings.setValue("ArmoredChat-Messages", message_history); @@ -147,15 +153,26 @@ switch (parsed.setting_name) { case "external_window": - console.log(parsed.setting_value); chat_overlay_window.presentationMode = parsed.setting_value ? Desktop.PresentationMode.NATIVE : Desktop.PresentationMode.VIRTUAL; break; + case "max_history": + let new_history = message_history.splice(0, message_history.length - settings.max_history); + Settings.setValue("ArmoredChat-Messages", new_history); + break; } break; case "initialized": + // https://github.com/overte-org/overte/issues/824 + chat_overlay_window.visible = app_is_visible; // The "visible" field in the Desktop.createWindow does not seem to work. Force set it to the initial state (false) _loadSettings(); break; + case "action": + switch (parsed.action) { + case "clear_history": + Settings.setValue("ArmoredChat-Messages", []); + break; + } } } // @@ -205,10 +222,9 @@ ); } function _loadSettings() { - console.log("Loading config"); settings = Settings.getValue("ArmoredChat-Config", settings); - console.log("\nSettings follow:"); - console.log(JSON.stringify(settings, " ", 4)); + + _emitEvent({ type: "setting_update", setting_name: "max_history", setting_value: Number(settings.max_history) }); // Compact chat if (settings.compact_chat) { @@ -224,7 +240,6 @@ // Refill the history with the saved messages message_history.forEach((message) => { delete message.action; - console.log(`Prefilling ${JSON.stringify(message)}`); _emitEvent({ type: "show_message", ...message }); }); } diff --git a/applications/armored-chat/img/icon.png b/applications/armored-chat/img/icon_black.png similarity index 100% rename from applications/armored-chat/img/icon.png rename to applications/armored-chat/img/icon_black.png diff --git a/applications/armored-chat/img/icon_white.png b/applications/armored-chat/img/icon_white.png new file mode 100644 index 0000000..e29bf99 Binary files /dev/null and b/applications/armored-chat/img/icon_white.png differ diff --git a/applications/armored-chat/index.css b/applications/armored-chat/index.css index 24d86e3..2af882b 100644 --- a/applications/armored-chat/index.css +++ b/applications/armored-chat/index.css @@ -99,6 +99,8 @@ body .page .content.message-list .message .body .image-container img { } body .page .content.message-list .message .embeds { width: 100%; + word-wrap: anywhere; + overflow-x: hidden; overflow-x: hidden; } body .page .content.message-list .message .embeds a { @@ -123,11 +125,19 @@ body .page .content.settings .setting { padding: 0.5rem 0.25rem; box-sizing: border-box; } -body .page .content.settings .setting-toggle input { +body .page .content.settings .setting input { margin: auto 0 auto auto; - width: 20px; height: 20px; } +body .page .content.settings .setting-button input { + width: 100px; +} +body .page .content.settings .setting-value input { + width: 70px; +} +body .page .content.settings .setting-toggle input { + width: 20px; +} body .page .content.settings .setting:nth-child(even) { background-color: #1a1a1a; } diff --git a/applications/armored-chat/index.html b/applications/armored-chat/index.html index 4d43bb3..193b915 100644 --- a/applications/armored-chat/index.html +++ b/applications/armored-chat/index.html @@ -64,6 +64,14 @@ External Window +
+ Erase history + +
+
+ Max history + +
@@ -179,6 +187,16 @@ _emitEvent({ type: "setting_update", setting_name: "external_window", setting_value: external_window }); }); + qs("#erase-history").addEventListener("click", () => { + let response = confirm("Are you sure you want to erase all messages?"); + if (response) _emitEvent({ type: "action", action: "clear_history" }); + // _emitEvent({ type: "setting_update", setting_name: "max_history", setting_value: compact_mode }); + }); + + qs("#max-history").addEventListener("change", () => { + _emitEvent({ type: "setting_update", setting_name: "max_history", setting_value: qs("#max-history").value }); + }); + // TODO: Limit embeds to 3. function _showMessage(message) { var target = message.channel + "-chat"; @@ -217,11 +235,16 @@ // Update template data to message data message_clone.querySelector(".name").innerText = message.displayName; - message_clone.querySelector(".timestamp").innerText = new Date().toLocaleTimeString(undefined, { hour12: false }); - message_clone.querySelector(".timestamp").title = new Date().toLocaleDateString(undefined, { - month: "long", - day: "numeric", - }); + if (!message.timeString) { + message_clone.querySelector(".timestamp").innerText = new Date().toLocaleTimeString(undefined, { hour12: false }); + message_clone.querySelector(".timestamp").title = new Date().toLocaleDateString(undefined, { + month: "long", + day: "numeric", + }); + } else { + message_clone.querySelector(".timestamp").innerText = message.timeString; + message_clone.querySelector(".timestamp").title = message.dateString; + } message_clone.querySelector(".embeds").innerHTML = message_embeds; message_clone.querySelector(".body").innerText = message.message; @@ -246,6 +269,10 @@ qs("#external-window-toggle").checked = true; external_window = true; break; + + case "max_history": + qs(`#max-history`).value = message.setting_value; + break; } } @@ -264,8 +291,10 @@
[NAME]
[TIMESTAMP]
-
[EMBEDS]
-
[CONTENT]
+
+
[EMBEDS]
+
[CONTENT]
+
diff --git a/applications/armored-chat/index.scss b/applications/armored-chat/index.scss index 2a01da4..42df092 100644 --- a/applications/armored-chat/index.scss +++ b/applications/armored-chat/index.scss @@ -107,15 +107,14 @@ body { img { width: auto; height: 100%; - - // max-width: 400px; - // max-height: 300px; } } } .embeds { width: 100%; + word-wrap: anywhere; + overflow-x: hidden; overflow-x: hidden; a { @@ -128,8 +127,6 @@ body { max-height: 300px; img { - // width: auto; - // height: 100%; max-width: 400px; max-height: 300px; } @@ -149,12 +146,25 @@ body { display: flex; padding: 0.5rem 0.25rem; box-sizing: border-box; + + input{ + margin: auto 0 auto auto; + height: 20px; + } + } + .setting-button{ + input { + width: 100px; + } + } + .setting-value{ + input { + width: 70px; + } } .setting-toggle { input { - margin: auto 0 auto auto; width: 20px; - height: 20px; } } .setting:nth-child(even) { diff --git a/applications/metadata.js b/applications/metadata.js index 9d5e6b1..e26114e 100644 --- a/applications/metadata.js +++ b/applications/metadata.js @@ -321,7 +321,7 @@ var metadata = { "applications": "name": "Chat", "description": "Chat application", "jsfile": "armored-chat/armored_chat.js", - "icon": "armored-chat/img/icon.png", + "icon": "armored-chat/img/icon_black.png", "caption": "CHAT" }, {