-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Package.vala
959 lines (801 loc) · 28.8 KB
/
Package.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/*-
* Copyright (c) 2014–2018 elementary, Inc. (https://elementary.io)
*
* 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/>.
*
* Authored by: Corentin Noël <[email protected]>
*/
public errordomain PackageLaunchError {
DESKTOP_ID_NOT_FOUND,
APP_INFO_NOT_FOUND
}
public errordomain PackageUninstallError {
APP_STATE_NOT_INSTALLED
}
public class AppCenterCore.PackageDetails : Object {
public string? name { get; set; }
public string? description { get; set; }
public string? summary { get; set; }
public string? version { get; set; }
}
public class AppCenterCore.Package : Object {
public const string APPCENTER_PACKAGE_ORIGIN = "appcenter-bionic-main";
// We stopped using this origin in elementary OS 5.1, references to this can be removed
// after everyone has had chance to update their appstream-data-pantheon package
private const string DEPRECATED_ELEMENTARY_STABLE_PACKAGE_ORIGIN = "stable-bionic-main";
private const string ELEMENTARY_STABLE_PACKAGE_ORIGIN = "elementary-stable-bionic-main";
/* Note: These are just a stopgap, and are not a replacement for a more
* fleshed out parental control system. We assume any of these "moderate"
* or above is considered explicit for our naive warning.
*
* See https://hughsie.github.io/oars/generate.html for ratings.
*/
private const string[] EXPLICIT_TAGS = {
"violence-realistic",
"violence-bloodshed",
"violence-sexual",
"drugs-narcotics",
"sex-nudity",
"sex-themes",
"sex-prostitution",
"language-profanity",
"language-humor",
"language-discrimination"
};
public signal void changing (bool is_changing);
/**
* This signal is likely to be fired from a non-main thread. Ensure any UI
* logic driven from this runs on the GTK thread
*/
public signal void info_changed (ChangeInformation.Status status);
public enum State {
NOT_INSTALLED,
INSTALLED,
INSTALLING,
UPDATE_AVAILABLE,
UPDATING,
REMOVING
}
public const string OS_UPDATES_ID = "xxx-os-updates";
public const string LOCAL_ID_SUFFIX = ".appcenter-local";
public const string DEFAULT_PRICE_DOLLARS = "1";
public AppStream.Component component { get; protected set; }
public ChangeInformation change_information { public get; private set; }
public GLib.Cancellable action_cancellable { public get; private set; }
public State state { public get; private set; default = State.NOT_INSTALLED; }
public Backend backend { public get; construct; }
public double progress {
get {
return change_information.progress;
}
}
private bool _installed = false;
public bool installed {
get {
if (component.get_id () == OS_UPDATES_ID) {
return true;
}
return _installed;
}
}
public void mark_installed () {
_installed = true;
update_state ();
}
public void clear_installed () {
_installed = false;
update_state ();
}
public bool update_available {
get {
return state == State.UPDATE_AVAILABLE;
}
}
/**
* The component ID of the package with the .desktop suffix removed if it exists.
* This is used for comparing two packages to see if they have a matching ID
*/
private string? _component_id = null;
public string normalized_component_id {
get {
if (_component_id != null) {
return _component_id;
}
_component_id = component.id;
if (_component_id.has_suffix (".desktop")) {
// ".desktop" is always 8 bytes in UTF-8 so we can just chop 8 bytes off the end
_component_id = _component_id.substring (0, _component_id.length - 8);
}
return _component_id;
}
}
public bool should_pay {
get {
if (!is_native || is_os_updates) {
return false;
}
if (get_payments_key () == null || get_suggested_amount () == "0") {
return false;
}
if (component.get_id () in AppCenter.App.settings.get_strv ("paid-apps")) {
return false;
}
var newest_release = get_newest_release ();
if (newest_release != null && newest_release.get_urgency () == AppStream.UrgencyKind.CRITICAL) {
return false;
}
return true;
}
}
public bool should_nag_update {
get {
return update_available && should_pay;
}
}
public bool is_updating {
get {
return state == State.UPDATING;
}
}
public bool changes_finished {
get {
return change_information.status == ChangeInformation.Status.FINISHED;
}
}
public bool is_os_updates {
get {
return component.id == OS_UPDATES_ID;
}
}
public bool is_driver {
get {
return component.get_kind () == AppStream.ComponentKind.DRIVER;
}
}
public bool is_font {
get {
return component.get_kind () == AppStream.ComponentKind.FONT;
}
}
public bool is_local {
get {
return component.get_id ().has_suffix (LOCAL_ID_SUFFIX);
}
}
public bool is_shareable {
get {
return is_native && !is_driver && !is_os_updates;
}
}
public bool is_native {
get {
switch (component.get_origin ()) {
case APPCENTER_PACKAGE_ORIGIN:
case DEPRECATED_ELEMENTARY_STABLE_PACKAGE_ORIGIN:
case ELEMENTARY_STABLE_PACKAGE_ORIGIN:
return true;
default:
return false;
}
}
}
public bool is_compulsory {
get {
unowned string? _current = Environment.get_variable ("XDG_SESSION_DESKTOP");
if (_current == null) {
return false;
}
string current = _current.down ();
unowned GenericArray<string> compulsory = component.get_compulsory_for_desktops ();
for (int i = 0; i < compulsory.length; i++) {
if (current == compulsory[i].down ()) {
return true;
}
}
return false;
}
}
private bool _explicit = false;
private bool _check_explicit = true;
public bool is_explicit {
get {
if (_check_explicit) {
_check_explicit = false;
var ratings = component.get_content_ratings ();
for (int i = 0; i < ratings.length; i++) {
var rating = ratings[i];
foreach (string tag in EXPLICIT_TAGS) {
var rating_value = rating.get_value (tag);
if (rating_value > AppStream.ContentRatingValue.MILD) {
_explicit = true;
return _explicit;
}
}
}
}
return _explicit;
}
}
public bool is_flatpak {
get {
return (backend is FlatpakBackend)
|| change_information.updatable_packages.contains (FlatpakBackend.get_default ());
}
}
private string? _author = null;
public string author {
get {
if (_author != null) {
return _author;
}
_author = component.developer_name;
if (_author == null) {
var project_group = component.project_group;
if (project_group != null) {
_author = project_group;
}
}
return _author;
}
}
private string? _author_title = null;
public string author_title {
get {
if (_author_title != null) {
return _author_title;
}
_author_title = author;
if (_author_title == null) {
_author_title = _("%s Developers").printf (get_name ());
}
return _author_title;
}
}
public bool is_plugin {
get {
return component.get_kind () == AppStream.ComponentKind.ADDON;
}
}
public Gee.Collection<Package> origin_packages {
owned get {
return BackendAggregator.get_default ().get_packages_for_component_id (component.get_id ());
}
}
public bool has_multiple_origins {
get {
return origin_packages.size > 1;
}
}
public string origin_description {
owned get {
unowned string origin = component.get_origin ();
if (backend is PackageKitBackend) {
if (origin == APPCENTER_PACKAGE_ORIGIN) {
return _("AppCenter");
} else if (origin == DEPRECATED_ELEMENTARY_STABLE_PACKAGE_ORIGIN || origin == ELEMENTARY_STABLE_PACKAGE_ORIGIN) {
return _("elementary Updates");
} else if (origin.has_prefix ("ubuntu-")) {
return _("Ubuntu (non-curated)");
}
} else if (backend is FlatpakBackend) {
var fp_package = this as FlatpakPackage;
if (fp_package != null && fp_package.installation == FlatpakBackend.system_installation) {
return _("%s (system-wide)").printf (origin);
}
return origin;
} else if (backend is UbuntuDriversBackend) {
return _("Ubuntu Drivers");
}
return _("Unknown Origin (non-curated)");
}
}
public int origin_score {
get {
int score = 0;
if (installed) {
score += 10;
}
if (is_native) {
score += 5;
}
if (is_flatpak) {
score++;
var fp_package = this as FlatpakPackage;
if (fp_package != null && fp_package.installation == FlatpakBackend.user_installation) {
score++;
}
}
return score;
}
}
public string hash {
owned get {
string key = "";
if (backend is FlatpakBackend) {
var fp_package = this as FlatpakPackage;
if (fp_package.installation != null && fp_package.installation == FlatpakBackend.system_installation) {
key += "system/";
} else {
key += "user/";
}
}
key += component.get_origin () + "/";
key += component.get_id ();
return key;
}
}
private string? name = null;
public string? description = null;
private string? summary = null;
private string? color_primary = null;
private string? color_primary_text = null;
private string? payments_key = null;
private string? suggested_amount = null;
private string? _latest_version = null;
public string? latest_version {
private get { return _latest_version; }
internal set { _latest_version = convert_version (value); }
}
private PackageDetails? backend_details = null;
private AppInfo? app_info;
private bool app_info_retrieved = false;
construct {
change_information = new ChangeInformation ();
change_information.status_changed.connect (() => info_changed (change_information.status));
action_cancellable = new GLib.Cancellable ();
}
public Package (Backend backend, AppStream.Component component) {
Object (backend: backend, component: component);
}
public void replace_component (AppStream.Component component) {
name = null;
description = null;
summary = null;
color_primary = null;
color_primary_text = null;
payments_key = null;
suggested_amount = null;
_author = null;
_author_title = null;
backend_details = null;
// The version on a PackageKit package comes from the package not AppStream, so only reset the version
// on other backends
if (!(backend is PackageKitBackend)) {
_latest_version = null;
}
this.component = component;
}
public void update_state () {
State new_state;
if (installed) {
if (change_information.has_changes ()) {
new_state = State.UPDATE_AVAILABLE;
} else {
new_state = State.INSTALLED;
}
} else {
new_state = State.NOT_INSTALLED;
}
// Only trigger a notify if the state has changed, quite a lot of things listen to this
if (state != new_state) {
state = new_state;
}
}
/**
* Instructs the backend to update this package
*
* @refresh_updates_after: Whether to run the check for updates (and update the badges etc...) after
* this method succeeds. This is fine after updating a single package, but for efficiency, it's better to
* do this only once at the end of updating a batch of packages, so this should be set to false if updating
* multiple packages in a loop.
*
*/
public async bool update (bool refresh_updates_after = true) throws GLib.Error {
if (state != State.UPDATE_AVAILABLE) {
return false;
}
var success = yield perform_operation (State.UPDATING, State.INSTALLED, State.UPDATE_AVAILABLE);
if (success && refresh_updates_after) {
unowned Client client = Client.get_default ();
yield client.refresh_updates ();
}
return success;
}
public async bool install () {
if (state != State.NOT_INSTALLED) {
return false;
}
try {
bool success = yield perform_operation (State.INSTALLING, State.INSTALLED, State.NOT_INSTALLED);
if (success) {
var client = AppCenterCore.Client.get_default ();
client.operation_finished (this, State.INSTALLING, null);
}
return success;
} catch (Error e) {
var client = AppCenterCore.Client.get_default ();
client.operation_finished (this, State.INSTALLING, e);
return false;
}
}
public async bool uninstall () throws Error {
// We possibly don't know if this package is installed or not yet, so trigger that check first
_installed = yield backend.is_package_installed (this);
update_state ();
if (state == State.INSTALLED || state == State.UPDATE_AVAILABLE) {
try {
return yield perform_operation (State.REMOVING, State.NOT_INSTALLED, state);
} catch (Error e) {
throw e;
}
}
throw new PackageUninstallError.APP_STATE_NOT_INSTALLED (_("Application state not set as installed in AppCenter for package: %s".printf (get_name ())));
}
public void launch () throws Error {
if (app_info == null) {
throw new PackageLaunchError.APP_INFO_NOT_FOUND ("AppInfo not found for package: %s".printf (get_name ()));
}
try {
app_info.launch (null, null);
} catch (Error e) {
throw e;
}
}
private async bool perform_operation (State performing, State after_success, State after_fail) throws GLib.Error {
bool success = false;
prepare_package_operation (performing);
try {
success = yield perform_package_operation ();
} catch (GLib.Error e) {
warning ("Operation failed for package %s - %s", get_name (), e.message);
throw e;
} finally {
clean_up_package_operation (success, after_success, after_fail);
}
return success;
}
private void prepare_package_operation (State initial_state) {
changing (true);
action_cancellable.reset ();
change_information.start ();
state = initial_state;
}
private async bool perform_package_operation () throws GLib.Error {
ChangeInformation.ProgressCallback cb = change_information.callback;
var client = AppCenterCore.Client.get_default ();
switch (state) {
case State.UPDATING:
var success = yield backend.update_package (this, (owned)cb, action_cancellable);
if (success) {
change_information.clear_update_info ();
update_state ();
}
return success;
case State.INSTALLING:
var success = yield backend.install_package (this, (owned)cb, action_cancellable);
_installed = success;
update_state ();
return success;
case State.REMOVING:
var success = yield backend.remove_package (this, (owned)cb, action_cancellable);
_installed = !success;
update_state ();
yield client.refresh_updates ();
return success;
default:
return false;
}
}
private void clean_up_package_operation (bool success, State success_state, State fail_state) {
changing (false);
if (success) {
change_information.complete ();
state = success_state;
} else {
state = fail_state;
change_information.cancel ();
}
}
public string? get_name () {
if (name != null) {
return name;
}
name = component.get_name ();
if (name == null) {
if (backend_details == null) {
populate_backend_details_sync ();
}
name = backend_details.name;
}
return name;
}
public void set_name (string? new_name) {
name = new_name;
}
public string? get_description () {
if (description == null) {
description = component.get_description ();
if (description == null) {
if (backend_details == null) {
populate_backend_details_sync ();
}
description = backend_details.description;
}
}
return description;
}
public string? get_summary () {
if (summary != null) {
return summary;
}
summary = component.get_summary ();
if (summary == null) {
if (backend_details == null) {
populate_backend_details_sync ();
}
summary = backend_details.summary;
}
return summary;
}
public void set_summary (string? new_summary) {
summary = new_summary;
}
public string get_progress_description () {
return change_information.status_description;
}
public GLib.Icon get_icon (uint size, uint scale_factor) {
GLib.Icon? icon = null;
uint current_size = 0;
uint current_scale = 0;
uint pixel_size = size * scale_factor;
weak GenericArray<AppStream.Icon> icons = component.get_icons ();
for (int i = 0; i < icons.length; i++) {
weak AppStream.Icon _icon = icons[i];
switch (_icon.get_kind ()) {
case AppStream.IconKind.STOCK:
unowned string icon_name = _icon.get_name ();
if (Gtk.IconTheme.get_default ().has_icon (icon_name)) {
return new ThemedIcon (icon_name);
}
break;
case AppStream.IconKind.CACHED:
case AppStream.IconKind.LOCAL:
var icon_scale = _icon.get_scale ();
var icon_width = _icon.get_width () * icon_scale;
bool is_bigger = (icon_width > current_size && current_size < pixel_size);
bool has_better_dpi = (icon_width == current_size && current_scale < icon_scale && scale_factor <= icon_scale);
if (is_bigger || has_better_dpi) {
var file = File.new_for_path (_icon.get_filename ());
icon = new FileIcon (file);
current_size = icon_width;
current_scale = icon_scale;
}
break;
case AppStream.IconKind.REMOTE:
var icon_scale = _icon.get_scale ();
var icon_width = _icon.get_width () * icon_scale;
bool is_bigger = (icon_width > current_size && current_size < pixel_size);
bool has_better_dpi = (icon_width == current_size && current_scale < icon_scale && scale_factor <= icon_scale);
if (is_bigger || has_better_dpi) {
var file = File.new_for_uri (_icon.get_url ());
icon = new FileIcon (file);
current_size = icon_width;
current_scale = icon_scale;
}
break;
}
}
if (icon == null) {
if (component.get_kind () == AppStream.ComponentKind.ADDON) {
icon = new ThemedIcon ("extension");
} else {
icon = new ThemedIcon ("application-default-icon");
}
}
return icon;
}
public Package? get_plugin_host_package () {
var extends = component.get_extends ();
if (extends == null || extends.length < 1) {
return null;
}
for (int i = 0; i < extends.length; i++) {
var package = backend.get_package_for_component_id (extends[i]);
if (package != null) {
return package;
}
}
return null;
}
public string? get_version () {
if (latest_version != null) {
return latest_version;
}
if (backend_details == null) {
populate_backend_details_sync ();
}
if (backend_details.version != null) {
latest_version = backend_details.version;
}
return latest_version;
}
public string? get_color_primary () {
if (color_primary != null) {
return color_primary;
} else {
color_primary = component.get_custom_value ("x-appcenter-color-primary");
return color_primary;
}
}
public string? get_color_primary_text () {
if (color_primary_text != null) {
return color_primary_text;
} else {
color_primary_text = component.get_custom_value ("x-appcenter-color-primary-text");
return color_primary_text;
}
}
public string? get_payments_key () {
if (payments_key != null) {
return payments_key;
} else {
payments_key = component.get_custom_value ("x-appcenter-stripe");
return payments_key;
}
}
public string get_suggested_amount () {
if (suggested_amount != null) {
return suggested_amount;
} else {
suggested_amount = component.get_custom_value ("x-appcenter-suggested-price");
return suggested_amount == null ? DEFAULT_PRICE_DOLLARS : suggested_amount;
}
}
private string convert_version (string version) {
if (is_os_updates) {
return version;
}
string returned = version;
returned = returned.split ("+", 2)[0];
returned = returned.split ("-", 2)[0];
returned = returned.split ("~", 2)[0];
if (":" in returned) {
returned = returned.split (":", 2)[1];
}
return returned;
}
public bool get_can_launch () {
if (app_info_retrieved) {
return app_info != null;
}
if (is_compulsory) {
return false;
}
var launchable = component.get_launchable (AppStream.LaunchableKind.DESKTOP_ID);
if (launchable != null) {
var launchables = launchable.get_entries ();
for (int i = 0; i < launchables.length; i++) {
app_info = new DesktopAppInfo (launchables[i]);
// A bit strange in Vala, but the DesktopAppInfo constructor does indeed return null if the desktop
// file isn't found: https://valadoc.org/gio-unix-2.0/GLib.DesktopAppInfo.DesktopAppInfo.html
if (app_info != null) {
break;
}
}
}
if (app_info != null) {
app_info_retrieved = true;
return true;
}
// Fallback to trying Appstream ID as desktop ID for applications that haven't updated to the newest spec yet
string? desktop_id = component.id;
if (desktop_id != null) {
app_info = new DesktopAppInfo (desktop_id);
}
app_info_retrieved = true;
return app_info != null;
}
public Gee.ArrayList<AppStream.Release> get_newest_releases (int min_releases, int max_releases) {
var list = new Gee.ArrayList<AppStream.Release> ();
var releases = component.get_releases ();
uint index = 0;
while (index < releases.length) {
if (releases[index].get_version () == null) {
releases.remove_index (index);
if (index >= releases.length) {
break;
}
continue;
}
index++;
}
if (releases.length < min_releases) {
return list;
}
releases.sort_with_data ((a, b) => {
return b.vercmp (a);
});
string installed_version = get_version ();
int start_index = 0;
int end_index = min_releases;
if (installed) {
for (int i = 0; i < releases.length; i++) {
var release = releases.@get (i);
unowned string release_version = release.get_version ();
if (release_version == null) {
continue;
}
if (AppStream.utils_compare_versions (release_version, installed_version) == 0) {
end_index = i.clamp (min_releases, max_releases);
break;
}
}
}
for (int j = start_index; j < end_index; j++) {
list.add (releases.get (j));
}
return list;
}
public AppStream.Release? get_newest_release () {
var releases = component.get_releases ();
releases.sort_with_data ((a, b) => {
if (a.get_version () == null || b.get_version () == null) {
if (a.get_version () != null) {
return -1;
} else if (b.get_version () != null) {
return 1;
} else {
return 0;
}
}
return b.vercmp (a);
});
if (releases.length > 0) {
return releases[0];
}
return null;
}
public async uint64 get_download_size_including_deps () {
uint64 size = 0;
try {
size = yield backend.get_download_size (this, null);
} catch (Error e) {
warning ("Error getting download size: %s", e.message);
}
return size;
}
private void populate_backend_details_sync () {
if (component.id == OS_UPDATES_ID || is_local) {
backend_details = new PackageDetails ();
return;
}
var loop = new MainLoop ();
PackageDetails? result = null;
backend.get_package_details.begin (this, (obj, res) => {
try {
result = backend.get_package_details.end (res);
} catch (Error e) {
warning (e.message);
} finally {
loop.quit ();
}
});
loop.run ();
backend_details = result;
if (backend_details == null) {
backend_details = new PackageDetails ();
}
}
}