Skip to content

Commit

Permalink
fix(gui): Enable landscape by default (#887)
Browse files Browse the repository at this point in the history
In #815 we disabled Landscape UI elements by default. 

The new default is Landscape UI elements enabled. They go disabled if
the value `LandscapeConfigVisibility` under
`HKEY_CURRENT_USER\Software\Canonical\UbuntuPro\` is set to `1`. If
missing, unset or set to anything else, we go with the new default.
Since that PR only affected the GUI, agent remains untouched.

The value name might be a bit more mouthful but it has the property of
not conveying the default behaviour, allowing us to change it without
surprising new users.

Tests and dev docs are updated as well.

---

UDENG-4243
  • Loading branch information
CarlosNihelton authored Sep 16, 2024
2 parents 72272d8 + a6c025d commit 936e93c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# How to enable opt-in features

Some features in UP4W are opt-in. While the code is arranged such that CI
always tests with those features enabled, when running UP4W on your machine,
you need to enable them explicitly via the Windows registry. This guide shows
you how to do that.

## Enable Landscape configuration in the GUI

1. Open the Windows registry editor: press `Win + R`, type `regedit` and press `Enter`.
1. Navigate to the following key: `HKEY_CURRENT_USER\Software\Canonical\UbuntuPro\`.
1. Create a new DWORD value named `ShowLandscapeConfig` and set it to `1`.

The next time you open the GUI, you'll find that the Landscape configuration
page can be shown via the set up wizard or by clicking on the 'Configure
Landscape' button.
Some features in UP4W are opt-in or can be toggled on and off via the Windows Registry.
While the code is arranged such that CI always tests with those features enabled,
when running UP4W on your machine, you may need to toggle them on and off
explicitly via the Windows registry. This guide shows you how to do that.

## Enable subscribing via the Microsoft Store

Expand All @@ -27,3 +17,17 @@ Pro via the Microsoft Store.
```{warning}
Beware that can incur in real charges if you proceed with the purchase.
```

## Disable Landscape configuration in the GUI

Landscape configuration page and related buttons are enabled by default, but can be disabled via registry.

1. Open the Windows registry editor: press `Win + R`, type `regedit` and press `Enter`.
1. Navigate to the following key: `HKEY_CURRENT_USER\Software\Canonical\UbuntuPro\`.
1. Create a new DWORD value named `LandscapeConfigVisibility` and set it to `0`.

The next time you open the GUI, you'll find that the Landscape configuration
page can be shown via the set up wizard or by clicking on the 'Configure
Landscape' button.
If that value is not present or set to anything other than `0`, Landscape configuration page
and related buttons will be visible.
2 changes: 1 addition & 1 deletion docs/dev/howto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ These how-to guides cover key operations and processes in Ubuntu Pro for WSL.
Install UP4W <02-install>
Restart UP4W <03-restart>
Access UP4W logs <06-access-the-logs>
Enable opt-in features <07-enable-opt-in-features>
Enable opt-in features <07-toggle-features>
Reset UP4W <reset-factory>
```
14 changes: 9 additions & 5 deletions gui/packages/ubuntupro/lib/core/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class Settings {
Settings(SettingsRepository repository) {
if (!repository.load()) return;

// Enable store purchase if the registry value is 1.
final purchase = repository.readInt(kAllowStorePurchase) == 1
? Options.withStorePurchase
: Options.none;
final landscape = repository.readInt(kShowLandscapeConfig) == 1
? Options.withLandscapeConfiguration
: Options.none;

// Hide Landscape UI if the registry value is 0.
final landscape = repository.readInt(kLandscapeConfigVisibility) == 0
? Options.none
: Options.withLandscapeConfiguration;

repository.close();

Expand All @@ -25,7 +28,8 @@ class Settings {
/// Useful for integration testing.
Settings.withOptions(this._options);

Options _options = Options.none;
/// By default Landscape is enabled and Store purchase is disabled.
Options _options = Options.withLandscapeConfiguration;

bool get isLandscapeConfigurationEnabled =>
_options & Options.withLandscapeConfiguration;
Expand All @@ -35,7 +39,7 @@ class Settings {
@visibleForTesting
static const kAllowStorePurchase = 'AllowStorePurchase';
@visibleForTesting
static const kShowLandscapeConfig = 'ShowLandscapeConfig';
static const kLandscapeConfigVisibility = 'LandscapeConfigVisibility';
}

/// Settings options modelled as an enum with bitwise operations, i.e. flags.
Expand Down
16 changes: 10 additions & 6 deletions gui/packages/ubuntupro/test/core/settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void main() {
test('all', () {
final repository = MockSettingsRepository();
when(repository.load()).thenReturn(true);
when(repository.readInt(Settings.kShowLandscapeConfig)).thenReturn(1);
when(repository.readInt(Settings.kLandscapeConfigVisibility))
.thenReturn(null);
when(repository.readInt(Settings.kAllowStorePurchase)).thenReturn(1);

final settings = Settings(repository);
Expand All @@ -49,7 +50,8 @@ void main() {
test('Landscape', () {
final repository = MockSettingsRepository();
when(repository.load()).thenReturn(true);
when(repository.readInt(Settings.kShowLandscapeConfig)).thenReturn(1);
when(repository.readInt(Settings.kLandscapeConfigVisibility))
.thenReturn(null);
when(repository.readInt(Settings.kAllowStorePurchase)).thenReturn(0);

final settings = Settings(repository);
Expand All @@ -60,7 +62,8 @@ void main() {
test('purchase', () {
final repository = MockSettingsRepository();
when(repository.load()).thenReturn(true);
when(repository.readInt(Settings.kShowLandscapeConfig)).thenReturn(0);
when(repository.readInt(Settings.kLandscapeConfigVisibility))
.thenReturn(0);
when(repository.readInt(Settings.kAllowStorePurchase)).thenReturn(1);

final settings = Settings(repository);
Expand All @@ -71,21 +74,22 @@ void main() {
test('none', () {
final repository = MockSettingsRepository();
when(repository.load()).thenReturn(true);
when(repository.readInt(Settings.kShowLandscapeConfig)).thenReturn(null);
when(repository.readInt(Settings.kLandscapeConfigVisibility))
.thenReturn(0);
when(repository.readInt(Settings.kAllowStorePurchase)).thenReturn(null);

final settings = Settings(repository);

expect(settings.isLandscapeConfigurationEnabled, isFalse);
expect(settings.isStorePurchaseAllowed, isFalse);
});
test('unset', () {
test('unset (defaults)', () {
final repository = MockSettingsRepository();
when(repository.load()).thenReturn(false);

final settings = Settings(repository);

expect(settings.isLandscapeConfigurationEnabled, isFalse);
expect(settings.isLandscapeConfigurationEnabled, isTrue);
expect(settings.isStorePurchaseAllowed, isFalse);
});
});
Expand Down

0 comments on commit 936e93c

Please sign in to comment.