Skip to content

Commit

Permalink
Merge pull request #33 from Crequency/dev=main
Browse files Browse the repository at this point in the history
[Pull Request] Adapt to new project structure
  • Loading branch information
Dynesshely committed Feb 28, 2024
2 parents 9245b7f + 0e8e8e9 commit 9ec0105
Show file tree
Hide file tree
Showing 89 changed files with 1,341 additions and 2,203 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Mirror Repo

on:
push:
branches:
- "*"
workflow_dispatch:

jobs:
mirror-repo:
runs-on: ubuntu-latest

steps:
- name: Mirror
uses: Yikun/hub-mirror-action@master
with:
src: github/Crequency
dst: gitee/Crequency
dst_key: ${{ secrets.GITEE_SYNC_KEY }}
dst_token: ${{ secrets.GITEE_SYNC_TOKEN }}
account_type: org
static_list: "KitX-Dashboard"
force_update: true
debug: true
39 changes: 27 additions & 12 deletions KitX Dashboard/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace KitX.Dashboard;
public partial class App : Application
{
public static readonly Bitmap DefaultIcon = new(
$"{ConstantTable.AssetsPath}{Instances.ConfigManager.AppConfig.App.CoverIconFileName}".GetFullPath()
$"{ConstantTable.AssetsPath}{ConfigManager.Instance.AppConfig.App.CoverIconFileName}".GetFullPath()
);

private AppViewModel? viewModel;
Expand All @@ -32,21 +32,34 @@ public override void Initialize()
{
AvaloniaXamlLoader.Load(this);

LoadTheme();

LoadLanguage();

CalculateThemeColor();

InitLiveCharts();
InitializeLiveCharts();

// Must construct after `LoadLanguage()` function.
viewModel = new();

DataContext = viewModel;
}

private void LoadTheme()
{
RequestedThemeVariant = ConfigManager.Instance.AppConfig.App.Theme switch
{
"Light" => ThemeVariant.Light,
"Dark" => ThemeVariant.Dark,
"Follow" => ThemeVariant.Default,
_ => ThemeVariant.Default
};
}

private void LoadLanguage()
{
var config = Instances.ConfigManager.AppConfig;
var config = ConfigManager.Instance.AppConfig;
var lang = config.App.AppLanguage;
var backup_lang = config.App.SurpportLanguages.Keys.First();
var path = $"{ConstantTable.LanguageFilePath}/{lang}.axaml".GetFullPath();
Expand Down Expand Up @@ -100,26 +113,28 @@ private void LoadLanguage()

private static void CalculateThemeColor()
{
Color c = Color.Parse(Instances.ConfigManager.AppConfig.App.ThemeColor);
Color c = Color.Parse(ConfigManager.Instance.AppConfig.App.ThemeColor);

if (Current is not null)
{
Current.Resources["ThemePrimaryAccent"] =
new SolidColorBrush(new Color(c.A, c.R, c.G, c.B));
Current.Resources["ThemePrimaryAccent"] = new SolidColorBrush(new Color(c.A, c.R, c.G, c.B));

for (char i = 'A'; i <= 'E'; ++i)
{
Current.Resources[$"ThemePrimaryAccentTransparent{i}{i}"] =
new SolidColorBrush(new Color((byte)(170 + (i - 'A') * 17), c.R, c.G, c.B));
Current.Resources[$"ThemePrimaryAccentTransparent{i}{i}"] = new SolidColorBrush(
new Color((byte)(170 + (i - 'A') * 17), c.R, c.G, c.B)
);
}
for (int i = 1; i <= 9; ++i)
{
Current.Resources[$"ThemePrimaryAccentTransparent{i}{i}"] =
new SolidColorBrush(new Color((byte)(i * 10 + i), c.R, c.G, c.B));
Current.Resources[$"ThemePrimaryAccentTransparent{i}{i}"] = new SolidColorBrush(
new Color((byte)(i * 10 + i), c.R, c.G, c.B)
);
}
}
}

private static void InitLiveCharts()
private static void InitializeLiveCharts()
{
{
var usingLightTheme = Current?.ActualThemeVariant == ThemeVariant.Light;
Expand Down Expand Up @@ -155,7 +170,7 @@ public override void OnFrameworkInitializationCompleted()
};
}

if (Instances.ConfigManager.AppConfig.App.ShowAnnouncementWhenStart)
if (ConfigManager.Instance.AppConfig.App.ShowAnnouncementWhenStart)
new Thread(async () =>
{
try
Expand Down
13 changes: 6 additions & 7 deletions KitX Dashboard/AppFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ public static void RunFramework()
if (File.Exists("./dump.log".GetFullPath()))
File.Delete("./dump.log".GetFullPath());

Instances.Initialize();

Instances.ConfigManager.AppConfig.App.RanTime++;
ConfigManager.Instance.AppConfig.App.RanTime++;

var config = Instances.ConfigManager.AppConfig;
var config = ConfigManager.Instance.AppConfig;

ProcessStartupArguments();

Expand Down Expand Up @@ -94,6 +92,8 @@ public static void RunFramework()

#endregion

Instances.Initialize();

#region Initialize global exception catching

AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
Expand Down Expand Up @@ -237,20 +237,19 @@ public static void EnsureExit()
Instances.FileWatcherManager?.Clear();
Instances.ConfigManager.SaveAll();
ConfigManager.Instance.SaveAll();
Log.CloseAndFlush();
if (Instances.WebManager is not null)
await Instances.WebManager.CloseAsync(new());
Instances.WebManager?.Dispose();
Instances.ActivitiesDataBase?.Commit();
Instances.ActivitiesDataBase?.Dispose();
ConstantTable.Running = false;
Thread.Sleep(Instances.ConfigManager.AppConfig.App.LastBreakAfterExit);
Thread.Sleep(ConfigManager.Instance.AppConfig.App.LastBreakAfterExit);
Environment.Exit(0);
}
Expand Down
6 changes: 2 additions & 4 deletions KitX Dashboard/Configuration/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ public class Config_SettingsPage

public string SelectedViewName { get; set; } = "View_General";

public bool MicaAreaExpanded { get; set; } = true;

public bool MicaToolTipIsOpen { get; set; } = true;

public bool PaletteAreaExpanded { get; set; } = false;

public bool WebRelatedAreaExpanded { get; set; } = true;
Expand Down Expand Up @@ -180,6 +176,8 @@ public class Config_Web

public List<string>? AcceptedNetworkInterfaces { get; set; } = null;

public int? UserSpecifiedDevicesServerPort { get; set; } = null;

public int? UserSpecifiedPluginsServerPort { get; set; } = null;

public int UdpPortSend { get; set; } = 23404;
Expand Down
6 changes: 4 additions & 2 deletions KitX Dashboard/Configuration/ConfigFetcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace KitX.Dashboard.Configuration;
using KitX.Dashboard.Managers;

namespace KitX.Dashboard.Configuration;

public class ConfigFetcher
{
public static AppConfig AppConfig => Instances.ConfigManager.AppConfig;
public static AppConfig AppConfig => ConfigManager.Instance.AppConfig;
}
2 changes: 1 addition & 1 deletion KitX Dashboard/Configuration/PluginsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace KitX.Dashboard.Configuration;

public class PluginsConfig : ConfigBase
{
public List<Plugin> Plugins { get; set; } = [];
public List<PluginInstallation> Plugins { get; set; } = [];
}
8 changes: 6 additions & 2 deletions KitX Dashboard/ConstantTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal static class ConstantTable

internal static string ThirdPartLicenseFilePath => thirdPartLicenseFilePath.GetFullPath();

internal static int DevicesServerPort = -1;

internal static int PluginsServerPort = -1;

internal static bool Running = true;
Expand All @@ -37,9 +39,11 @@ internal static class ConstantTable

internal static bool IsMainMachine = false;

internal static bool SkipNetworkSystemOnStartup = false;
internal static string? MainMachineAddress;

internal static int DevicesServerPort = -1;
internal static int MainMachinePort = -1;

internal static bool SkipNetworkSystemOnStartup = false;

internal static DateTime ServerBuildTime = new();

Expand Down
3 changes: 1 addition & 2 deletions KitX Dashboard/Converters/ActivityStatusConverters.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Avalonia.Data.Converters;
using Common.Activity;
using Material.Icons;
using System;
using System.Globalization;
using Material.Icons;
using Avalonia.Media;

namespace KitX.Dashboard.Converters;

Expand Down
42 changes: 42 additions & 0 deletions KitX Dashboard/Converters/DeviceInfoConverters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Avalonia.Data.Converters;
using KitX.Shared.CSharp.Device;
using System;
using System.Globalization;

namespace KitX.Dashboard.Converters;

public class PluginsServerAddressConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not DeviceInfo info) return null;

return $"{info.Device.IPv4}:{info.PluginsServerPort}";
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
}

public class DevicesServerAddressConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not DeviceInfo info) return null;

return $"{info.Device.IPv4}:{info.DevicesServerPort}";
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
}

public class DeviceLastOnLineTimeConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not DateTime time) return null;

return time.ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss");
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
}
33 changes: 0 additions & 33 deletions KitX Dashboard/Converters/OperatingSystem2Enum.cs

This file was deleted.

66 changes: 66 additions & 0 deletions KitX Dashboard/Converters/OperatingSystemUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Avalonia.Data.Converters;
using KitX.Shared.CSharp.Device;
using Material.Icons;
using System;
using System.Globalization;

namespace KitX.Dashboard.Converters;

public static class OperatingSystemUtils
{
public static OperatingSystems GetOSType()
{
if (OperatingSystem.IsAndroid())
return OperatingSystems.Android;
if (OperatingSystem.IsBrowser())
return OperatingSystems.Browser;
if (OperatingSystem.IsFreeBSD())
return OperatingSystems.FreeBSD;
if (OperatingSystem.IsIOS())
return OperatingSystems.IOS;
if (OperatingSystem.IsLinux())
return OperatingSystems.Linux;
if (OperatingSystem.IsMacCatalyst())
return OperatingSystems.MacCatalyst;
if (OperatingSystem.IsMacOS())
return OperatingSystems.MacOS;
if (OperatingSystem.IsTvOS())
return OperatingSystems.TvOS;
if (OperatingSystem.IsWatchOS())
return OperatingSystems.WatchOS;
if (OperatingSystem.IsWindows())
return OperatingSystems.Windows;

return OperatingSystems.Unknown;
}
}

public class OperatingSystemToIconConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is null) return null;

var os = (OperatingSystems)value;

return os switch
{
OperatingSystems.Unknown => MaterialIconKind.QuestionMarkCircle,
OperatingSystems.Android => MaterialIconKind.Android,
OperatingSystems.Browser => MaterialIconKind.MicrosoftEdge,
OperatingSystems.FreeBSD => MaterialIconKind.Freebsd,
OperatingSystems.IOS => MaterialIconKind.AppleIos,
OperatingSystems.Linux => MaterialIconKind.Linux,
OperatingSystems.MacCatalyst => MaterialIconKind.Apple,
OperatingSystems.MacOS => MaterialIconKind.AppleKeyboardCommand,
OperatingSystems.TvOS => MaterialIconKind.Apple,
OperatingSystems.WatchOS => MaterialIconKind.Apple,
OperatingSystems.Windows => MaterialIconKind.MicrosoftWindows,
OperatingSystems.IoT => MaterialIconKind.Chip,
OperatingSystems.AppleVisionOS => MaterialIconKind.Apple,
_ => MaterialIconKind.QuestionMarkCircle,
};
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
}
3 changes: 2 additions & 1 deletion KitX Dashboard/Converters/PluginInfoConverters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Data.Converters;
using KitX.Dashboard.Managers;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand All @@ -15,7 +16,7 @@ public class PluginMultiLanguagePropertyConverter : IValueConverter
if (value is Dictionary<string, string> dict)
{
var result = dict.TryGetValue(
Instances.ConfigManager.AppConfig.App.AppLanguage,
ConfigManager.Instance.AppConfig.App.AppLanguage,
out var lang
) ? lang : dict.Values.First();

Expand Down
Loading

0 comments on commit 9ec0105

Please sign in to comment.