Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat(gtk): remember last opened tab

Zack Bartel7d9723fc7ff6
diff --git a/docs/man/man1/tether-gtk.1.in b/docs/man/man1/tether-gtk.1.in
index 362d28a..a1e381b 100644
--- a/docs/man/man1/tether-gtk.1.in
+++ b/docs/man/man1/tether-gtk.1.in
@@ -4,7 +4,7 @@ tether-gtk \- Graphical interface for Tether
.SH SYNOPSIS
.B tether-gtk
[\fB\-\-tray\fR]
-[\fB\-\-devices\fR | \fB\-\-messages\fR | \fB\-\-notifications\fR]
+[\fB\-\-devices\fR | \fB\-\-messages\fR | \fB\-\-notifications\fR | \fB\-\-contacts\fR | \fB\-\-calls\fR]
[\fB\-\-thread\fR=\fIKEY\fR]
.SH DESCRIPTION
.B tether-gtk
@@ -27,9 +27,11 @@ start it automatically.
Start without showing the window. The application is reachable only from its
tray icon until \fBOpen Tether\fR is chosen.
.TP
-.B \-\-devices\fR, \fB\-\-messages\fR, \fB\-\-notifications
+.B \-\-devices\fR, \fB\-\-messages\fR, \fB\-\-notifications\fR, \fB\-\-contacts\fR, \fB\-\-calls
Open on that tab. When \fBtether-gtk\fR is already running the existing window
-is raised and switched instead of a second one being started.
+is raised and switched instead of a second one being started. Without one of
+these, the tab last open is restored. \fB\-\-calls\fR only applies while call
+control is enabled.
.TP
.B \-\-thread=\fIKEY\fR
Open the messages tab on the conversation with this thread key, for example
@@ -47,6 +49,8 @@ selects the tray icon set:
(default) is monochrome and recolored by the panel,
.B color
is the full-color application icon.
+.B last_view
+(string) is the tab restored on the next start.
.SH SEE ALSO
.BR tether (1),
.BR tetherd (8)
diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp
index 3898622..c9b67de 100644
--- a/src/gtk/main.cpp
+++ b/src/gtk/main.cpp
@@ -19,6 +19,7 @@
#include <string>
#include <tether/crypto.hpp>
#include <tether/i18n.hpp>
+#include <utility>
#include <vector>
namespace {
@@ -31,6 +32,8 @@ namespace {
GtkWidget* g_calls_nav = nullptr;
gboolean g_start_hidden = FALSE;
+ constexpr const char* kViews[] = {"devices", "messages", "notifications", "calls", "contacts"};
+
GtkWidget* g_sidebar = nullptr;
GtkWidget* g_sidebar_toggle = nullptr;
struct NavEntry {
@@ -70,6 +73,8 @@ namespace {
// what the current invocation asked to see
std::string g_requested_view;
std::string g_requested_thread;
+ // calls are hidden until the first bt_status
+ bool g_calls_requested = false;
// Call control is off by default and enabled out of band, so the tab only
// exists once the daemon reports it on.
@@ -79,6 +84,8 @@ namespace {
gtk_widget_set_visible(g_calls_page, enabled);
if (g_calls_nav)
gtk_widget_set_visible(g_calls_nav, enabled);
+ if (std::exchange(g_calls_requested, false) && enabled && g_stack)
+ gtk_stack_set_visible_child_name(GTK_STACK(g_stack), "calls");
if (enabled || !g_stack)
return;
const gchar* name = gtk_stack_get_visible_child_name(GTK_STACK(g_stack));
@@ -86,13 +93,24 @@ namespace {
gtk_stack_set_visible_child_name(GTK_STACK(g_stack), "devices");
}
+ void select_view(const std::string& view) {
+ if (!g_stack)
+ return;
+ if (view == "calls" && g_calls_page && !gtk_widget_get_visible(g_calls_page)) {
+ g_calls_requested = true;
+ return;
+ }
+ g_calls_requested = false;
+ gtk_stack_set_visible_child_name(GTK_STACK(g_stack), view.c_str());
+ }
+
void apply_requested_view() {
if (!g_stack)
return;
if (!g_requested_thread.empty())
g_requested_view = "messages";
if (!g_requested_view.empty())
- gtk_stack_set_visible_child_name(GTK_STACK(g_stack), g_requested_view.c_str());
+ select_view(g_requested_view);
if (!g_requested_thread.empty())
messages_view_open_thread(g_requested_thread);
g_requested_view.clear();
@@ -146,6 +164,10 @@ namespace {
prefs()["window_height"] = height;
}
}
+ if (g_stack) {
+ if (const gchar* view = gtk_stack_get_visible_child_name(GTK_STACK(g_stack)))
+ prefs()["last_view"] = std::string(view);
+ }
messages_view_store_prefs();
}
@@ -444,6 +466,7 @@ namespace {
if (!g_start_hidden)
gtk_widget_show(window);
gtk_stack_set_visible_child_name(GTK_STACK(stack), "devices");
+ select_view(prefs().value("last_view", std::string("devices")));
}
} // namespace
@@ -459,7 +482,7 @@ int main(int argc, char** argv) {
G_OPTION_ARG_NONE,
_("Start hidden in the system tray"),
nullptr);
- for (const char* view : {"devices", "messages", "notifications", "calls", "contacts"}) {
+ for (const char* view : kViews) {
g_application_add_main_option(
G_APPLICATION(app), view, 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, _("Open on this tab"), nullptr);
}
@@ -512,7 +535,7 @@ int main(int argc, char** argv) {
}
if (g_variant_dict_contains(options, "tray"))
g_start_hidden = TRUE;
- for (const char* view : {"devices", "messages", "notifications", "contacts"}) {
+ for (const char* view : kViews) {
if (g_variant_dict_contains(options, view))
g_requested_view = view;
}