| | |
| | | "sample.wallpaper", |
| | | "sample.clock", |
| | | "sample.system-info", |
| | | "sample.audio-visualizer" |
| | | "sample.audio-visualizer", |
| | | "sample.llm-command-palette" |
| | | }; |
| | | |
| | | private readonly DesktopPaths _paths; |
| | |
| | | } |
| | | |
| | | var targetDirectory = Path.Combine(_paths.PluginDirectory, manifest.Id); |
| | | CopyDirectoryReplacingFiles(sourceDirectory, targetDirectory); |
| | | CopyDirectoryPreservingPluginConfig(sourceDirectory, targetDirectory); |
| | | manifests.Add((manifest, manifest.Id)); |
| | | } |
| | | |
| | |
| | | changed = true; |
| | | } |
| | | |
| | | if (RepairManifestClickThrough(manifest, layout.Instances)) |
| | | { |
| | | changed = true; |
| | | } |
| | | |
| | | continue; |
| | | } |
| | | |
| | |
| | | ClickThrough = manifest.DefaultLayout.ClickThrough, |
| | | Opacity = manifest.DefaultLayout.Opacity, |
| | | Scale = manifest.DefaultLayout.Scale, |
| | | DisplayPriority = manifest.DefaultLayout.DisplayPriority |
| | | DisplayLayer = manifest.DefaultLayout.DisplayLayer |
| | | }); |
| | | changed = true; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private static void CopyDirectoryReplacingFiles(string sourceDirectory, string targetDirectory) |
| | | private static void CopyDirectoryPreservingPluginConfig(string sourceDirectory, string targetDirectory) |
| | | { |
| | | Directory.CreateDirectory(targetDirectory); |
| | | |
| | |
| | | var relativePath = Path.GetRelativePath(sourceDirectory, sourceFile); |
| | | var targetFile = Path.Combine(targetDirectory, relativePath); |
| | | Directory.CreateDirectory(Path.GetDirectoryName(targetFile)!); |
| | | |
| | | if (string.Equals(relativePath, "plugin.json", StringComparison.OrdinalIgnoreCase) && |
| | | File.Exists(targetFile)) |
| | | { |
| | | File.Copy(sourceFile, Path.Combine(targetDirectory, "plugin.template.json"), overwrite: true); |
| | | continue; |
| | | } |
| | | |
| | | File.Copy(sourceFile, targetFile, overwrite: true); |
| | | } |
| | | } |
| | |
| | | return changed; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Heal instances whose persisted clickThrough drifted from the plugin default. |
| | | /// Interactive plugins (e.g. LLM palette) ship with clickThrough=false; "恢复默认" |
| | | /// used to force true for every widget and left them permanently unclickable. |
| | | /// </summary> |
| | | private static bool RepairManifestClickThrough(PluginManifest manifest, IList<WidgetLayout> layouts) |
| | | { |
| | | if (manifest.DefaultLayout.ClickThrough) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | var changed = false; |
| | | var pluginId = new PluginId(manifest.Id); |
| | | for (var index = 0; index < layouts.Count; index++) |
| | | { |
| | | var layout = layouts[index]; |
| | | if (layout.PluginId == pluginId && layout.ClickThrough) |
| | | { |
| | | layouts[index] = layout with { ClickThrough = false }; |
| | | changed = true; |
| | | } |
| | | } |
| | | |
| | | return changed; |
| | | } |
| | | |
| | | private static bool IsAudioVisualizer(PluginManifest manifest) |
| | | => string.Equals(manifest.Id, "sample.audio-visualizer", StringComparison.OrdinalIgnoreCase); |
| | | |
| | | private static bool IsLlmCommandPalette(PluginManifest manifest) |
| | | => string.Equals(manifest.Id, "sample.llm-command-palette", StringComparison.OrdinalIgnoreCase); |
| | | |
| | | private static double ResolveDefaultX(PluginManifest manifest) |
| | | => IsAudioVisualizer(manifest) ? 0 : manifest.DefaultLayout.X; |
| | | { |
| | | if (IsAudioVisualizer(manifest)) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | if (IsLlmCommandPalette(manifest)) |
| | | { |
| | | var width = ResolveDefaultWidth(manifest); |
| | | return Math.Max(0, (SystemParameters.PrimaryScreenWidth - width) / 2); |
| | | } |
| | | |
| | | return manifest.DefaultLayout.X; |
| | | } |
| | | |
| | | private static double ResolveDefaultY(PluginManifest manifest) |
| | | => IsAudioVisualizer(manifest) ? SystemParameters.PrimaryScreenHeight * 2 / 3 : manifest.DefaultLayout.Y; |
| | | |
| | | private static double ResolveDefaultWidth(PluginManifest manifest) |
| | | => IsAudioVisualizer(manifest) ? SystemParameters.PrimaryScreenWidth : manifest.DefaultLayout.Width; |
| | | => IsAudioVisualizer(manifest) |
| | | ? SystemParameters.PrimaryScreenWidth |
| | | : IsLlmCommandPalette(manifest) |
| | | ? Math.Min(manifest.DefaultLayout.Width, SystemParameters.PrimaryScreenWidth * 0.72) |
| | | : manifest.DefaultLayout.Width; |
| | | |
| | | private static double ResolveDefaultHeight(PluginManifest manifest) |
| | | => IsAudioVisualizer(manifest) |