summaryrefslogtreecommitdiff
path: root/src/window.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.vala')
-rw-r--r--src/window.vala96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/window.vala b/src/window.vala
new file mode 100644
index 0000000..bea5408
--- /dev/null
+++ b/src/window.vala
@@ -0,0 +1,96 @@
+/* window.vala
+
+ *
+ * Copyright 2023 Mubashshir
+
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace JadupcSupport
+{
+
+ [GtkTemplate (ui = "/com/jadupc/support/ui/window.ui")]
+ public class Window : Gtk.ApplicationWindow
+ {
+ [GtkChild] private unowned Gtk.Label session;
+ [GtkChild] private unowned Gtk.InfoBar infobar;
+ [GtkChild] private unowned Gtk.Stack view;
+ [GtkChild] private unowned Vte.Terminal terminal;
+ [GtkChild] private unowned Gtk.Button sessionbutton;
+ [GtkChild] private unowned Gtk.Label infobarText;
+ [GtkChild] private unowned Gtk.Image infobarIcon;
+
+ public Window (Gtk.Application app)
+ {
+ var lang = Environment.get_variable("LANG"); // fix locale for Vte.Terminal
+ Environment.set_variable("LANG", "en_US", true); // fix locale for Vte.Terminal
+ Object (application: app);
+ Environment.set_variable("LANG", lang, true); // fix locale for Vte.Terminal
+
+ utils.realize_all(this); // Realize all children to pacify Gtk.
+ icon_name = "com.jadupc.support";
+
+ infobar.response.connect(() => infobar.set_revealed(false));
+ sessionbutton.clicked.connect(() => {
+ if (infobar.revealed)
+ infobar.revealed = false;
+ session.label = _("Connecting...");
+ view.visible_child_name = "inprogress";
+ Timeout.add_once(3000, () => on_session_connect("test@tty.jadupc.com"));
+ });
+
+ terminal.child_exited.connect(status => {
+ if(status > 0)
+ show_in_infobar(ERROR, _("Error: %s").printf(utils.strret(status)));
+ reset_window();
+ });
+
+ show_in_infobar(INFO, _("Welcome to JaduPc Remote Support Console!"));
+ }
+
+ internal void show_in_infobar(Gtk.MessageType type, string message)
+ {
+ infobarIcon.icon_name = utils.get_message_icon(type);
+
+ infobarText.label = message;
+ infobar.message_type = type;
+ infobar.revealed = true;
+ }
+
+ private void reset_window()
+ {
+ session.label = _("Disconnected...");
+ Timeout.add_once(view.transition_duration, () => terminal.reset(true, true));
+ view.visible_child_name = "session";
+ }
+
+ private void spawn_async_cb(Vte.Terminal term, Pid pid, Error? error)
+ {
+ if(pid > 1) return;
+ reset_window();
+ show_in_infobar(ERROR, error.message);
+ }
+
+ private void on_session_connect(string url)
+ {
+ session.label = @"<a href=\"ssh://$url\">ssh://$url</a>";
+ view.visible_child_name = "terminal";
+ terminal.has_focus = true;
+
+ terminal.spawn_async(Vte.PtyFlags.DEFAULT, "~", {"sh"}, {@"PATH=$(Config.SECURE_PATH)"},
+ SpawnFlags.SEARCH_PATH_FROM_ENVP, null, -1, null, spawn_async_cb);
+ }
+ }
+}