Skip to content

Commit

Permalink
Removed dependency on libadwaita in Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
veler committed Aug 15, 2024
1 parent 7fd73a0 commit 3a3b9df
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/dev/DevToys.Blazor/wwwroot/css/devtoys.g.css

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions src/app/dev/platforms/desktop/DevToys.Linux/Core/ThemeListener.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Adw;
using DevToys.Api;
using DevToys.Api;
using DevToys.Core.Settings;
using DevToys.Blazor.Components;
using DevToys.Blazor.Core.Services;
Expand All @@ -13,7 +12,7 @@ internal sealed class ThemeListener : IThemeListener
{
private readonly ISettingsProvider _settingsProvider;
private readonly Gtk.Settings _gtkSettings;
private readonly StyleManager _adwStyleManager;
//private readonly StyleManager _adwStyleManager;

private Gtk.Window? _mainWindow;
private bool _ignoreOperatingSystemSettingChanged;
Expand All @@ -25,7 +24,7 @@ public ThemeListener(ISettingsProvider settingsProvider)
_settingsProvider = settingsProvider;
_settingsProvider.SettingChanged += SettingsProvider_SettingChanged;

_adwStyleManager = StyleManager.GetDefault();
//_adwStyleManager = StyleManager.GetDefault();

// Listen for operating system settings.
_gtkSettings = Gtk.Settings.GetDefault()!;
Expand Down Expand Up @@ -68,12 +67,12 @@ public void ApplyDesiredColorTheme()
if (theme == AvailableApplicationTheme.Dark)
{
ActualAppTheme = ApplicationTheme.Dark;
_adwStyleManager.ColorScheme = ColorScheme.ForceDark;
//_adwStyleManager.ColorScheme = ColorScheme.ForceDark;
}
else
{
ActualAppTheme = ApplicationTheme.Light;
_adwStyleManager.ColorScheme = ColorScheme.ForceLight;
//_adwStyleManager.ColorScheme = ColorScheme.ForceLight;
}

_ignoreOperatingSystemSettingChanged = false;
Expand Down Expand Up @@ -142,14 +141,19 @@ private bool GetBestValueForCompactMode()

private void UpdateSystemSettingsAndApplyTheme()
{
IsHighContrast = _adwStyleManager.HighContrast;
IsHighContrast
= _gtkSettings.GtkThemeName is not null
&& _gtkSettings.GtkThemeName.Contains("high", StringComparison.OrdinalIgnoreCase)
&& _gtkSettings.GtkThemeName.Contains("contrast", StringComparison.OrdinalIgnoreCase);
CurrentSystemTheme = GetCurrentSystemTheme();

ApplyDesiredColorTheme();
}

private AvailableApplicationTheme GetCurrentSystemTheme()
{
return _gtkSettings.GtkApplicationPreferDarkTheme ? AvailableApplicationTheme.Dark : AvailableApplicationTheme.Light;
return _gtkSettings.GtkApplicationPreferDarkTheme || (_gtkSettings.GtkThemeName?.Contains("Dark", StringComparison.OrdinalIgnoreCase) ?? false)
? AvailableApplicationTheme.Dark
: AvailableApplicationTheme.Light;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GirCore.Adw-1" />
<PackageReference Include="GirCore.Gtk-4.0" />
<PackageReference Include="GirCore.WebKit-6.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView" />
Expand Down
6 changes: 3 additions & 3 deletions src/app/dev/platforms/desktop/DevToys.Linux/LinuxProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal partial class LinuxProgram

internal LinuxProgram()
{
Application = Adw.Application.New(null, Gio.ApplicationFlags.NonUnique);
Application = Gtk.Application.New(null, Gio.ApplicationFlags.NonUnique);

GLib.Functions.SetPrgname("DevToys");
// Set the human-readable application name for app bar and task list.
Expand All @@ -41,7 +41,7 @@ internal LinuxProgram()
Application.OnShutdown += OnApplicationShutdown;
}

internal Adw.Application Application { get; }
internal Gtk.Application Application { get; }

private void OnApplicationActivate(object sender, object e)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ LanguageDefinition languageDefinition
LanguageManager.Instance.SetCurrentCulture(languageDefinition);

// Create and open main window.
_mainWindow = new MainWindow(serviceProvider, (Adw.Application)sender);
_mainWindow = new MainWindow(serviceProvider, (Gtk.Application)sender);
}

private void OnApplicationShutdown(object sender, object e)
Expand Down
2 changes: 1 addition & 1 deletion src/app/dev/platforms/desktop/DevToys.Linux/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class MainWindow
private readonly BlazorWebView _blazorGtkWebView;
private readonly Gtk.Window _window;

internal MainWindow(IServiceProvider serviceProvider, Adw.Application application)
internal MainWindow(IServiceProvider serviceProvider, Gtk.Application application)
{
serviceProvider.GetService<IMefProvider>()!.SatisfyImports(this);
Guard.IsNotNull(_themeListener);
Expand Down

0 comments on commit 3a3b9df

Please sign in to comment.