mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Restore functionality in About pane of the settings window
This commit is contained in:
parent
ca6dee5180
commit
21fb4c6053
3 changed files with 175 additions and 22 deletions
|
|
@ -0,0 +1,134 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
public partial class SettingsPaneAboutViewModel : BaseModel
|
||||
{
|
||||
private readonly Settings _settings;
|
||||
private readonly Updater _updater;
|
||||
|
||||
public string LogFolderSize
|
||||
{
|
||||
get
|
||||
{
|
||||
var size = GetLogFiles().Sum(file => file.Length);
|
||||
return $"{InternationalizationManager.Instance.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})";
|
||||
}
|
||||
}
|
||||
|
||||
public string Website => Constant.Website;
|
||||
public string SponsorPage => Constant.SponsorPage;
|
||||
public string ReleaseNotes => _updater.GitHubRepository + "/releases/latest";
|
||||
public string Documentation => Constant.Documentation;
|
||||
public string Docs => Constant.Docs;
|
||||
public string Github => Constant.GitHub;
|
||||
|
||||
public string Version => Constant.Version switch
|
||||
{
|
||||
"1.0.0" => Constant.Dev,
|
||||
_ => Constant.Version
|
||||
};
|
||||
|
||||
public string ActivatedTimes => string.Format(
|
||||
InternationalizationManager.Instance.GetTranslation("about_activate_times"),
|
||||
_settings.ActivateTimes
|
||||
);
|
||||
|
||||
public SettingsPaneAboutViewModel(Settings settings, Updater updater)
|
||||
{
|
||||
_settings = settings;
|
||||
_updater = updater;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenWelcomeWindow()
|
||||
{
|
||||
var window = new WelcomeWindow(_settings);
|
||||
window.ShowDialog();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AskClearLogFolderConfirmation()
|
||||
{
|
||||
var confirmResult = MessageBox.Show(
|
||||
InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),
|
||||
InternationalizationManager.Instance.GetTranslation("clearlogfolder"),
|
||||
MessageBoxButton.YesNo
|
||||
);
|
||||
|
||||
if (confirmResult == MessageBoxResult.Yes)
|
||||
{
|
||||
ClearLogFolder();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenSettingsFolder()
|
||||
{
|
||||
PluginManager.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Settings));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenLogsFolder()
|
||||
{
|
||||
App.API.OpenDirectory(GetLogDir(Constant.Version).FullName);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private Task UpdateApp() => _updater.UpdateAppAsync(App.API, false);
|
||||
|
||||
private void ClearLogFolder()
|
||||
{
|
||||
var logDirectory = GetLogDir();
|
||||
var logFiles = GetLogFiles();
|
||||
|
||||
logFiles.ForEach(f => f.Delete());
|
||||
|
||||
logDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
|
||||
.Where(dir => !Constant.Version.Equals(dir.Name))
|
||||
.ToList()
|
||||
.ForEach(dir => dir.Delete());
|
||||
|
||||
OnPropertyChanged(nameof(LogFolderSize));
|
||||
}
|
||||
|
||||
private static DirectoryInfo GetLogDir(string version = "")
|
||||
{
|
||||
return new DirectoryInfo(Path.Combine(DataLocation.DataDirectory(), Constant.Logs, version));
|
||||
}
|
||||
|
||||
private static List<FileInfo> GetLogFiles(string version = "")
|
||||
{
|
||||
return GetLogDir(version).EnumerateFiles("*", SearchOption.AllDirectories).ToList();
|
||||
}
|
||||
|
||||
private static string BytesToReadableString(long bytes)
|
||||
{
|
||||
const int scale = 1024;
|
||||
string[] orders = { "GB", "MB", "KB", "B" };
|
||||
long max = (long)Math.Pow(scale, orders.Length - 1);
|
||||
|
||||
foreach (string order in orders)
|
||||
{
|
||||
if (bytes > max)
|
||||
return $"{decimal.Divide(bytes, max):##.##} {order}";
|
||||
|
||||
max /= scale;
|
||||
}
|
||||
|
||||
return "0 B";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,18 +6,12 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
|
||||
xmlns:settingsVm="clr-namespace:Flow.Launcher.SettingPages.ViewModels"
|
||||
Title="About"
|
||||
d:DataContext="{d:DesignInstance Type=settingsVm:SettingsPaneAboutViewModel}"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<ui:Page.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Resources/SettingWindowStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<CollectionViewSource x:Key="SortedFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}" />
|
||||
</ResourceDictionary>
|
||||
</ui:Page.Resources>
|
||||
<ScrollViewer
|
||||
Margin="0,0,0,0"
|
||||
Background="{DynamicResource Color01B}"
|
||||
|
|
@ -36,7 +30,10 @@
|
|||
|
||||
<cc:Card Title="{Binding Version}" Sub="{DynamicResource version}" Icon="">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Margin="0,0,10,0" Content="{DynamicResource checkUpdates}" />
|
||||
<Button
|
||||
Margin="0,0,10,0"
|
||||
Command="{Binding UpdateAppCommand}"
|
||||
Content="{DynamicResource checkUpdates}" />
|
||||
<Button Padding="0" Style="{StaticResource AccentButtonStyle}">
|
||||
<Hyperlink
|
||||
NavigateUri="{Binding SponsorPage, Mode=OneWay}"
|
||||
|
|
@ -100,21 +97,32 @@
|
|||
|
||||
<cc:Card Title="{DynamicResource devtool}" Icon="">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Margin="0,0,12,0" Content="{Binding CheckLogFolder, Mode=OneWay}" />
|
||||
<Button
|
||||
Margin="0,0,12,0"
|
||||
Command="{Binding AskClearLogFolderConfirmationCommand}"
|
||||
Content="{Binding LogFolderSize, Mode=OneWay}" />
|
||||
<Button Content="" FontFamily="/Resources/#Segoe Fluent Icons" FontSize="20">
|
||||
<ui:FlyoutService.Flyout>
|
||||
<ui:MenuFlyout>
|
||||
<MenuItem Header="{DynamicResource welcomewindow}">
|
||||
<MenuItem
|
||||
Command="{Binding OpenWelcomeWindowCommand}"
|
||||
Header="{DynamicResource welcomewindow}">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Glyph="" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="{DynamicResource settingfolder}">
|
||||
|
||||
<MenuItem
|
||||
Command="{Binding OpenSettingsFolderCommand}"
|
||||
Header="{DynamicResource settingfolder}">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Glyph="" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="{DynamicResource logfolder}">
|
||||
|
||||
<MenuItem
|
||||
Command="{Binding OpenLogsFolderCommand}"
|
||||
Header="{DynamicResource logfolder}">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Glyph="" />
|
||||
</MenuItem.Icon>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,29 @@
|
|||
using System.Windows.Navigation;
|
||||
using System;
|
||||
using System.Windows.Navigation;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
public partial class SettingsPaneAbout
|
||||
{
|
||||
private SettingsPaneAboutViewModel _viewModel = null!;
|
||||
|
||||
public partial class SettingsPaneAbout
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
public SettingsPaneAbout()
|
||||
if (!IsInitialized)
|
||||
{
|
||||
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: { } updater })
|
||||
throw new ArgumentException("Settings are required for SettingsPaneAbout.");
|
||||
_viewModel = new SettingsPaneAboutViewModel(settings, updater);
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
App.API.OpenUrl(e.Uri.AbsoluteUri);
|
||||
e.Handled = true;
|
||||
}
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
App.API.OpenUrl(e.Uri.AbsoluteUri);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue