| | |
| | | _apiStatus = apiStatus; |
| | | _paths = paths; |
| | | InitializeComponent(); |
| | | DisplayPrioritySelector.ItemsSource = Enum.GetValues<DisplayPriority>(); |
| | | DisplayLayerSelector.ItemsSource = Enum.GetValues<DisplayLayer>(); |
| | | _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) }; |
| | | _timer.Tick += async (_, _) => await RefreshAsync(); |
| | | Loaded += async (_, _) => |
| | |
| | | WidgetSelector.ItemsSource = widgets; |
| | | WidgetSelector.SelectedItem = widgets.FirstOrDefault(widget => widget.InstanceId == selected) ?? widgets.FirstOrDefault(); |
| | | WidgetsGrid.ItemsSource = widgets; |
| | | DisplayPrioritySelector.SelectedItem = (WidgetSelector.SelectedItem as WidgetRow)?.DisplayPriority ?? DisplayPriority.IconLayer; |
| | | DisplayLayerSelector.SelectedItem = (WidgetSelector.SelectedItem as WidgetRow)?.DisplayLayer ?? DisplayLayer.Desktop; |
| | | PluginsGrid.ItemsSource = _state.Plugins.Select(PluginRow.From).ToArray(); |
| | | DiagnosticsGrid.ItemsSource = diagnostics.Select(DiagnosticRow.From).ToArray(); |
| | | RecentDiagnosticsGrid.ItemsSource = diagnostics.Take(8).Select(DiagnosticRow.From).ToArray(); |
| | |
| | | private async void ToggleSafeInput_Click(object sender, RoutedEventArgs e) => await ExecuteAsync(() => _runtime.SetSafeInputModeAsync(!(_state?.IsSafeInputMode ?? false))); |
| | | private async void ToggleGlobalLock_Click(object sender, RoutedEventArgs e) => await ExecuteAsync(() => _runtime.SetGlobalLockedAsync(!(_state?.IsGlobalLocked ?? false))); |
| | | private async void ReloadPlugins_Click(object sender, RoutedEventArgs e) => await ExecuteAsync(() => _runtime.ReloadPluginsAsync()); |
| | | private async void ApplyDisplayPriority_Click(object sender, RoutedEventArgs e) |
| | | private async void ApplyDisplayLayer_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | if (SelectedWidget() is not { } widget || DisplayPrioritySelector.SelectedItem is not DisplayPriority priority) |
| | | if (SelectedWidget() is not { } widget || DisplayLayerSelector.SelectedItem is not DisplayLayer layer) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | await ExecuteWidgetAsync(widget.InstanceId, new WidgetLayoutPatch { DisplayPriority = priority }); |
| | | if (layer == DisplayLayer.GlobalTop) |
| | | { |
| | | var choice = MessageBox.Show( |
| | | this, |
| | | "全局置顶会让该组件覆盖其他应用窗口。确认继续?", |
| | | "全局置顶", |
| | | MessageBoxButton.YesNo, |
| | | MessageBoxImage.Warning); |
| | | if (choice != MessageBoxResult.Yes) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | await ExecuteWidgetAsync(widget.InstanceId, new WidgetLayoutPatch { DisplayLayer = layer }); |
| | | } |
| | | |
| | | private async void ToggleWidgetVisible_Click(object sender, RoutedEventArgs e) |
| | |
| | | { |
| | | var choice = MessageBox.Show( |
| | | this, |
| | | "确认恢复默认布局和交互配置?此操作会显示并解锁组件,恢复透明度、点击穿透和默认显示优先级。", |
| | | "确认恢复默认布局和交互配置?此操作会显示并解锁组件,恢复透明度、点击穿透和默认显示层级。", |
| | | "恢复默认", |
| | | MessageBoxButton.YesNo, |
| | | MessageBoxImage.Warning); |
| | |
| | | IsLocked = false, |
| | | Opacity = 1, |
| | | ClickThrough = true, |
| | | DisplayPriority = DisplayPriority.IconLayer |
| | | DisplayLayer = DisplayLayer.Desktop |
| | | }); |
| | | } |
| | | |
| | |
| | | description = $"Loaded from {Path.GetFileName(fileName)}.", |
| | | author = "Moli.Desktop", |
| | | permissions = Array.Empty<string>(), |
| | | defaultLayout = new { width = 1920, height = 1080, x = 0, y = 0, locked = true, clickThrough = true, opacity = 1, scale = 1 }, |
| | | defaultLayout = new { width = 1920, height = 1080, x = 0, y = 0, locked = true, clickThrough = true, opacity = 1, scale = 1, displayLayer = "desktop" }, |
| | | config = new { sourceFile = fileName, sourceType = extension.TrimStart('.') } |
| | | }; |
| | | await File.WriteAllTextAsync( |
| | |
| | | |
| | | private static string Html(string value) => System.Net.WebUtility.HtmlEncode(value); |
| | | |
| | | private sealed record WidgetRow(string InstanceId, string PluginId, string Bounds, string MonitorId, bool IsVisible, bool IsLocked, double Opacity, bool ClickThrough, DisplayPriority DisplayPriority) |
| | | private sealed record WidgetRow(string InstanceId, string PluginId, string Bounds, string MonitorId, bool IsVisible, bool IsLocked, double Opacity, bool ClickThrough, DisplayLayer DisplayLayer) |
| | | { |
| | | public static WidgetRow From(WidgetRuntimeState state) |
| | | => new( |
| | |
| | | state.IsLocked, |
| | | state.Opacity, |
| | | state.ClickThrough, |
| | | state.DisplayPriority); |
| | | state.DisplayLayer); |
| | | } |
| | | |
| | | private sealed record PluginRow(string Id, string Name, string Type, string State, string? ErrorCode, string Entry) |