using System; using System.Diagnostics; using System.Reflection; using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Platform.Linux.Services; public class AppInfoService : IAppInfo { private static readonly Lazy _instance = new Lazy(() => new AppInfoService()); private readonly Assembly _entryAssembly; private readonly string _packageName; private readonly string _name; private readonly string _versionString; private readonly Version _version; private readonly string _buildString; public static AppInfoService Instance => _instance.Value; public string PackageName => _packageName; public string Name => _name; public string VersionString => _versionString; public Version Version => _version; public string BuildString => _buildString; public LayoutDirection RequestedLayoutDirection => (LayoutDirection)1; public AppTheme RequestedTheme { get { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) try { string environmentVariable = Environment.GetEnvironmentVariable("GTK_THEME"); if (!string.IsNullOrEmpty(environmentVariable) && environmentVariable.Contains("dark", StringComparison.OrdinalIgnoreCase)) { return (AppTheme)2; } if (GetGnomeColorScheme().Contains("dark", StringComparison.OrdinalIgnoreCase)) { return (AppTheme)2; } return (AppTheme)1; } catch { return (AppTheme)1; } } } public AppPackagingModel PackagingModel { get { if (Environment.GetEnvironmentVariable("FLATPAK_ID") == null) { if (Environment.GetEnvironmentVariable("SNAP") == null) { if (Environment.GetEnvironmentVariable("APPIMAGE") == null) { return (AppPackagingModel)1; } return (AppPackagingModel)0; } return (AppPackagingModel)0; } return (AppPackagingModel)0; } } public AppInfoService() { _entryAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); _packageName = _entryAssembly.GetName().Name ?? "Unknown"; _name = _entryAssembly.GetCustomAttribute()?.Title ?? _packageName; _versionString = (_version = _entryAssembly.GetName().Version ?? new Version(1, 0)).ToString(); _buildString = _entryAssembly.GetCustomAttribute()?.InformationalVersion ?? _versionString; } private string GetGnomeColorScheme() { try { using Process process = Process.Start(new ProcessStartInfo { FileName = "gsettings", Arguments = "get org.gnome.desktop.interface color-scheme", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }); if (process != null) { string text = process.StandardOutput.ReadToEnd(); process.WaitForExit(1000); return text.Trim().Trim('\''); } } catch { } return ""; } public void ShowSettingsUI() { try { Process.Start(new ProcessStartInfo { FileName = "gnome-control-center", UseShellExecute = true }); } catch { try { Process.Start(new ProcessStartInfo { FileName = "xdg-open", Arguments = "x-settings:", UseShellExecute = true }); } catch { } } } }