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

Refactoring of the whole application #246

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
WIP Part 16: Refactor
  • Loading branch information
Vysp3r committed Dec 31, 2024
commit e6acd7b5f34da0882a3c234b4b2ba51f2bdec849
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
- [ninja](https://github.com/ninja-build/ninja)
- [meson >= 0.62.0](https://github.com/mesonbuild/meson)
- [gtk4](https://gitlab.gnome.org/GNOME/gtk/)
- [libadwaita >= 1.4](https://gitlab.gnome.org/GNOME/libadwaita)
- [libadwaita >= 1.6](https://gitlab.gnome.org/GNOME/libadwaita)
- [json-glib](https://gitlab.gnome.org/GNOME/json-glib)
- [libsoup](https://gitlab.gnome.org/GNOME/libsoup)
- [libarchive](https://github.com/libarchive/libarchive)
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sources = files(
protonplus_deps = [
dependency('gtk4'),
dependency('glib-2.0'),
dependency('libadwaita-1', version: '>= 1.4'),
dependency('libadwaita-1', version: '>= 1.6'),
dependency('json-glib-1.0'),
dependency('libsoup-3.0'),
dependency('gee-0.8'),
Expand Down
62 changes: 32 additions & 30 deletions src/widgets/application.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ProtonPlus.Widgets {
public class Application : Adw.Application {
public static Window window { get; set; }
Adw.AboutDialog about_dialog { get; set; }

construct {
application_id = Constants.APP_ID;
Expand All @@ -24,6 +25,8 @@ namespace ProtonPlus.Widgets {
window = new Window ();
window.initialize ();

init_about_dialog();

init_settings ();

init_shortcuts ();
Expand All @@ -34,6 +37,34 @@ namespace ProtonPlus.Widgets {
window.present ();
}

void init_about_dialog () {
const string[] devs = {
"Charles Malouin (Vysp3r) https://github.com/Vysp3r",
"Johnny Arcitec https://github.com/Arcitec",
"windblows95 https://github.com/windblows95",
null
};

const string[] thanks = {
"GNOME Project https://www.gnome.org/",
"ProtonUp-Qt Project https://davidotek.github.io/protonup-qt/",
"LUG Helper Project https://github.com/starcitizen-lug/lug-helper",
null
};

about_dialog = new Adw.AboutDialog ();
about_dialog.set_application_name (Constants.APP_NAME);
about_dialog.set_application_icon (Constants.APP_ID);
about_dialog.set_version ("v" + Constants.APP_VERSION);
about_dialog.set_comments (_("A modern compatibility tools manager for Linux."));
about_dialog.add_link ("GitHub", "https://github.com/Vysp3r/ProtonPlus");
about_dialog.set_issue_url ("https://github.com/Vysp3r/ProtonPlus/issues/new/choose");
about_dialog.set_copyright ("© 2022-2025 Vysp3r");
about_dialog.set_license_type (Gtk.License.GPL_3_0);
about_dialog.set_developers (devs);
about_dialog.add_credit_section (_("Special thanks to"), thanks);
}

void init_settings () {
var settings = new Settings ("com.vysp3r.ProtonPlus.State");

Expand Down Expand Up @@ -70,36 +101,7 @@ namespace ProtonPlus.Widgets {
}

void show_about_dialog () {
const string[] devs = {
"Charles Malouin (Vysp3r) https://github.com/Vysp3r",
"Johnny Arcitec https://github.com/Arcitec",
"windblows95 https://github.com/windblows95",
null
};

const string[] thanks = {
"GNOME Project https://www.gnome.org/",
"ProtonUp-Qt Project https://davidotek.github.io/protonup-qt/",
"LUG Helper Project https://github.com/starcitizen-lug/lug-helper",
null
};

var about_window = new Adw.AboutWindow ();

about_window.set_application_name (Constants.APP_NAME);
about_window.set_application_icon (Constants.APP_ID);
about_window.set_version ("v" + Constants.APP_VERSION);
about_window.set_comments (_("A modern compatibility tools manager for Linux."));
about_window.add_link ("GitHub", "https://github.com/Vysp3r/ProtonPlus");
about_window.set_issue_url ("https://github.com/Vysp3r/ProtonPlus/issues/new/choose");
about_window.set_copyright ("© 2022-2024 Vysp3r");
about_window.set_license_type (Gtk.License.GPL_3_0);
about_window.set_developers (devs);
about_window.add_credit_section (_("Special thanks to"), thanks);
about_window.set_transient_for (window);
about_window.set_modal (true);

about_window.present ();
about_dialog.present (window);
}
}
}
4 changes: 4 additions & 0 deletions src/widgets/busy-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ namespace ProtonPlus.Widgets {
public virtual void initialize (Models.Release release) {
this.release = release;

header_bar.set_show_end_title_buttons (false);

window_title.set_subtitle (release.displayed_title);
}

public virtual void done (bool success) {
header_bar.set_show_end_title_buttons (true);

if (success) {
count = 5;

refresh_closing_label ();

GLib.Timeout.add_seconds_full (Priority.DEFAULT, 1, () => {
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/busy-dialogs/install-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ namespace ProtonPlus.Widgets.Dialogs {
public override void initialize (Models.Release release) {
base.initialize (release);

window_title.set_title (_("Installing"));
header_bar.set_show_end_title_buttons (true);

window_title.set_title (_("Installing"));

release.notify["progress"].connect (release_progress_changed);
}
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/launcher-box.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace ProtonPlus.Widgets {

public LauncherBox (Models.Launcher launcher) {
this.launcher = launcher;

set_margin_start (15);
set_margin_end (15);
set_margin_bottom (15);

bin_layout = new Gtk.BinLayout ();
set_layout_manager (bin_layout);
Expand Down
14 changes: 7 additions & 7 deletions src/widgets/release-rows/basic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ namespace ProtonPlus.Widgets.ReleaseRows {
}

protected override void remove_button_clicked () {
var message_dialog = new Adw.MessageDialog (Application.window, _("Delete %s").printf (release.title), "%s\n\n%s".printf (_("You're about to remove %s from your system.").printf (release.title), _("Are you sure you want this?")));
var alert_dialog = new Adw.AlertDialog (_("Delete %s").printf (release.title), "%s\n\n%s".printf (_("You're about to remove %s from your system.").printf (release.title), _("Are you sure you want this?")));

message_dialog.add_response ("no", _("No"));
message_dialog.add_response ("yes", _("Yes"));
alert_dialog.add_response ("no", _("No"));
alert_dialog.add_response ("yes", _("Yes"));

message_dialog.set_response_appearance ("no", Adw.ResponseAppearance.DEFAULT);
message_dialog.set_response_appearance ("yes", Adw.ResponseAppearance.DESTRUCTIVE);
alert_dialog.set_response_appearance ("no", Adw.ResponseAppearance.DEFAULT);
alert_dialog.set_response_appearance ("yes", Adw.ResponseAppearance.DESTRUCTIVE);

message_dialog.choose.begin (null, (obj, res) => {
var response = message_dialog.choose.end (res);
alert_dialog.choose.begin (Application.window, null, (obj, res) => {
var response = alert_dialog.choose.end (res);

if (response != "yes")
return;
Expand Down
50 changes: 25 additions & 25 deletions src/widgets/release-rows/steamtinkerlaunch.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ namespace ProtonPlus.Widgets.ReleaseRows {
if (!Utils.System.check_dependency ("xwininfo"))missing_dependencies += "xwininfo\n";

if (missing_dependencies != "") {
var dialog = new Adw.MessageDialog (Widgets.Application.window, _("Missing dependencies!"), "%s\n\n%s\n%s".printf (_("You are missing the following dependencies for %s:").printf (title), missing_dependencies, _("Installation will be canceled.")));
var alert_dialog = new Adw.AlertDialog (_("Missing dependencies!"), "%s\n\n%s\n%s".printf (_("You are missing the following dependencies for %s:").printf (title), missing_dependencies, _("Installation will be canceled.")));

dialog.add_response ("ok", _("OK"));
alert_dialog.add_response ("ok", _("OK"));

dialog.present ();
alert_dialog.present (Widgets.Application.window);

return;
}
Expand All @@ -79,16 +79,16 @@ namespace ProtonPlus.Widgets.ReleaseRows {
var has_external_install = release.detect_external_locations ();

if (has_external_install) {
var dialog = new Adw.MessageDialog (Widgets.Application.window, _("Existing installation of %s").printf (title), "%s\n\n%s".printf (_("It looks like you currently have another version of %s which was not installed by ProtonPlus.").printf (title), _("Do you want to delete it and install %s with ProtonPlus?").printf (title)));
var alert_dialog = new Adw.AlertDialog (_("Existing installation of %s").printf (title), "%s\n\n%s".printf (_("It looks like you currently have another version of %s which was not installed by ProtonPlus.").printf (title), _("Do you want to delete it and install %s with ProtonPlus?").printf (title)));

dialog.add_response ("cancel", _("Cancel"));
dialog.add_response ("ok", _("OK"));
alert_dialog.add_response ("cancel", _("Cancel"));
alert_dialog.add_response ("ok", _("OK"));

dialog.set_response_appearance ("cancel", Adw.ResponseAppearance.DEFAULT);
dialog.set_response_appearance ("ok", Adw.ResponseAppearance.DESTRUCTIVE);
alert_dialog.set_response_appearance ("cancel", Adw.ResponseAppearance.DEFAULT);
alert_dialog.set_response_appearance ("ok", Adw.ResponseAppearance.DESTRUCTIVE);

dialog.choose.begin (null, (obj, res) => {
string response = dialog.choose.end (res);
alert_dialog.choose.begin (Widgets.Application.window, null, (obj, res) => {
string response = alert_dialog.choose.end (res);

if (response != "ok")
return;
Expand Down Expand Up @@ -119,17 +119,17 @@ namespace ProtonPlus.Widgets.ReleaseRows {
protected override void remove_button_clicked () {
var remove_check = new Gtk.CheckButton.with_label (_("Check this to also remove your configuration files."));

var message_dialog = new Adw.MessageDialog (Application.window, _("Delete %s").printf (release.title), "%s\n\n%s".printf (_("You're about to remove %s from your system.").printf (release.title), _("Are you sure you want this?")));
var alert_dialog = new Adw.AlertDialog (_("Delete %s").printf (release.title), "%s\n\n%s".printf (_("You're about to remove %s from your system.").printf (release.title), _("Are you sure you want this?")));

message_dialog.set_extra_child (remove_check);
alert_dialog.set_extra_child (remove_check);

message_dialog.add_response ("no", _("No"));
message_dialog.add_response ("yes", _("Yes"));
alert_dialog.add_response ("no", _("No"));
alert_dialog.add_response ("yes", _("Yes"));

message_dialog.set_response_appearance ("no", Adw.ResponseAppearance.DEFAULT);
message_dialog.set_response_appearance ("yes", Adw.ResponseAppearance.DESTRUCTIVE);
alert_dialog.set_response_appearance ("no", Adw.ResponseAppearance.DEFAULT);
alert_dialog.set_response_appearance ("yes", Adw.ResponseAppearance.DESTRUCTIVE);

message_dialog.response.connect ((response) => {
alert_dialog.response.connect ((response) => {
if (response != "yes")
return;

Expand All @@ -152,7 +152,7 @@ namespace ProtonPlus.Widgets.ReleaseRows {
});
});

message_dialog.present ();
alert_dialog.present (Widgets.Application.window);
}

void upgrade_button_clicked () {
Expand All @@ -175,24 +175,24 @@ namespace ProtonPlus.Widgets.ReleaseRows {
}

protected override void info_button_clicked () {
Adw.MessageDialog? dialog = null;
Adw.AlertDialog? alert_dialog = null;
switch (release.runner.group.launcher.installation_type) {
case Models.Launcher.InstallationTypes.FLATPAK :
var command_label = new Gtk.Label ("flatpak install com.valvesoftware.Steam.Utility.steamtinkerlaunch");
command_label.set_selectable (true);
dialog = new Adw.MessageDialog (Application.window, _("%s is not supported").printf ("Steam Flatpak"), _("To install %s for the %s, please run the following command:").printf (release.title, "Steam Flatpak"));
dialog.set_extra_child (command_label);
alert_dialog = new Adw.AlertDialog ( _("%s is not supported").printf ("Steam Flatpak"), _("To install %s for the %s, please run the following command:").printf (release.title, "Steam Flatpak"));
alert_dialog.set_extra_child (command_label);
break;
case Models.Launcher.InstallationTypes.SNAP:
dialog = new Adw.MessageDialog (Application.window, _("%s is not supported").printf ("Steam Snap"), _("There's currently no known way for us to install %s for the %s.").printf (release.title, "Steam Snap"));
alert_dialog = new Adw.AlertDialog ( _("%s is not supported").printf ("Steam Snap"), _("There's currently no known way for us to install %s for the %s.").printf (release.title, "Steam Snap"));
break;
default:
break;
}
if (dialog != null) {
dialog.add_response ("ok", _("OK"));
if (alert_dialog != null) {
alert_dialog.add_response ("ok", _("OK"));

dialog.present ();
alert_dialog.present (Application.window);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/widgets/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace ProtonPlus.Widgets {
construct {
set_application ((Adw.Application) GLib.Application.get_default ());
set_title (Constants.APP_NAME);
set_resizable (true);

add_action (load_info_box ());
add_action (add_task ());
Expand Down