-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
313 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.ComponentModel; | ||
|
||
namespace Fischless.Linq; | ||
|
||
public abstract class SmartEnum<TEnum> where TEnum : struct | ||
{ | ||
public static TEnum? FromName(string name, TEnum? @default = default) | ||
{ | ||
if (Enum.TryParse(name, out TEnum @enum)) | ||
{ | ||
return @enum; | ||
} | ||
return @default; | ||
} | ||
|
||
public static TEnum? FromValue(int? value, TEnum? @default = default) | ||
{ | ||
if (value != null) | ||
{ | ||
if (Enum.TryParse(value.ToString(), out TEnum @enum)) | ||
{ | ||
return @enum; | ||
} | ||
} | ||
return @default; | ||
} | ||
|
||
public static TEnum? FromDescriptionAttribute(string? description, TEnum? @default = default) | ||
{ | ||
if (description != null) | ||
{ | ||
foreach (TEnum enumValue in Enum.GetValues(typeof(TEnum))) | ||
{ | ||
var enumMember = typeof(TEnum).GetMember(enumValue.ToString())[0]; | ||
if (enumMember.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() is DescriptionAttribute attribute && attribute.Description == description) | ||
{ | ||
return enumValue; | ||
} | ||
} | ||
} | ||
return @default; | ||
} | ||
|
||
public static string? ToDescriptionAttribute(TEnum? value, string? @default = default) | ||
{ | ||
if (value != null) | ||
{ | ||
var enumMember = typeof(TEnum).GetMember(value.ToString())[0]; | ||
if (enumMember.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() is DescriptionAttribute attribute) | ||
{ | ||
return attribute.Description; | ||
} | ||
} | ||
return @default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+230 KB
src/Desktop/LyricStudio/Assets/Images/UI_SummerTimeV2_Img_Island05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 93 additions & 1 deletion
94
src/Desktop/LyricStudio/ViewModels/Pages/SettingsPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,102 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Fischless.Globalization; | ||
using Fischless.Linq; | ||
using FluentAvalonia.Core; | ||
using LyricStudio.Core.Configuration; | ||
using LyricStudio.Models; | ||
using Serilog; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace LyricStudio.ViewModels; | ||
|
||
public class SettingsPageViewModel : ObservableObject | ||
public partial class SettingsPageViewModel : ObservableObject | ||
{ | ||
[ObservableProperty] | ||
private int languageIndex = (int)SmartEnum<LanguageIndex>.FromDescriptionAttribute(ConfigurationKeys.Language.Get(), Fischless.Globalization.LanguageIndex.Chinese)!; | ||
|
||
partial void OnLanguageIndexChanged(int value) | ||
{ | ||
string prev = SmartEnum<LanguageIndex>.ToDescriptionAttribute(SmartEnum<LanguageIndex>.FromValue(LanguageIndex)); | ||
string next = SmartEnum<LanguageIndex>.ToDescriptionAttribute(SmartEnum<LanguageIndex>.FromValue(value)); | ||
|
||
_ = prev; | ||
MuiLanguage.SetLanguage(next); | ||
ConfigurationKeys.Language.Set(next); | ||
Config.Configer?.Save(AppConfig.SettingsFile); | ||
} | ||
|
||
public SettingsPageViewModel() | ||
{ | ||
} | ||
|
||
[RelayCommand] | ||
private void CheckUpdate() | ||
{ | ||
try | ||
{ | ||
Process.Start(new ProcessStartInfo() | ||
{ | ||
FileName = "https://github.com/lemutec/LyricStudio/releases", | ||
UseShellExecute = true, | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e.Message); | ||
} | ||
} | ||
|
||
[RelayCommand] | ||
private void CheckLicense() | ||
{ | ||
try | ||
{ | ||
Process.Start(new ProcessStartInfo() | ||
{ | ||
FileName = "https://github.com/lemutec/LyricStudio/blob/master/LICENSE", | ||
UseShellExecute = true, | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e.Message); | ||
} | ||
} | ||
|
||
[RelayCommand] | ||
private void OpenSpecialFolder() | ||
{ | ||
try | ||
{ | ||
Process.Start(new ProcessStartInfo() | ||
{ | ||
FileName = $"file://{new FileInfo(AppConfig.SettingsFile).DirectoryName}/", | ||
UseShellExecute = true, | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e.Message); | ||
} | ||
} | ||
|
||
[RelayCommand] | ||
private void OpenLogsFolder() | ||
{ | ||
try | ||
{ | ||
Process.Start(new ProcessStartInfo() | ||
{ | ||
FileName = $"file://{AppConfig.LogFolder}/", | ||
UseShellExecute = true, | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters