Skip to content

Commit

Permalink
add translation check for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Oct 11, 2023
1 parent f617456 commit dcb5949
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ProjBobcat/ProjBobcat/Class/Helper/SystemInfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static bool IsRunningUnderTranslation()
{
#if WINDOWS
return Platforms.Windows.SystemInfoHelper.IsRunningUnderTranslation();
#elif OSX
return Platforms.MacOS.SystemInfoHelper.IsRunningUnderTranslation();
#else
return false;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.Win32;
using Windows.Win32.Foundation;
using Microsoft.Extensions.Configuration;
using ProjBobcat.Class;
using ProjBobcat.Class.Helper;
Expand Down Expand Up @@ -358,10 +356,12 @@ await Task.Run(() =>
{
if (launchWrapper.Process == null) break;
#if WINDOWS
#pragma warning disable CA1416 // 验证平台兼容性
_ = PInvoke.SetWindowText(new HWND(launchWrapper.Process.MainWindowHandle),
_ = Windows.Win32.PInvoke.SetWindowText(new Windows.Win32.Foundation.HWND(launchWrapper.Process.MainWindowHandle),
settings.WindowTitle);
#pragma warning restore CA1416 // 验证平台兼容性
#endif
} while (string.IsNullOrEmpty(launchWrapper.Process?.MainWindowTitle));
});
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
Expand Down
14 changes: 14 additions & 0 deletions ProjBobcat/ProjBobcat/Platforms/MacOS/SystemInfoHelper.MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace ProjBobcat.Platforms.MacOS
{
static class SystemInfoHelper
{
[DllImport ("libc")]
static extern int sysctlbyname (string name, out int int_val, ref IntPtr length, IntPtr newp, IntPtr newlen);

public static IEnumerable<string> FindJavaMacOS()
{
const string rootPath = "/Library/Java/JavaVirtualMachines";
Expand Down Expand Up @@ -172,5 +176,15 @@ public static MemoryInfo GetOsxMemoryStatus()

return metrics;
}

public static bool IsRunningUnderTranslation()
{
var size = (IntPtr)sizeof(int);
var res = sysctlbyname ("hw.logicalcpu", out var value, ref size, IntPtr.Zero, (IntPtr)0);

if (res != 0) return false;

return value == 1;
}
}
}

0 comments on commit dcb5949

Please sign in to comment.