From a0f469eb974e4ccde28da72185fdbf81d4719ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 2 Feb 2023 08:55:16 -0800 Subject: [PATCH] Application: use startup --- src/Application.vala | 68 +++++++++++++++++++++++--------------------- src/MainWindow.vala | 2 -- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index c0f7aff..5453558 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -20,7 +20,6 @@ */ public class Torrential.Application : Gtk.Application { - private MainWindow? window = null; private TorrentManager torrent_manager = null; const OptionEntry[] ENTRIES = { @@ -40,17 +39,36 @@ public class Torrential.Application : Gtk.Application { torrent_manager = new TorrentManager (); } + public override void startup () { + base.startup (); + + Intl.setlocale (LocaleCategory.ALL, ""); + Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + Intl.textdomain (GETTEXT_PACKAGE); + + Gtk.IconTheme.get_default ().add_resource_path ("/com/github/davidmhewitt/torrential"); + + var granite_settings = Granite.Settings.get_default (); + var gtk_settings = Gtk.Settings.get_default (); + + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; + + granite_settings.notify["prefers-color-scheme"].connect (() => { + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; + }); + } + public override void open (File[] files, string hint) { if (files[0].has_uri_scheme ("magnet")) { var magnet = files[0].get_uri (); magnet = magnet.replace ("magnet:///?", "magnet:?"); - if (window != null) { - window.add_magnet (magnet); - } else { + if (active_window == null) { activate (); - window.add_magnet (magnet); } + + ((MainWindow) active_window).add_magnet (magnet); return; } @@ -60,38 +78,24 @@ public class Torrential.Application : Gtk.Application { } activate (); - window.add_files (uris); + ((MainWindow) active_window).add_files (uris); } public override void activate () { - Intl.setlocale (LocaleCategory.ALL, ""); - GLib.Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); - GLib.Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - GLib.Intl.textdomain (GETTEXT_PACKAGE); - - if (window == null) { - window = new MainWindow (this, torrent_manager); + if (active_window == null) { + var window = new MainWindow (this, torrent_manager); add_window (window); } else { - window.present (); + active_window.present (); } - - var granite_settings = Granite.Settings.get_default (); - var gtk_settings = Gtk.Settings.get_default (); - - gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; - - granite_settings.notify["prefers-color-scheme"].connect (() => { - gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; - }); } public override int command_line (GLib.ApplicationCommandLine command_line) { var options = command_line.get_options_dict (); if (options.contains ("quit")) { - if (window != null) { - window.quit (); + if (active_window != null) { + ((MainWindow) active_window).quit (); } } @@ -116,16 +120,16 @@ public class Torrential.Application : Gtk.Application { return Posix.EXIT_SUCCESS; } - public void close_session () { + private void close_session () { torrent_manager.close_session (); } -} -int main (string[] args) { - var app = new Torrential.Application (); - var result = app.run (args); + public static int main (string[] args) { + var app = new Torrential.Application (); + var result = app.run (args); - app.close_session (); + app.close_session (); - return result; + return result; + } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index bf43d77..427bb03 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -71,8 +71,6 @@ public class Torrential.MainWindow : Gtk.ApplicationWindow { this.torrent_manager = torrent_manager; - Gtk.IconTheme.get_default ().add_resource_path ("/com/github/davidmhewitt/torrential"); - settings = new GLib.Settings ("com.github.davidmhewitt.torrential.settings"); set_default_size (