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 <publicmail@armoreddragon.com>
This commit is contained in:
Armored Dragon 2024-05-21 12:19:03 -05:00
parent 7b50f9184f
commit 66fd21777c
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 60 additions and 4 deletions

View file

@ -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!

View file

@ -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
}
}