mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-09-16 05:19:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fb96ca3a4 | ||
|
|
6de52f5585 |
@@ -1,5 +1,6 @@
|
||||
using Daybreak.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Daybreak.Configuration
|
||||
@@ -30,5 +31,7 @@ namespace Daybreak.Configuration
|
||||
public bool AddressBarReadonly { get; set; } = true;
|
||||
[JsonProperty("ExperimentalFeatures")]
|
||||
public ExperimentalFeatures ExperimentalFeatures { get; set; } = new();
|
||||
[JsonProperty("ShortcutLocation")]
|
||||
public string ShortcutLocation { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using Daybreak.Services.Privilege;
|
||||
using Daybreak.Services.Runtime;
|
||||
using Daybreak.Services.Screens;
|
||||
using Daybreak.Services.Screenshots;
|
||||
using Daybreak.Services.Shortcuts;
|
||||
using Daybreak.Services.Updater;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Daybreak.Views;
|
||||
@@ -41,6 +42,7 @@ namespace Daybreak.Configuration
|
||||
serviceProducer.RegisterSingleton<IIconRetriever, IconRetriever>();
|
||||
serviceProducer.RegisterSingleton<IPrivilegeManager, PrivilegeManager>();
|
||||
serviceProducer.RegisterSingleton<IScreenManager, ScreenManager>();
|
||||
serviceProducer.RegisterSingleton<IShortcutManager, ShortcutManager>();
|
||||
}
|
||||
public static void RegisterLifetimeServices(IApplicationLifetimeProducer applicationLifetimeProducer)
|
||||
{
|
||||
|
||||
@@ -9,13 +9,14 @@
|
||||
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
|
||||
<Version>0.8.3</Version>
|
||||
<Version>0.8.5</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.32" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.818.41" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />
|
||||
<PackageReference Include="Slim" Version="1.2.1" />
|
||||
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
|
||||
<PackageReference Include="SystemExtensions.NetStandard" Version="1.1.4" />
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Daybreak.Services.Shortcuts
|
||||
{
|
||||
public interface IShortcutManager
|
||||
{
|
||||
bool ShortcutEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using Daybreak.Services.Configuration;
|
||||
using ShellLink;
|
||||
using System.Diagnostics;
|
||||
using System.Extensions;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Daybreak.Services.Shortcuts
|
||||
{
|
||||
public sealed class ShortcutManager : IShortcutManager
|
||||
{
|
||||
private const string ShortcutName = "Daybreak.lnk";
|
||||
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
|
||||
public bool ShortcutEnabled {
|
||||
get => this.ShortcutExists();
|
||||
set
|
||||
{
|
||||
if (value is true)
|
||||
{
|
||||
this.CreateShortcut();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.RemoveShortcut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ShortcutManager(IConfigurationManager configurationManager)
|
||||
{
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
}
|
||||
|
||||
private bool ShortcutExists()
|
||||
{
|
||||
var shortcutFolder = this.configurationManager.GetConfiguration().ShortcutLocation;
|
||||
var shortcutPath = $"{shortcutFolder}\\{ShortcutName}";
|
||||
if (File.Exists(shortcutPath))
|
||||
{
|
||||
var shortcut = Shortcut.ReadFromFile(shortcutPath);
|
||||
var currentExecutable = Process.GetCurrentProcess()?.MainModule?.FileName;
|
||||
if (shortcut.ExtraData?.EnvironmentVariableDataBlock?.TargetAnsi?.Equals(currentExecutable) is true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CreateShortcut()
|
||||
{
|
||||
if (this.ShortcutExists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var shortcutFolder = this.configurationManager.GetConfiguration().ShortcutLocation;
|
||||
var shortcutPath = $"{shortcutFolder}\\{ShortcutName}";
|
||||
var currentExecutable = Process.GetCurrentProcess()?.MainModule?.FileName;
|
||||
var shortcut = Shortcut.CreateShortcut(currentExecutable);
|
||||
shortcut.StringData = new ShellLink.Structures.StringData
|
||||
{
|
||||
WorkingDir = Path.GetDirectoryName(currentExecutable),
|
||||
RelativePath = "Daybreak.exe"
|
||||
};
|
||||
shortcut.WriteToFile(shortcutPath);
|
||||
}
|
||||
|
||||
private void RemoveShortcut()
|
||||
{
|
||||
if (this.ShortcutExists() is false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var shortcutFolder = this.configurationManager.GetConfiguration().ShortcutLocation;
|
||||
var shortcutPath = $"{shortcutFolder}\\{ShortcutName}";
|
||||
File.Delete(shortcutPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:local="clr-namespace:Daybreak.Views"
|
||||
xmlns:controls="clr-namespace:Daybreak.Controls"
|
||||
mc:Ignorable="d"
|
||||
x:Name="_this"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid Background="#A0202020">
|
||||
<Grid.RowDefinitions>
|
||||
@@ -14,6 +15,10 @@
|
||||
</Grid.RowDefinitions>
|
||||
<controls:BackButton Foreground="White" Height="30" Width="30" Grid.Column="0" HorizontalAlignment="Left" Margin="5"
|
||||
Clicked="BackButton_Clicked"></controls:BackButton>
|
||||
<TextBlock Text="Choose screen" FontSize="18" Foreground="White" HorizontalAlignment="Center"></TextBlock>
|
||||
<controls:OpaqueButton Text="Test" Foreground="White" HighlightOpacity="0.3" Highlight="White" FontSize="18" Width="80"
|
||||
HorizontalAlignment="Right" Margin="0, 0, 50, 0" Clicked="OpaqueButton_Clicked"
|
||||
IsEnabled="{Binding ElementName=_this, Path=CanTest, Mode=OneWay}"></controls:OpaqueButton>
|
||||
<controls:SaveButton Foreground="White" Height="30" Width="30" Grid.Column="1" HorizontalAlignment="Right" Margin="5"
|
||||
Clicked="SaveButton_Clicked"></controls:SaveButton>
|
||||
<Viewbox Grid.Row="1">
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using Daybreak.Controls.Templates;
|
||||
using Daybreak.Models;
|
||||
using Daybreak.Services.ApplicationLauncher;
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Screens;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using System;
|
||||
using System.Extensions;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Extensions;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Daybreak.Views
|
||||
@@ -16,21 +19,34 @@ namespace Daybreak.Views
|
||||
/// </summary>
|
||||
public partial class ScreenChoiceView : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty CanTestProperty =
|
||||
DependencyPropertyExtensions.Register<ScreenChoiceView, bool>(nameof(CanTest));
|
||||
|
||||
private readonly IScreenManager screenManager;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly IApplicationLauncher applicationLauncher;
|
||||
private int selectedId;
|
||||
|
||||
public bool CanTest
|
||||
{
|
||||
get => this.GetTypedValue<bool>(CanTestProperty);
|
||||
set => this.SetValue(CanTestProperty, value);
|
||||
}
|
||||
|
||||
public ScreenChoiceView(
|
||||
IViewManager viewManager,
|
||||
IScreenManager screenManager,
|
||||
IConfigurationManager configurationManager)
|
||||
IConfigurationManager configurationManager,
|
||||
IApplicationLauncher applicationLauncher)
|
||||
{
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.screenManager = screenManager.ThrowIfNull(nameof(screenManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.applicationLauncher = applicationLauncher.ThrowIfNull(nameof(applicationLauncher));
|
||||
this.InitializeComponent();
|
||||
this.selectedId = configurationManager.GetConfiguration().DesiredGuildwarsScreen;
|
||||
this.CanTest = applicationLauncher.IsGuildwarsRunning;
|
||||
this.SetupView();
|
||||
}
|
||||
|
||||
@@ -77,5 +93,16 @@ namespace Daybreak.Views
|
||||
this.configurationManager.GetConfiguration().DesiredGuildwarsScreen = this.selectedId;
|
||||
this.viewManager.ShowView<SettingsCategoryView>();
|
||||
}
|
||||
|
||||
private void OpaqueButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var screen = this.screenManager.Screens.Skip(this.selectedId).FirstOrDefault();
|
||||
if (screen is null)
|
||||
{
|
||||
throw new InvalidOperationException($"Unable to test placement. No screen with id {this.selectedId}");
|
||||
}
|
||||
|
||||
this.screenManager.MoveGuildwarsToScreen(screen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,11 @@
|
||||
<TextBlock Text="Right browser homepage: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Auto-place on desired screen: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Desired screen id: " FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Shortcut folder" FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
<TextBlock Text="Shortcut placed" FontSize="22" Foreground="White" Height="30"></TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="1">
|
||||
<Grid>
|
||||
<Grid Height="30">
|
||||
<TextBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
|
||||
FontSize="22" Margin="0, 0, 30, 0" Background="Transparent" Foreground="White"
|
||||
Text="{Binding ElementName=_this, Path=TexmodPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
|
||||
@@ -100,7 +102,7 @@
|
||||
Foreground="White" BorderBrush="Gray" BorderThickness="0"
|
||||
Clicked="TexmodFilePickerGlyph_Clicked"></controls:FilePickerGlyph>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<Grid Height="30">
|
||||
<TextBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
|
||||
FontSize="22" Margin="0, 0, 30, 0" Background="Transparent" Foreground="White"
|
||||
Text="{Binding ElementName=_this, Path=ToolboxPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
|
||||
@@ -115,14 +117,14 @@
|
||||
<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"
|
||||
FontSize="22" Background="Transparent" Foreground="White" Height="30"
|
||||
Text="{Binding ElementName=_this, Path=LeftBrowserUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
|
||||
<TextBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
|
||||
FontSize="22" Background="Transparent" Foreground="White"
|
||||
FontSize="22" Background="Transparent" Foreground="White" Height="30"
|
||||
Text="{Binding ElementName=_this, Path=RightBrowserUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
|
||||
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
|
||||
FontSize="22" Foreground="White" IsChecked="{Binding ElementName=_this, Path=AutoPlaceOnScreen, Mode=TwoWay}"></ToggleButton>
|
||||
<Grid>
|
||||
<Grid Height="30">
|
||||
<TextBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
|
||||
FontSize="22" Background="Transparent" Foreground="White"
|
||||
Text="{Binding ElementName=_this, Path=DesiredScreen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
@@ -131,6 +133,18 @@
|
||||
Foreground="White" BorderBrush="Gray" BorderThickness="0"
|
||||
Clicked="ScreenPickerGlyph_Clicked"></controls:FilePickerGlyph>
|
||||
</Grid>
|
||||
<Grid Height="30">
|
||||
<TextBox HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
|
||||
FontSize="22" Background="Transparent" Foreground="White"
|
||||
Text="{Binding ElementName=_this, Path=ShortcutFolder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Margin="0, 0, 30, 0"></TextBox>
|
||||
<controls:FilePickerGlyph Height="30" Width="30" HorizontalAlignment="Right"
|
||||
Foreground="White" BorderBrush="Gray" BorderThickness="0"
|
||||
Clicked="ShortcutFolderPickerGlyph_Clicked"></controls:FilePickerGlyph>
|
||||
</Grid>
|
||||
<ToggleButton HorizontalAlignment="Center" HorizontalContentAlignment="Stretch" Style="{StaticResource AnimatedSwitch}" Height="30" Width="40"
|
||||
FontSize="22" Foreground="White" IsChecked="{Binding ElementName=_this, Path=ShortcutPlaced, Mode=TwoWay}"
|
||||
Checked="ShortcutEnabled_Checked" Unchecked="ShortcutEnabled_Unchecked"></ToggleButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Daybreak.Services.Configuration;
|
||||
using Daybreak.Services.Shortcuts;
|
||||
using Daybreak.Services.ViewManagement;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
@@ -6,13 +7,14 @@ using System.Extensions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Extensions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Daybreak.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SettingsView.xaml
|
||||
/// </summary>
|
||||
public partial class SettingsView : UserControl
|
||||
public partial class SettingsView : System.Windows.Controls.UserControl
|
||||
{
|
||||
public static readonly DependencyProperty TexmodPathProperty =
|
||||
DependencyPropertyExtensions.Register<SettingsView, string>(nameof(TexmodPath));
|
||||
@@ -32,9 +34,14 @@ namespace Daybreak.Views
|
||||
DependencyPropertyExtensions.Register<SettingsView, bool>(nameof(AutoPlaceOnScreen));
|
||||
public static readonly DependencyProperty DesiredScreenProperty =
|
||||
DependencyPropertyExtensions.Register<SettingsView, string>(nameof(DesiredScreen));
|
||||
public static readonly DependencyProperty ShortcutFolderProperty =
|
||||
DependencyPropertyExtensions.Register<SettingsView, string>(nameof(ShortcutFolder));
|
||||
public static readonly DependencyProperty ShortcutPlacedProperty =
|
||||
DependencyPropertyExtensions.Register<SettingsView, bool>(nameof(ShortcutPlaced));
|
||||
|
||||
private readonly IConfigurationManager configurationManager;
|
||||
private readonly IViewManager viewManager;
|
||||
private readonly IShortcutManager shortcutManager;
|
||||
|
||||
public string TexmodPath
|
||||
{
|
||||
@@ -81,11 +88,23 @@ namespace Daybreak.Views
|
||||
get => this.GetTypedValue<string>(DesiredScreenProperty);
|
||||
set => this.SetValue(DesiredScreenProperty, value);
|
||||
}
|
||||
public string ShortcutFolder
|
||||
{
|
||||
get => this.GetTypedValue<string>(ShortcutFolderProperty);
|
||||
set => this.SetValue(ShortcutFolderProperty, value);
|
||||
}
|
||||
public bool ShortcutPlaced
|
||||
{
|
||||
get => this.GetTypedValue<bool>(ShortcutPlacedProperty);
|
||||
set => this.SetValue(ShortcutPlacedProperty, value);
|
||||
}
|
||||
|
||||
public SettingsView(
|
||||
IConfigurationManager configurationManager,
|
||||
IViewManager viewManager)
|
||||
IViewManager viewManager,
|
||||
IShortcutManager shortcutManager)
|
||||
{
|
||||
this.shortcutManager = shortcutManager.ThrowIfNull(nameof(shortcutManager));
|
||||
this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager));
|
||||
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
||||
this.InitializeComponent();
|
||||
@@ -104,6 +123,8 @@ namespace Daybreak.Views
|
||||
this.BrowsersEnabled = config.BrowsersEnabled;
|
||||
this.AutoPlaceOnScreen = config.SetGuildwarsWindowSizeOnLaunch;
|
||||
this.DesiredScreen = config.DesiredGuildwarsScreen.ToString();
|
||||
this.ShortcutFolder = config.ShortcutLocation;
|
||||
this.ShortcutPlaced = this.shortcutManager.ShortcutEnabled;
|
||||
}
|
||||
|
||||
private void SaveButton_Clicked(object sender, EventArgs e)
|
||||
@@ -118,13 +139,14 @@ namespace Daybreak.Views
|
||||
currentConfig.BrowsersEnabled = this.BrowsersEnabled;
|
||||
currentConfig.SetGuildwarsWindowSizeOnLaunch = this.AutoPlaceOnScreen;
|
||||
currentConfig.DesiredGuildwarsScreen = int.Parse(this.DesiredScreen);
|
||||
currentConfig.ShortcutLocation = this.ShortcutFolder;
|
||||
this.configurationManager.SaveConfiguration(currentConfig);
|
||||
this.viewManager.ShowView<SettingsCategoryView>();
|
||||
}
|
||||
|
||||
private void ToolboxFilePickerGlyph_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var filePicker = new OpenFileDialog()
|
||||
var filePicker = new Microsoft.Win32.OpenFileDialog()
|
||||
{
|
||||
CheckFileExists = true,
|
||||
CheckPathExists = true,
|
||||
@@ -139,7 +161,7 @@ namespace Daybreak.Views
|
||||
|
||||
private void TexmodFilePickerGlyph_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var filePicker = new OpenFileDialog()
|
||||
var filePicker = new Microsoft.Win32.OpenFileDialog()
|
||||
{
|
||||
CheckFileExists = true,
|
||||
CheckPathExists = true,
|
||||
@@ -152,6 +174,21 @@ namespace Daybreak.Views
|
||||
}
|
||||
}
|
||||
|
||||
private void ShortcutFolderPickerGlyph_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var folderPicker = new FolderBrowserDialog()
|
||||
{
|
||||
Description = "Select shortcut folder",
|
||||
UseDescriptionForTitle = true,
|
||||
SelectedPath = this.ShortcutFolder,
|
||||
ShowNewFolderButton = true
|
||||
};
|
||||
if (folderPicker.ShowDialog() is DialogResult.OK)
|
||||
{
|
||||
this.ShortcutFolder = folderPicker.SelectedPath;
|
||||
}
|
||||
}
|
||||
|
||||
private void ScreenPickerGlyph_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
this.viewManager.ShowView<ScreenChoiceView>();
|
||||
@@ -169,5 +206,15 @@ namespace Daybreak.Views
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShortcutEnabled_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.shortcutManager.ShortcutEnabled = true;
|
||||
}
|
||||
|
||||
private void ShortcutEnabled_Unchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.shortcutManager.ShortcutEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user