Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application: use startup #177

Merged
merged 1 commit into from Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 36 additions & 32 deletions src/Application.vala
Expand Up @@ -20,7 +20,6 @@
*/

public class Torrential.Application : Gtk.Application {
private MainWindow? window = null;
private TorrentManager torrent_manager = null;

const OptionEntry[] ENTRIES = {
Expand All @@ -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;
}

Expand All @@ -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 ();
}
}

Expand All @@ -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;
}
}
2 changes: 0 additions & 2 deletions src/MainWindow.vala
Expand Up @@ -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 (
Expand Down