Skip to content

Commit

Permalink
Some null checking
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jun 21, 2024
1 parent 9289e0d commit bd1900b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Widgets/ActionStack.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

public class AppCenter.ActionStack : Gtk.Box {
private AppCenterCore.Package _package;
public AppCenterCore.Package package {
private AppCenterCore.Package? _package;
public AppCenterCore.Package? package {
get {
return _package;
}
Expand Down Expand Up @@ -170,20 +170,20 @@ public class AppCenter.ActionStack : Gtk.Box {
}
}

private void action_cancelled () {
private void action_cancelled () requires (package != null) {
update_action ();
package.action_cancellable.cancel ();
}

private void launch_package_app () {
private void launch_package_app () requires (package != null) {
try {
package.launch ();
} catch (Error e) {
warning ("Failed to launch %s: %s".printf (package.get_name (), e.message));
}
}

private async void action_clicked () {
private async void action_clicked () requires (package != null) {
if (package.installed && !package.update_available) {
action_button_revealer.reveal_child = false;
} else if (package.update_available) {
Expand Down
7 changes: 6 additions & 1 deletion src/Widgets/HumbleButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class AppCenter.Widgets.HumbleButton : Gtk.Button {
public signal void download_requested ();

public AppCenterCore.Package package { get; set; }
public AppCenterCore.Package? package { get; set; }

private int _amount = 1;
public int amount {
Expand Down Expand Up @@ -79,6 +79,11 @@ public class AppCenter.Widgets.HumbleButton : Gtk.Button {
#endif

clicked.connect (() => {
if (package == null) {
warning ("Humble button with no associated package clicked.");
return;
}

if (amount != 0) {
show_stripe_dialog ();
} else {
Expand Down

0 comments on commit bd1900b

Please sign in to comment.