Skip to content

Commit

Permalink
test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Mar 11, 2021
1 parent b4d77e4 commit 2ada599
Show file tree
Hide file tree
Showing 38 changed files with 631 additions and 194 deletions.
3 changes: 3 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Read what we [milestones](https://github.com/SteamTools-Team/SteamTools/mileston
* [AvaloniaUI](https://github.com/AvaloniaUI/Avalonia)
* [Chromium Embedded Framework (CEF)](https://github.com/chromiumembedded/cef)
* [CefNet](https://github.com/CefNet/CefNet)
* [React](https://github.com/facebook/react)
* [Ant Design](https://github.com/ant-design/ant-design)
* [Ant Design Blazor](https://github.com/ant-design-blazor/ant-design-blazor)
* [Xamarin.Essentials](https://github.com/xamarin/essentials)
* [Entity Framework Core](https://github.com/dotnet/efcore)
* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
* [AvaloniaUI](https://github.com/AvaloniaUI/Avalonia)
* [Chromium Embedded Framework (CEF)](https://github.com/chromiumembedded/cef)
* [CefNet](https://github.com/CefNet/CefNet)
* [React](https://github.com/facebook/react)
* [Ant Design](https://github.com/ant-design/ant-design)
* [Ant Design Blazor](https://github.com/ant-design-blazor/ant-design-blazor)
* [Xamarin.Essentials](https://github.com/xamarin/essentials)
* [Entity Framework Core](https://github.com/dotnet/efcore)
* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Application.Models.Settings;
using System.Application.UI.Resx;
using System.Application.Models;
using System.Threading.Tasks;
#if WINDOWS
using System.Windows.Shell;
using WpfApplication = System.Windows.Application;
Expand Down Expand Up @@ -55,6 +54,17 @@ public AppTheme Theme
if (value == mTheme) return;
string? the;
FluentThemeMode mode;

if (value == AppTheme.FollowingSystem)
{
var dps = DI.Get<IDesktopPlatformService>();
var isLightOrDarkTheme = dps.IsLightOrDarkTheme;
if (isLightOrDarkTheme.HasValue)
{
value = isLightOrDarkTheme.Value ? AppTheme.Light : AppTheme.Dark;
}
}

switch (value)
{
case AppTheme.Light:
Expand Down
123 changes: 32 additions & 91 deletions System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.ReactiveUI;
using NLog;
using NLog.Config;
using System.IO;
using System.Properties;
using System.Reflection;
Expand All @@ -18,21 +19,17 @@ static class Program
[STAThread]
static void Main(string[] args)
{
FixNLogConfig();

// 目前桌面端默认使用 SystemTextJson 如果出现兼容性问题可取消下面这行代码
// Serializable.DefaultJsonImplType = Serializable.JsonImplType.NewtonsoftJson;

InitLogDir();

var logger = LogManager.GetCurrentClassLogger();
try
{
Migrations.FromV1();
Startup.Init();

#if DEBUG
//TestSecurityStorage();
#endif

#if WINDOWS
var app = new WpfApp();
app.InitializeComponent();
Expand Down Expand Up @@ -69,93 +66,37 @@ static AppBuilder BuildAvaloniaApp()
.LogToTrace()
.UseReactiveUI();

static void FixNLogConfig()
static void InitLogDir()
{
var isMac = DI.Platform == Platform.Apple && DI.DeviceIdiom == DeviceIdiom.Desktop;
const char directorySeparatorChar = '\\';
if (isMac || Path.DirectorySeparatorChar != directorySeparatorChar)
{
const string fileName = "nlog.config";
var filePath = Path.Combine(AppContext.BaseDirectory, fileName);
if (File.Exists(filePath))
{
string logConfigStr;
try
{
logConfigStr = File.ReadAllText(filePath);
}
catch
{
return;
}
string newValue;
if (isMac)
{
newValue = $"~/Library/Logs/{BuildConfig.APPLICATION_ID}/";
}
else
{
newValue = $"\"Logs{Path.DirectorySeparatorChar}";
}
logConfigStr = logConfigStr.Replace("\"Logs\\", newValue, StringComparison.OrdinalIgnoreCase);
File.Delete(filePath);
File.WriteAllText(filePath, logConfigStr);
}
}
var logDirPath = isMac ?
"~/Library/Logs/steam++" :
Path.Combine(AppContext.BaseDirectory, "Logs");
IOPath.DirCreateByNotExists(logDirPath);

var logDirPath_ = logDirPath + Path.DirectorySeparatorChar;

var xmlConfigStr =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" autoReload=\"true\"" +
$" internalLogFile=\"" + logDirPath_ + "internal-nlog.txt\"" +
" internalLogLevel=\"Off\">" +
" <targets>" +
" <target xsi:type=\"File\" name=\"logfile\" fileName=\"" + logDirPath_ + "nlog-all-${shortdate}.log\"" +
" layout=\"${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}\"/>" +
" <target xsi:type=\"Console\" name=\"logconsole\"" +
" layout=\"${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}\"/>" +
" </targets>" +
" <rules>" +
" <logger name=\"*\" minlevel=\"" + AppHelper.DefaultNLoggerMinLevel.Name + "\" writeTo=\"logfile,logconsole\"/>" +
" </rules>" +
"</nlog>"
;

var xmlConfig = XmlLoggingConfiguration.CreateFromXmlString(xmlConfigStr);
LogManager.Configuration = xmlConfig;
}

#if DEBUG

//static async void TestSecurityStorage()
//{
// await IStorage.Instance.SetAsync("↑↑", Encoding.UTF8.GetBytes("↓↓"));

// var left_top = Encoding.UTF8.GetString((
// await IStorage.Instance.GetAsync<byte[]>("↑↑")).ThrowIsNull("↑-key"));

// if (left_top != "↓↓")
// {
// throw new Exception();
// }

// await IStorage.Instance.SetAsync<string>("←←", "→→");

// var left_left = await IStorage.Instance.GetAsync<string>("←←");

// if (left_left != "→→")
// {
// throw new Exception();
// }

// await IStorage.Instance.SetAsync("aa", "bb");

// var left_aa = await IStorage.Instance.GetAsync("aa");

// if (left_aa != "bb")
// {
// throw new Exception();
// }

// var dict = new Dictionary<string, string> {
// { "🎈✨", "🎆🎇" },
// { "✨🎊", "🎃🎑" },
// };

// await IStorage.Instance.SetAsync("dict", dict);

// var left_dict = await IStorage.Instance.GetAsync<Dictionary<string, string>>("dict");

// if (left_dict == null)
// {
// throw new Exception();
// }

// if (left_dict.Count != dict.Count)
// {
// throw new Exception();
// }
//}

#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<DefineConstants>PUBLISH;$(DefineConstants)</DefineConstants>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<Platform>x64</Platform>
<PublishDir>bin\Release\Publish\linux-x64</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>link</TrimMode>
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
<!--剪裁框架库功能 https://docs.microsoft.com/zh-cn/dotnet/core/deploying/trimming-options#trimming-framework-library-features -->
<DebuggerSupport>false</DebuggerSupport>
<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
<EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<EventSourceSupport>false</EventSourceSupport>
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<DefineConstants>MAC;PUBLISH;$(DefineConstants)</DefineConstants>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<Platform>x64</Platform>
<PublishDir>bin\Release\Publish\osx-x64</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>link</TrimMode>
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
<!--剪裁框架库功能 https://docs.microsoft.com/zh-cn/dotnet/core/deploying/trimming-options#trimming-framework-library-features -->
<DebuggerSupport>false</DebuggerSupport>
<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
<EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<EventSourceSupport>false</EventSourceSupport>
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<!--可以通过将应用程序集编译为 ReadyToRun (R2R) 格式来改进 .NET Core 应用程序的启动时间和延迟。 R2R 是一种预先 (AOT) 编译形式 https://docs.microsoft.com/zh-cn/dotnet/core/deploying/ready-to-run-->
<!--可以通过将应用程序集编译为 ReadyToRun (R2R) 格式来改进 .NET Core 应用程序的启动时间和延迟。 R2R 是一种预先 (AOT) 编译形式 https://docs.microsoft.com/zh-cn/dotnet/core/deploying/ready-to-run -->
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>link</TrimMode>
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
<!--剪裁框架库功能 https://docs.microsoft.com/zh-cn/dotnet/core/deploying/trimming-options#trimming-framework-library-features-->
<!--剪裁框架库功能 https://docs.microsoft.com/zh-cn/dotnet/core/deploying/trimming-options#trimming-framework-library-features -->
<DebuggerSupport>false</DebuggerSupport>
<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
<EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//namespace System.Application.UI
//{
// public enum WebViewImplType : byte
// {
// ChromiumEmbeddedFramework,

// /// <summary>
// /// https://docs.microsoft.com/zh-cn/microsoft-edge/webview2
// /// </summary>
// MicrosoftEdgeWebView2InWPF,
// }
//}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,32 @@ protected override void OnBeforeCommandLineProcessing(string processType, CefCom
//commandLine.AppendSwitchWithValue("proxy-server", "127.0.0.1:8888");

//commandLine.AppendSwitchWithValue("remote-debugging-port", "9222");
commandLine.AppendSwitch("off-screen-rendering-enabled");
commandLine.AppendSwitchWithValue("off-screen-frame-rate", "30");
//commandLine.AppendSwitch("off-screen-rendering-enabled");
//commandLine.AppendSwitchWithValue("off-screen-frame-rate", "30");

if (ThisAssembly.Debuggable)
{
//enable-devtools-experiments
commandLine.AppendSwitch("enable-devtools-experiments");
}
//if (ThisAssembly.Debuggable)
//{
// //enable-devtools-experiments
// commandLine.AppendSwitch("enable-devtools-experiments");
//}

//e.CommandLine.AppendSwitchWithValue("user-agent", "Mozilla/5.0 (Windows 10.0) WebKa/" + DateTime.UtcNow.Ticks);

//("force-device-scale-factor", "1");

commandLine.AppendSwitch("disable-gpu");
commandLine.AppendSwitch("disable-gpu-compositing");
commandLine.AppendSwitch("disable-gpu-vsync");
commandLine.AppendSwitchWithValue("disable-gpu", "1");
commandLine.AppendSwitchWithValue("disable-gpu-compositing", "1");
commandLine.AppendSwitchWithValue("disable-gpu-vsync", "1");
commandLine.AppendSwitchWithValue("disable-gpu-shader-disk-cache", "1");

commandLine.AppendSwitch("enable-begin-frame-scheduling");
commandLine.AppendSwitch("enable-media-stream");
//commandLine.AppendSwitch("enable-begin-frame-scheduling");
//commandLine.AppendSwitch("enable-media-stream");

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
commandLine.AppendSwitch("no-zygote");
commandLine.AppendSwitch("no-sandbox");
}
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
//{
// commandLine.AppendSwitch("no-zygote");
// commandLine.AppendSwitch("no-sandbox");
//}
}

protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
Expand Down Expand Up @@ -123,9 +124,10 @@ public static void Init(string[] args)

var settings = new CefSettings
{
Locale = "zh-CN",
MultiThreadedMessageLoop = !externalMessagePump,
ExternalMessagePump = externalMessagePump,
NoSandbox = true,
NoSandbox = false,
WindowlessRenderingEnabled = true,
LocalesDirPath = localesDirPath,
ResourcesDirPath = cefPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia.Platform;
using Avalonia.Styling;
using System;
using System.Windows;

// ReSharper disable once CheckNamespace
namespace Avalonia.Controls
Expand All @@ -22,6 +23,8 @@ public FluentWindow(IWindowImpl impl) : base(impl)

void Constructor()
{
this.SetDefaultFontFamily();

ExtendClientAreaToDecorationsHint = true;
ExtendClientAreaTitleBarHeightHint = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ public string GetCommandLineArgs(Process process)

public void SetBootAutoStart(bool isAutoStart, string name)
{

}

public string? GetSteamDirPath()
{
return null;
var rootPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return Path.Combine(rootPath, "Steam");
}

public string? GetSteamProgramPath()
{
return null;
return "/usr/bin/steam";
}

public string GetLastSteamLoginUserName() => string.Empty;

public void SetCurrentUser(string userName) { }
public void SetCurrentUser(string userName)
{
}

static string GetMachineSecretKey()
{
Expand All @@ -51,5 +53,7 @@ static string GetMachineSecretKey()
static readonly Lazy<(byte[] key, byte[] iv)> mMachineSecretKey = IDesktopPlatformService.GetMachineSecretKey(GetMachineSecretKey);

public (byte[] key, byte[] iv) MachineSecretKey => mMachineSecretKey.Value;

public bool? IsLightOrDarkTheme => null;
}
}
Loading

0 comments on commit 2ada599

Please sign in to comment.