Skip to content

Commit 86d04e1

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

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

src/Objects/InstallOptions.vala

Lines changed: 23 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,7 @@ 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;
121144
return (owned) disks;
122145
}
123146

src/Views/AlongsideView.vala

Lines changed: 21 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,24 @@ 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+
unowned uint8[] device_path = option.get_path ();
68+
var device = Utils.string_from_utf8 (option.get_device ());
69+
70+
if (install_device != null && install_device == device) {
71+
debug ("skipping %s because it is on the install device\n", device);
72+
continue;
73+
}
74+
6475
string? os = Utils.string_from_utf8 (option.get_os ());
6576
os = os == "none" ? null : os;
6677

67-
var device = Utils.string_from_utf8 (option.get_device ());
6878
var free = option.get_sectors_free ();
6979
var total = option.get_sectors_total ();
7080
var partition = option.get_partition ();
71-
var path = Utils.string_from_utf8 (option.get_path ());
81+
var path = Utils.string_from_utf8 (device_path);
7282
string logo = Utils.get_distribution_logo_from_alongside (option);
7383

7484
string label;
@@ -129,11 +139,18 @@ public class AlongsideView: OptionsView {
129139
private void add_erase_options () {
130140
var install_options = InstallOptions.get_default ();
131141
unowned Distinst.InstallOptions options = install_options.get_updated_options ();
142+
unowned string? install_device = install_options.get_install_device_path ();
132143

133144
foreach (unowned Distinst.EraseOption disk in options.get_erase_options ()) {
145+
string device_path = Utils.string_from_utf8 (disk.get_device_path ());
146+
147+
if (install_device != null && install_device == device_path && !install_options.has_recovery ()) {
148+
continue;
149+
}
150+
134151
string logo = Utils.string_from_utf8 (disk.get_linux_icon ());
135152
string label = Utils.string_from_utf8 (disk.get_model ());
136-
string details = "Erase %s %.1f GiB".printf (
153+
string details = "%s %.1f GiB".printf (
137154
Utils.string_from_utf8 (disk.get_device_path ()),
138155
(double) disk.get_sectors () / SECTORS_AS_GIB
139156
);

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 (

src/Views/TryInstallView.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public class Installer.TryInstallView : AbstractInstallerView {
155155
InstallTypeButton alongside_button = null;
156156

157157
// Disallow the alongside OS option if the live media is the recovery partition.
158-
if (!options.has_recovery ()) {
158+
if (options.has_recovery ()) {
159159
alongside_button = button_creator.new_button (
160160
_("Install Alongside OS"),
161161
"drive-multidisk",

0 commit comments

Comments
 (0)