From 66fd21777cf62318e328cf6147a901a116f33f4e Mon Sep 17 00:00:00 2001 From: Armored Dragon Date: Tue, 21 May 2024 12:19:03 -0500 Subject: [PATCH] Maximum messages setting. Settings now initialize properly. Settings now save properly. Removed compact_chat setting as deprecated. Added spacing between settings. Message history now prunes itself if the number of messages exceeds maximum. Signed-off-by: Armored Dragon --- .../armored-chat/armored_chat.js | 21 +++++++-- .../armored-chat/armored_chat.qml | 43 ++++++++++++++++++- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/scripts/communityScripts/armored-chat/armored_chat.js b/scripts/communityScripts/armored-chat/armored_chat.js index 4bc75f9345..4130c05d2f 100644 --- a/scripts/communityScripts/armored-chat/armored_chat.js +++ b/scripts/communityScripts/armored-chat/armored_chat.js @@ -12,8 +12,8 @@ var app_is_visible = false; var settings = { - compact_chat: false, external_window: false, + maximum_messages: 200, }; // Global vars @@ -123,8 +123,9 @@ day: "numeric", }); message_history.push(saved_message); - if (message_history.length > settings.max_history) + while (message_history.length > settings.maximum_messages) { message_history.shift(); + } Settings.setValue("ArmoredChat-Messages", message_history); } @@ -145,6 +146,9 @@ ? Desktop.PresentationMode.NATIVE : Desktop.PresentationMode.VIRTUAL; break; + case "maximum_messages": + // Do nothing + break; } break; @@ -204,12 +208,23 @@ }, 1500); } function _loadSettings() { + settings = Settings.getValue("ArmoredChat-Config", settings); + + // Load message history message_history.forEach((message) => { delete message.action; _emitEvent({ type: "show_message", ...message }); }); + + // Send current settings to the app + _emitEvent({ type: "initial_settings", settings: settings }); + + console.log(`\n\n\n` + JSON.stringify(settings)); + } + function _saveSettings() { + console.log("Saving config"); + Settings.setValue("ArmoredChat-Config", settings); } - function _saveSettings() {} /** * Emit a packet to the HTML front end. Easy communication! diff --git a/scripts/communityScripts/armored-chat/armored_chat.qml b/scripts/communityScripts/armored-chat/armored_chat.qml index 9b313162fe..84b8ed5d01 100644 --- a/scripts/communityScripts/armored-chat/armored_chat.qml +++ b/scripts/communityScripts/armored-chat/armored_chat.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 +import controlsUit 1.0 as HifiControlsUit Rectangle { color: Qt.rgba(0.1,0.1,0.1,1) @@ -18,6 +19,7 @@ Rectangle { Timer { interval: 100 running: true + repeat: false onTriggered: { toScript({type: "initialized"}) } @@ -26,6 +28,7 @@ Rectangle { // toScript({type: "initialized"}) // } + // User view Item { anchors.fill: parent @@ -233,8 +236,9 @@ Rectangle { width: parent.width - 10 height: parent.height - 10 anchors.centerIn: parent - spacing: 0 + spacing: 10 + // External Window Rectangle { width: parent.width height: 40 @@ -248,6 +252,7 @@ Rectangle { } CheckBox{ + id: s_external_window anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter @@ -257,6 +262,38 @@ Rectangle { } } + // Maximum saved messages + Rectangle { + width: parent.width + height: 40 + color: "transparent" + + Text{ + text: "Maximum saved messages" + color: "white" + font.pointSize: 12 + anchors.verticalCenter: parent.verticalCenter + } + + + HifiControlsUit.SpinBox { + id: s_maximum_messages + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + decimals: 0 + width: 100 + height: parent.height + realFrom: 1 + realTo: 1000 + backgroundColor: "#cccccc" + + onValueChanged: { + toScript({type: 'setting_change', setting: 'maximum_messages', value: value}) + } + } + } + + // Erase History Rectangle { width: parent.width height: 40 @@ -285,6 +322,7 @@ Rectangle { } + // Templates Component { id: template_chat_message @@ -455,6 +493,9 @@ Rectangle { case "clear_messages": local.clear() domain.clear() + case "initial_settings": + if (message.settings.external_window) s_external_window.checked = true + if (message.settings.maximum_messages) s_maximum_messages.value = message.settings.maximum_messages } }