| | |
| | | using Moli.Desktop.Plugins; |
| | | using Moli.Desktop.Runtime; |
| | | using Moli.Desktop.WebView; |
| | | using Brushes = System.Windows.Media.Brushes; |
| | | |
| | | namespace Moli.Desktop.Windows; |
| | | |
| | |
| | | private readonly DesktopPaths _paths; |
| | | private readonly IDiagnosticsService _diagnostics; |
| | | private bool _clickThrough = true; |
| | | private double _opacity = 1; |
| | | |
| | | public WallpaperWindow( |
| | | PluginDescriptor plugin, |
| | |
| | | public async Task LoadAsync(WallpaperRuntimeState state, CancellationToken cancellationToken = default) |
| | | { |
| | | _clickThrough = state.ClickThrough; |
| | | _opacity = state.Opacity; |
| | | Opacity = Math.Clamp(state.Opacity, 0.1, 1.0); |
| | | await _webView.InitializeAsync(new WebViewHostOptions |
| | | { |
| | | UserDataFolder = Path.Combine(_paths.WebViewDataDirectory, "wallpaper", _plugin.Id.Value), |
| | |
| | | public void ApplyState(WallpaperRuntimeState state, bool safeInputMode) |
| | | { |
| | | _clickThrough = !safeInputMode && state.ClickThrough; |
| | | _opacity = state.Opacity; |
| | | Opacity = Math.Clamp(state.Opacity, 0.1, 1.0); |
| | | ApplyWin32Styles(); |
| | | } |
| | |
| | | { |
| | | _interop.SetToolWindow(hwnd, true); |
| | | _interop.SetNoActivate(hwnd, true); |
| | | _interop.SetLayered(hwnd, true, ToAlpha(_opacity)); |
| | | _interop.SetLayered(hwnd, true); |
| | | _interop.SetClickThrough(hwnd, _clickThrough); |
| | | _interop.MoveToDesktopLayer(hwnd, DesktopLayerMode.WorkerW, _monitor); |
| | | _interop.MoveToDesktopLayer(hwnd, DesktopLayerMode.WorkerW, _monitor, _monitor.Bounds); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | new Dictionary<string, string> { ["pluginId"] = _plugin.Id.Value, ["exception"] = ex.GetType().Name }); |
| | | } |
| | | } |
| | | |
| | | private static byte ToAlpha(double opacity) => (byte)Math.Round(Math.Clamp(opacity, 0.1, 1.0) * 255); |
| | | } |