| | |
| | | using System.IO; |
| | | using System.Text.Json; |
| | | using System.Text.Json.Serialization; |
| | | using System.Windows; |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Layout; |
| | |
| | | { |
| | | "sample.wallpaper", |
| | | "sample.clock", |
| | | "sample.system-info" |
| | | "sample.system-info", |
| | | "sample.audio-visualizer" |
| | | }; |
| | | |
| | | private readonly DesktopPaths _paths; |
| | |
| | | } |
| | | |
| | | var targetDirectory = Path.Combine(_paths.PluginDirectory, manifest.Id); |
| | | CopyDirectoryMissingFiles(sourceDirectory, targetDirectory); |
| | | CopyDirectoryReplacingFiles(sourceDirectory, targetDirectory); |
| | | manifests.Add((manifest, manifest.Id)); |
| | | } |
| | | |
| | |
| | | foreach (var manifest in manifests.Where(manifest => manifest.Type == PluginType.Widget)) |
| | | { |
| | | var pluginId = new PluginId(manifest.Id); |
| | | if (layout.Instances.Any(instance => instance.PluginId == pluginId)) |
| | | var existingInstances = layout.Instances.Where(instance => instance.PluginId == pluginId).ToList(); |
| | | if (existingInstances.Count > 0) |
| | | { |
| | | if (RepairAudioVisualizerLayout(manifest, layout.Instances)) |
| | | { |
| | | changed = true; |
| | | } |
| | | |
| | | continue; |
| | | } |
| | | |
| | |
| | | PluginId = pluginId, |
| | | MonitorId = new MonitorId("primary"), |
| | | Bounds = new RectD( |
| | | manifest.DefaultLayout.X, |
| | | manifest.DefaultLayout.Y, |
| | | manifest.DefaultLayout.Width, |
| | | manifest.DefaultLayout.Height), |
| | | ResolveDefaultX(manifest), |
| | | ResolveDefaultY(manifest), |
| | | ResolveDefaultWidth(manifest), |
| | | ResolveDefaultHeight(manifest)), |
| | | IsLocked = manifest.DefaultLayout.Locked, |
| | | ClickThrough = manifest.DefaultLayout.ClickThrough, |
| | | Opacity = manifest.DefaultLayout.Opacity, |
| | | Scale = manifest.DefaultLayout.Scale |
| | | Scale = manifest.DefaultLayout.Scale, |
| | | DisplayPriority = manifest.DefaultLayout.DisplayPriority |
| | | }); |
| | | changed = true; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private static void CopyDirectoryMissingFiles(string sourceDirectory, string targetDirectory) |
| | | private static void CopyDirectoryReplacingFiles(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 (!File.Exists(targetFile)) |
| | | File.Copy(sourceFile, targetFile, overwrite: true); |
| | | } |
| | | } |
| | | |
| | | private static bool RepairAudioVisualizerLayout(PluginManifest manifest, IList<WidgetLayout> layouts) |
| | | { |
| | | File.Copy(sourceFile, targetFile); |
| | | if (!IsAudioVisualizer(manifest)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | var changed = false; |
| | | for (var index = 0; index < layouts.Count; index++) |
| | | { |
| | | var layout = layouts[index]; |
| | | if (layout.PluginId == new PluginId(manifest.Id) && layout.IsLocked) |
| | | { |
| | | layouts[index] = layout with { IsLocked = false }; |
| | | changed = true; |
| | | } |
| | | } |
| | | |
| | | return changed; |
| | | } |
| | | |
| | | private static bool IsAudioVisualizer(PluginManifest manifest) |
| | | => string.Equals(manifest.Id, "sample.audio-visualizer", StringComparison.OrdinalIgnoreCase); |
| | | |
| | | private static double ResolveDefaultX(PluginManifest manifest) |
| | | => IsAudioVisualizer(manifest) ? 0 : 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; |
| | | |
| | | private static double ResolveDefaultHeight(PluginManifest manifest) |
| | | => IsAudioVisualizer(manifest) |
| | | ? Math.Min(SystemParameters.PrimaryScreenHeight * 0.25, Math.Max(LayoutManager.MinHeight, manifest.DefaultLayout.Height)) |
| | | : manifest.DefaultLayout.Height; |
| | | |
| | | private static string? ResolveSamplePluginRoot() |
| | | { |
| | | var candidates = new[] |