Compare commits

...

6 Commits

Author SHA1 Message Date
intervinn
9e78bd4116
Merge b54e44aa58 into f75d755e9e 2025-03-20 23:23:46 -04:00
bluepilledgreat
f75d755e9e fix build warnings
Some checks failed
CI (Debug) / build (push) Has been cancelled
CI (Release) / build (push) Has been cancelled
CI (Release) / release (push) Has been cancelled
CI (Release) / release-test (push) Has been cancelled
2025-03-20 16:40:09 +00:00
Matt
12bc3ef6e7
Web environments (#4911)
* add web environments

* add comment

* update enum name

* fixes and improvements

* add new enum value

* update enum names
2025-03-20 16:39:02 +00:00
intervinn
b54e44aa58 remove content 2024-12-30 12:57:24 +03:00
intervinn
3e9e0fba16 Change font family depending on custom font 2024-12-17 17:14:22 +03:00
intervinn
7be311dda6 Split Fonts and CustomFont 2024-12-17 15:05:20 +03:00
10 changed files with 134 additions and 7 deletions

View File

@ -65,6 +65,20 @@ namespace Bloxstrap
);
private static bool _showingExceptionDialog = false;
private static string? _webUrl = null;
public static string WebUrl
{
get {
if (_webUrl != null)
return _webUrl;
string url = ConstructBloxstrapWebUrl();
if (Settings.Loaded) // only cache if settings are done loading
_webUrl = url;
return url;
}
}
public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS)
{
@ -126,6 +140,25 @@ namespace Bloxstrap
Terminate(ErrorCode.ERROR_INSTALL_FAILURE);
}
public static string ConstructBloxstrapWebUrl()
{
// dont let user switch web environment if debug mode is not on
if (Settings.Prop.WebEnvironment == WebEnvironment.Production || !Settings.Prop.DeveloperMode)
return "bloxstraplabs.com";
string? sub = Settings.Prop.WebEnvironment.GetDescription();
return $"web-{sub}.bloxstraplabs.com";
}
public static bool CanSendLogs()
{
// non developer mode always uses production
if (!Settings.Prop.DeveloperMode || Settings.Prop.WebEnvironment == WebEnvironment.Production)
return IsProductionBuild;
return true;
}
public static async Task<GithubRelease?> GetLatestRelease()
{
const string LOG_IDENT = "App::GetLatestRelease";
@ -157,7 +190,7 @@ namespace Bloxstrap
try
{
await HttpClient.GetAsync($"https://bloxstraplabs.com/metrics/post?key={key}&value={value}");
await HttpClient.GetAsync($"https://{WebUrl}/metrics/post?key={key}&value={value}");
}
catch (Exception ex)
{
@ -167,13 +200,13 @@ namespace Bloxstrap
public static async void SendLog()
{
if (!Settings.Prop.EnableAnalytics || !IsProductionBuild)
if (!Settings.Prop.EnableAnalytics || !CanSendLogs())
return;
try
{
await HttpClient.PostAsync(
$"https://bloxstraplabs.com/metrics/post-exception",
$"https://{WebUrl}/metrics/post-exception",
new StringContent(Logger.AsDocument)
);
}
@ -347,6 +380,9 @@ namespace Bloxstrap
Settings.Save();
}
Logger.WriteLine(LOG_IDENT, $"Developer mode: {Settings.Prop.DeveloperMode}");
Logger.WriteLine(LOG_IDENT, $"Web environment: {Settings.Prop.WebEnvironment}");
Locale.Set(Settings.Prop.Locale);
if (!LaunchSettings.BypassUpdateCheck)

View File

@ -0,0 +1,26 @@
using System.ComponentModel;
namespace Bloxstrap.Enums
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum WebEnvironment
{
[Description("prod")]
Production,
[Description("stage")]
Staging,
[Description("dev")]
Dev,
[Description("pizza")]
DevPizza,
[Description("matt")]
DevMatt,
[Description("local")]
Local
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel;
using System.Reflection;
namespace Bloxstrap.Extensions
{
internal static class TEnumEx
{
public static string? GetDescription<TEnum>(this TEnum e)
{
string? enumName = e?.ToString();
if (enumName == null)
return null;
FieldInfo? field = e?.GetType().GetField(enumName);
if (field == null)
return null;
DescriptionAttribute? attribute = field.GetCustomAttribute<DescriptionAttribute>();
return attribute?.Description;
}
}
}

View File

@ -13,6 +13,8 @@ namespace Bloxstrap
/// </summary>
public string? LastFileHash { get; private set; }
public bool Loaded { get; set; } = false;
public virtual string ClassName => typeof(T).Name;
public virtual string FileLocation => Path.Combine(Paths.Base, $"{ClassName}.json");
@ -35,6 +37,7 @@ namespace Bloxstrap
throw new ArgumentNullException("Deserialization returned null");
Prop = settings;
Loaded = true;
LastFileHash = MD5Hash.FromString(contents);
App.Logger.WriteLine(LOG_IDENT, "Loaded successfully!");

View File

@ -10,6 +10,8 @@ namespace Bloxstrap.Models.Persistable
public string BootstrapperTitle { get; set; } = App.ProjectName;
public string BootstrapperIconCustomLocation { get; set; } = "";
public Theme Theme { get; set; } = Theme.Default;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public bool DeveloperMode { get; set; } = false;
public bool CheckForUpdates { get; set; } = true;
public bool MultiInstanceLaunching { get; set; } = false;
public bool ConfirmLaunches { get; set; } = false;
@ -21,6 +23,7 @@ namespace Bloxstrap.Models.Persistable
public bool BackgroundUpdatesEnabled { get; set; } = true;
public bool DebugDisableVersionPackageCleanup { get; set; } = false;
public string? SelectedCustomTheme { get; set; } = null;
public WebEnvironment WebEnvironment { get; set; } = WebEnvironment.Production;
// integration configuration
public bool EnableActivityTracking { get; set; } = true;

View File

@ -26,7 +26,8 @@
public static string Application { get; private set; } = "";
public static string CustomFont => Path.Combine(Modifications, "content\\fonts\\CustomFont.ttf");
public static string Fonts => Path.Combine("content\\fonts");
public static string CustomFont => Path.Combine(Fonts, "CustomFont.ttf");
public static bool Initialized => !String.IsNullOrEmpty(Base);

View File

@ -29,6 +29,14 @@
<ui:ToggleSwitch IsChecked="{Binding AnalyticsEnabled, Mode=TwoWay}" />
</controls:OptionControl>
<!-- This does not need i18n as this is locked behind "Developer Mode" -->
<controls:OptionControl
Visibility="{Binding Path=WebEnvironmentVisibility, Mode=OneTime}"
Header="Web environment"
Description="Site to use for metrics">
<ComboBox Width="200" Padding="10,5,10,5" ItemsSource="{Binding WebEnvironments, Mode=OneWay}" SelectedValue="{Binding WebEnvironment, Mode=TwoWay}" />
</controls:OptionControl>
<ui:CardExpander Margin="0,8,0,0" IsExpanded="True">
<ui:CardExpander.Header>
<Grid>

View File

@ -99,7 +99,7 @@
Description="{x:Static resources:Strings.Menu_Mods_Misc_CustomFont_Description}">
<StackPanel>
<ui:Button Icon="DocumentAdd16" Content="{x:Static resources:Strings.Menu_Mods_Misc_CustomFont_Choose}" Command="{Binding ManageCustomFontCommand}" Visibility="{Binding ChooseCustomFontVisibility, Mode=OneWay}" />
<ui:Button Icon="Delete16" Content="{x:Static resources:Strings.Menu_Mods_Misc_CustomFont_Remove}" Appearance="Danger" Command="{Binding ManageCustomFontCommand}" Visibility="{Binding DeleteCustomFontVisibility, Mode=OneWay}" />
<ui:Button Icon="Delete16" FontFamily="{Binding DeleteCustomFontFontFamily}" Content="{x:Static resources:Strings.Menu_Mods_Misc_CustomFont_Remove}" Appearance="Danger" Command="{Binding ManageCustomFontCommand}" Visibility="{Binding DeleteCustomFontVisibility, Mode=OneWay}" />
</StackPanel>
</controls:OptionControl>
</StackPanel>

View File

@ -1,4 +1,5 @@
using System.Windows.Input;
using System.Windows;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Win32;
@ -7,6 +8,8 @@ namespace Bloxstrap.UI.ViewModels.Settings
{
public class BloxstrapViewModel : NotifyPropertyChangedViewModel
{
public WebEnvironment[] WebEnvironments => Enum.GetValues<WebEnvironment>();
public bool UpdateCheckingEnabled
{
get => App.Settings.Prop.CheckForUpdates;
@ -19,6 +22,14 @@ namespace Bloxstrap.UI.ViewModels.Settings
set => App.Settings.Prop.EnableAnalytics = value;
}
public WebEnvironment WebEnvironment
{
get => App.Settings.Prop.WebEnvironment;
set => App.Settings.Prop.WebEnvironment = value;
}
public Visibility WebEnvironmentVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed;
public bool ShouldExportConfig { get; set; } = true;
public bool ShouldExportLogs { get; set; } = true;

View File

@ -9,8 +9,10 @@ using Windows.Win32.Foundation;
using CommunityToolkit.Mvvm.Input;
using Bloxstrap.Models.SettingTasks;
using Bloxstrap.AppData;
using System.Drawing.Text;
using Wpf.Ui.Controls;
using System.Windows.Media;
namespace Bloxstrap.UI.ViewModels.Settings
{
@ -52,9 +54,12 @@ namespace Bloxstrap.UI.ViewModels.Settings
TextFontTask.NewState = dialog.FileName;
}
OnPropertyChanged(nameof(ChooseCustomFontVisibility));
OnPropertyChanged(nameof(DeleteCustomFontVisibility));
OnPropertyChanged(nameof(CustomFontName));
OnPropertyChanged(nameof(DeleteCustomFontFontFamily));
}
public ICommand OpenModsFolderCommand => new RelayCommand(OpenModsFolder);
@ -63,6 +68,18 @@ namespace Bloxstrap.UI.ViewModels.Settings
public Visibility DeleteCustomFontVisibility => !String.IsNullOrEmpty(TextFontTask.NewState) ? Visibility.Visible : Visibility.Collapsed;
public System.Windows.Media.FontFamily DeleteCustomFontFontFamily => new System.Windows.Media.FontFamily($"{TextFontTask.NewState}#{CustomFontName}");
public string CustomFontName
{
get
{
var families = Fonts.GetFontFamilies(TextFontTask.NewState);
var first = families.ElementAt(0);
return first.ToString().Split("#").ElementAt(first.ToString().Split("#").Count() - 1);
}
}
public ICommand ManageCustomFontCommand => new RelayCommand(ManageCustomFont);
public ICommand OpenCompatSettingsCommand => new RelayCommand(OpenCompatSettings);