Private
Public Access
1
0

adds setting screen

This commit is contained in:
2025-05-03 01:11:26 -07:00
parent ef0312ccbd
commit 0f565756df
13 changed files with 316 additions and 77 deletions

View File

@@ -1,8 +1,7 @@
using GLib;
using Gee;
public class Repository : Object
{
public class Repository : DBusServiceBase {
public signal void conversations_updated();
public signal void messages_updated(string conversation_guid);
@@ -15,24 +14,38 @@ public class Repository : Object
}
private static Repository instance = null;
private DBusService.Repository dbus_repository;
private uint dbus_watch_id;
private DBusService.Repository? dbus_repository;
private Repository() {
connect_to_dbus.begin((obj, res) => {
connect_to_dbus.end(res);
});
base();
}
~Repository() {
if (dbus_watch_id > 0) {
Bus.unwatch_name(dbus_watch_id);
}
protected override string get_service_name() {
return "Repository";
}
protected override async Object? get_proxy() throws Error {
dbus_repository = yield Bus.get_proxy(BusType.SESSION, DBUS_NAME, DBUS_PATH);
dbus_repository.get_version(); // Test the connection
return dbus_repository;
}
protected override void setup_signals() {
dbus_repository.conversations_updated.connect(() => {
conversations_updated();
});
dbus_repository.messages_updated.connect((conversation_guid) => {
messages_updated(conversation_guid);
});
// Initial load
conversations_updated();
}
public Conversation[] get_conversations() throws Error {
if (dbus_repository == null) {
throw new Error(1337, 1, "Repository not connected");
if (!is_connected || dbus_repository == null) {
throw create_not_connected_error();
}
var conversations = dbus_repository.get_conversations();
@@ -46,8 +59,8 @@ public class Repository : Object
}
public Message[] get_messages(string conversation_guid, string last_message_id = "") throws Error {
if (dbus_repository == null) {
throw new Error(1337, 1, "Repository not connected");
if (!is_connected || dbus_repository == null) {
throw create_not_connected_error();
}
var messages = dbus_repository.get_messages(conversation_guid, last_message_id);
@@ -61,56 +74,10 @@ public class Repository : Object
}
public string send_message(string conversation_guid, string message) throws Error {
if (dbus_repository == null) {
throw new Error(1337, 1, "Repository not connected");
if (!is_connected || dbus_repository == null) {
throw create_not_connected_error();
}
return dbus_repository.send_message(conversation_guid, message);
}
private async void connect_to_dbus() {
bool connected = false;
const string path = "/net/buzzert/kordophonecd/daemon";
try {
debug("Trying to connect to DBus service at path: %s", path);
dbus_repository = yield Bus.get_proxy(BusType.SESSION,
"net.buzzert.kordophonecd",
path);
// Test the connection
dbus_repository.get_version();
// If we get here, connection succeeded
debug("Connected to DBus service at path: %s", path);
connected = true;
// Listen for updates
dbus_repository.conversations_updated.connect(() => {
conversations_updated();
});
dbus_repository.messages_updated.connect((conversation_guid) => {
messages_updated(conversation_guid);
});
// Initial load
conversations_updated();
} catch (Error e) {
debug("Failed to connect to kordophonecd at %s: %s", path, e.message);
}
if (!connected) {
warning("Failed to connect to kordophonecd on any known path");
// Watch for the service to appear
dbus_watch_id = Bus.watch_name(BusType.SESSION,
"net.buzzert.kordophonecd",
BusNameWatcherFlags.AUTO_START,
() => {
connect_to_dbus.begin();
},
null);
}
}
}