Skip to content

Commit

Permalink
Button to disable browsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Macocian committed Apr 17, 2021
1 parent b27998d commit d2bada4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Daybreak/Configuration/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Daybreak.Configuration
{
public sealed class ApplicationConfiguration
{
[JsonProperty("BrowsersEnabled")]
public bool BrowsersEnabled { get; set; } = true;
[JsonProperty("ToolboxPath")]
public string ToolboxPath { get; set; }
[JsonProperty("TexmodPath")]
Expand Down
16 changes: 14 additions & 2 deletions Daybreak/Controls/ChromiumBrowserWrapper.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class ChromiumBrowserWrapper : UserControl
public readonly static DependencyProperty AddressProperty = DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, string>(nameof(Address));
public readonly static DependencyProperty FavoriteAddressProperty = DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, string>(nameof(FavoriteAddress));
public readonly static DependencyProperty NavigatingProperty = DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, bool>(nameof(Navigating));
public readonly static DependencyProperty BrowserEnabledProperty = DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, bool>(nameof(BrowserEnabled));
public readonly static DependencyProperty AddressBarReadonlyProperty = DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, bool>(nameof(AddressBarReadonly));
public readonly static DependencyProperty BrowserSupportedProperty = DependencyPropertyExtensions.Register<ChromiumBrowserWrapper, bool>(nameof(BrowserSupported), new PropertyMetadata(true));

Expand Down Expand Up @@ -53,6 +54,11 @@ public bool AddressBarReadonly
get => this.GetTypedValue<bool>(AddressBarReadonlyProperty);
private set => this.SetTypedValue<bool>(AddressBarReadonlyProperty, value);
}
public bool BrowserEnabled
{
get => this.GetTypedValue<bool>(BrowserEnabledProperty);
private set => this.SetTypedValue<bool>(BrowserEnabledProperty, value);
}
public bool BrowserSupported
{
get => this.GetTypedValue<bool>(BrowserSupportedProperty);
Expand All @@ -77,13 +83,19 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
}
}

public void ReinitializeBrowser()
public async void ReinitializeBrowser()
{
this.InitializeBrowser();
await this.InitializeBrowser();
}

private void InitializeEnvironment()
{
if (this.configurationManager.GetConfiguration().BrowsersEnabled is false)
{
this.BrowserSupported = false;
return;
}

try
{
this.coreWebView2Environment = System.Extensions.TaskExtensions.RunSync(() => CoreWebView2Environment.CreateAsync(null, "BrowserData", null));
Expand Down
2 changes: 1 addition & 1 deletion Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<Version>0.6.3</Version>
<Version>0.6.4</Version>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions Daybreak/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
Foreground="White" FontSize="24" Width="200" Height="40" Margin="0, 10, 0, 10"
IsEnabled="{Binding ElementName=_this, Path=LaunchTexmodButtonEnabled, Mode=OneWay}"
Clicked="LaunchTexmodButton_Clicked" Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="1"></controls:OpaqueButton>
<Grid x:Name="RightContainer" Grid.Column="2" Margin="10">
<Grid Grid.Column="2" Margin="10" Visibility="{Binding ElementName=_this, Path=BrowsersEnabled, Mode=OneWay, Converter={StaticResource BooleanToVisibility}}">
<controls:ChromiumBrowserWrapper Address="{Binding ElementName=_this, Path=RightBrowserAddress, Mode=OneWay}"
Foreground="White" FavoriteUriChanged="RightBrowser_FavoriteUriChanged"
FavoriteAddress="{Binding ElementName=_this, Path=RightBrowserFavoriteAddress, Mode=OneWay}"
MaximizeClicked="RightChromiumBrowserWrapper_MaximizeClicked"/>
</Grid>
<Grid x:Name="LeftContainer" Grid.Column="0" Margin="10">
<Grid Grid.Column="0" Margin="10" Visibility="{Binding ElementName=_this, Path=BrowsersEnabled, Mode=OneWay, Converter={StaticResource BooleanToVisibility}}">
<controls:ChromiumBrowserWrapper Address="{Binding ElementName=_this, Path=LeftBrowserAddress, Mode=OneWay}"
Foreground="White" FavoriteUriChanged="LeftBrowser_FavoriteUriChanged"
FavoriteAddress="{Binding ElementName=_this, Path=LeftBrowserFavoriteAddress, Mode=OneWay}"
Expand Down
22 changes: 18 additions & 4 deletions Daybreak/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public partial class MainView : UserControl
DependencyPropertyExtensions.Register<MainView, bool>(nameof(LaunchToolboxButtonEnabled));
public static readonly DependencyProperty LaunchTexmodButtonEnabledProperty =
DependencyPropertyExtensions.Register<MainView, bool>(nameof(LaunchTexmodButtonEnabled));
public static readonly DependencyProperty BrowsersEnabledProperty =
DependencyPropertyExtensions.Register<MainView, bool>(nameof(BrowsersEnabled), new PropertyMetadata(true));
public static readonly DependencyProperty RightBrowserAddressProperty =
DependencyPropertyExtensions.Register<MainView, string>(nameof(RightBrowserAddress));
public static readonly DependencyProperty LeftBrowserAddressProperty =
Expand Down Expand Up @@ -76,6 +78,11 @@ public bool LaunchTexmodButtonEnabled
get => this.GetTypedValue<bool>(LaunchTexmodButtonEnabledProperty);
set => this.SetTypedValue(LaunchTexmodButtonEnabledProperty, value);
}
public bool BrowsersEnabled
{
get => this.GetTypedValue<bool>(BrowsersEnabledProperty);
set => this.SetTypedValue(BrowsersEnabledProperty, value);
}

public MainView(
IApplicationLauncher applicationDetector,
Expand All @@ -93,10 +100,17 @@ public MainView(
private void NavigateToDefaults()
{
var applicationConfiguration = this.configurationManager.GetConfiguration();
this.LeftBrowserFavoriteAddress = applicationConfiguration.LeftBrowserDefault;
this.RightBrowserFavoriteAddress = applicationConfiguration.RightBrowserDefault;
this.LeftBrowserAddress = applicationConfiguration.LeftBrowserDefault;
this.RightBrowserAddress = applicationConfiguration.RightBrowserDefault;
if (applicationConfiguration.BrowsersEnabled)
{
this.LeftBrowserFavoriteAddress = applicationConfiguration.LeftBrowserDefault;
this.RightBrowserFavoriteAddress = applicationConfiguration.RightBrowserDefault;
this.LeftBrowserAddress = applicationConfiguration.LeftBrowserDefault;
this.RightBrowserAddress = applicationConfiguration.RightBrowserDefault;
}
else
{
this.BrowsersEnabled = false;
}
}

private void PeriodicallyCheckGameState()
Expand Down
9 changes: 6 additions & 3 deletions Daybreak/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
<TextBlock Text="Texmod path" FontSize="22" Foreground="White"></TextBlock>
<TextBlock Text="GWToolbox path: " FontSize="22" Foreground="White"></TextBlock>
<TextBlock Text="GWToolbox auto-launch: " FontSize="22" Foreground="White"></TextBlock>
<TextBlock Text="Address bar readonly: " FontSize="22" Foreground="White"/>
<TextBlock Text="Browsers enabled: " FontSize="22" Foreground="White"/>
<TextBlock Text="Browsers address bar readonly: " FontSize="22" Foreground="White"/>
<TextBlock Text="Left browser homepage: " FontSize="22" Foreground="White"></TextBlock>
<TextBlock Text="Right browser homepage: " FontSize="22" Foreground="White"></TextBlock>
</StackPanel>
Expand All @@ -106,9 +107,11 @@
Clicked="ToolboxFilePickerGlyph_Clicked"></controls:FilePickerGlyph>
</Grid>
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
FontSize="22" Background="Transparent" Foreground="White" IsChecked="{Binding ElementName=_this, Path=ToolboxAutoLaunch, Mode=TwoWay}"></ToggleButton>
FontSize="22" Foreground="White" IsChecked="{Binding ElementName=_this, Path=ToolboxAutoLaunch, Mode=TwoWay}"></ToggleButton>
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
FontSize="22" Background="Transparent" Foreground="White" IsChecked="{Binding ElementName=_this, Path=AddressBarReadonly, Mode=TwoWay}"></ToggleButton>
FontSize="22" Foreground="White" IsChecked="{Binding ElementName=_this, Path=BrowsersEnabled, Mode=TwoWay}"></ToggleButton>
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
FontSize="22" Foreground="White" IsChecked="{Binding ElementName=_this, Path=AddressBarReadonly, Mode=TwoWay}"></ToggleButton>
<TextBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
FontSize="22" Background="Transparent" Foreground="White"
Text="{Binding ElementName=_this, Path=LeftBrowserUrl, Mode=TwoWay}"
Expand Down
9 changes: 9 additions & 0 deletions Daybreak/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public partial class SettingsView : UserControl
DependencyPropertyExtensions.Register<SettingsView, string>(nameof(ToolboxPath));
public static readonly DependencyProperty AddressBarReadonlyProperty =
DependencyPropertyExtensions.Register<SettingsView, bool>(nameof(AddressBarReadonly));
public static readonly DependencyProperty BrowsersEnabledProperty =
DependencyPropertyExtensions.Register<SettingsView, bool>(nameof(BrowsersEnabled));
public static readonly DependencyProperty LeftBrowserUrlProperty =
DependencyPropertyExtensions.Register<SettingsView, string>(nameof(LeftBrowserUrl));
public static readonly DependencyProperty RightBrowserUrlProperty =
Expand Down Expand Up @@ -60,6 +62,11 @@ public string RightBrowserUrl
get => this.GetTypedValue<string>(RightBrowserUrlProperty);
set => this.SetValue(RightBrowserUrlProperty, value);
}
public bool BrowsersEnabled
{
get => this.GetTypedValue<bool>(BrowsersEnabledProperty);
set => this.SetValue(BrowsersEnabledProperty, value);
}

public SettingsView(
IConfigurationManager configurationManager,
Expand All @@ -80,6 +87,7 @@ private void LoadSettings()
this.RightBrowserUrl = config.RightBrowserDefault;
this.ToolboxAutoLaunch = config.ToolboxAutoLaunch;
this.TexmodPath = config.TexmodPath;
this.BrowsersEnabled = config.BrowsersEnabled;
}

private void SaveButton_Clicked(object sender, EventArgs e)
Expand All @@ -91,6 +99,7 @@ private void SaveButton_Clicked(object sender, EventArgs e)
currentConfig.RightBrowserDefault = this.RightBrowserUrl;
currentConfig.ToolboxAutoLaunch = this.ToolboxAutoLaunch;
currentConfig.TexmodPath = this.TexmodPath;
currentConfig.BrowsersEnabled = this.BrowsersEnabled;
this.configurationManager.SaveConfiguration(currentConfig);
this.viewManager.ShowView<SettingsCategoryView>();
}
Expand Down

0 comments on commit d2bada4

Please sign in to comment.