Skip to content

Commit 1ecbb12

Browse files
committed
🙈 Hide alongside / erase options if they belong to the install device
1 parent 90ee94b commit 1ecbb12

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/Objects/InstallOptions.vala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class InstallOptions : GLib.Object {
2929

3030
private Gee.ArrayList<string> unlocked_devices { get; set; default = new Gee.ArrayList<string> (); }
3131

32+
private unowned Distinst.Disk? install_device;
33+
private string? install_device_path;
34+
3235
// The amount of free space that should be retained when shrinking (20 GiB).
3336
public const uint64 SHRINK_OVERHEAD = 20 * 2 * 1024 * 1024;
3437

@@ -40,6 +43,25 @@ public class InstallOptions : GLib.Object {
4043
return _options_object;
4144
}
4245

46+
public unowned Distinst.Disk? get_install_device () {
47+
if (install_device == null) {
48+
install_device = disks.get_disk_with_mount ("/cdrom");
49+
}
50+
51+
return install_device;
52+
}
53+
54+
public unowned string? get_install_device_path () {
55+
if (install_device_path == null) {
56+
unowned Distinst.Disk? install_device = get_install_device ();
57+
if (install_device != null) {
58+
install_device_path = Utils.string_from_utf8 (install_device.get_device_path ());
59+
}
60+
}
61+
62+
return install_device_path;
63+
}
64+
4365
public void set_minimum_size (uint64 size) {
4466
minimum_size = size;
4567
}
@@ -118,6 +140,8 @@ public class InstallOptions : GLib.Object {
118140
// Transder ownership of the disks to the caller.
119141
public Distinst.Disks take_disks () {
120142
disks_moved = true;
143+
install_device = null;
144+
install_device_path = null;
121145
return (owned) disks;
122146
}
123147

src/Views/AlongsideView.vala

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ public class AlongsideView: OptionsView {
4747
public void update_options () {
4848
base.clear_options ();
4949

50+
var options = InstallOptions.get_default ();
51+
5052
add_alongside_options ();
5153

52-
if (InstallOptions.get_default ().get_options ().has_erase_options ()) {
54+
if (options.get_options ().has_erase_options ()) {
5355
add_erase_options ();
5456
}
5557

@@ -59,16 +61,23 @@ public class AlongsideView: OptionsView {
5961

6062
private void add_alongside_options () {
6163
var install_options = InstallOptions.get_default ();
64+
unowned string? install_device = install_options.get_install_device_path ();
6265

6366
foreach (var option in install_options.get_options ().get_alongside_options ()) {
67+
var device = Utils.string_from_utf8 (option.get_device ());
68+
69+
if (install_device != null && install_device == device) {
70+
debug ("skipping %s because it is on the install device\n", device);
71+
continue;
72+
}
73+
6474
string? os = Utils.string_from_utf8 (option.get_os ());
6575
os = os == "none" ? null : os;
6676

67-
var device = Utils.string_from_utf8 (option.get_device ());
6877
var free = option.get_sectors_free ();
6978
var total = option.get_sectors_total ();
7079
var partition = option.get_partition ();
71-
var path = Utils.string_from_utf8 (option.get_path ());
80+
var partition_path = Utils.string_from_utf8 (option.get_path ());
7281
string logo = Utils.get_distribution_logo_from_alongside (option);
7382

7483
string label;
@@ -80,7 +89,7 @@ public class AlongsideView: OptionsView {
8089
label = _("%s on %s").printf (os == null ? _("Partition") : os, device);
8190
details = _("Shrink %s (%.1f GiB free)")
8291
.printf (
83-
path,
92+
partition_path,
8493
(double) free / SECTORS_AS_GIB
8594
);
8695
}
@@ -129,8 +138,15 @@ public class AlongsideView: OptionsView {
129138
private void add_erase_options () {
130139
var install_options = InstallOptions.get_default ();
131140
unowned Distinst.InstallOptions options = install_options.get_updated_options ();
141+
unowned string? install_device = install_options.get_install_device_path ();
132142

133143
foreach (unowned Distinst.EraseOption disk in options.get_erase_options ()) {
144+
string device_path = Utils.string_from_utf8 (disk.get_device_path ());
145+
146+
if (install_device != null && install_device == device_path && !install_options.has_recovery ()) {
147+
continue;
148+
}
149+
134150
string logo = Utils.string_from_utf8 (disk.get_linux_icon ());
135151
string label = Utils.string_from_utf8 (disk.get_model ());
136152
string details = "Erase %s %.1f GiB".printf (

src/Views/DiskView.vala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ public class Installer.DiskView : OptionsView {
4242
public async void load (uint64 minimum_disk_size) {
4343
var install_options = InstallOptions.get_default ();
4444
unowned Distinst.InstallOptions options = install_options.get_updated_options ();
45+
unowned string? install_device = install_options.get_install_device_path ();
4546

4647
foreach (unowned Distinst.EraseOption disk in options.get_erase_options ()) {
48+
string device_path = Utils.string_from_utf8 (disk.get_device_path ());
49+
50+
if (install_device != null && install_device == device_path && !install_options.has_recovery ()) {
51+
continue;
52+
}
53+
4754
string logo = Utils.string_from_utf8 (disk.get_linux_icon ());
4855
string label = Utils.string_from_utf8 (disk.get_model ());
4956
string details = "%s %.1f GiB".printf (

0 commit comments

Comments
 (0)