-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
96 lines (84 loc) · 3.22 KB
/
Copy pathPlugin.cs
File metadata and controls
96 lines (84 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using QuickLook.Common.Plugin;
using QuickLook.Plugin.XdfViewer.Xdf;
using QuickLook.Plugin.XdfViewer.Xdf.Model;
using QuickLook.Plugin.XdfViewer.ViewModels;
namespace QuickLook.Plugin.XdfViewer
{
public class Plugin : IViewer
{
private XdfPreviewPanel _panel;
public int Priority => 0;
public void Init() { }
public bool CanHandle(string path)
{
return !Directory.Exists(path)
&& path.EndsWith(".xdf", StringComparison.OrdinalIgnoreCase);
}
public void Prepare(string path, ContextObject context)
{
context.PreferredSize = new Size(750, 550);
}
public void View(string path, ContextObject context)
{
var panel = new XdfPreviewPanel();
_panel = panel;
panel.ApplyTheme(context.Theme);
var fileName = Path.GetFileName(path);
context.ViewerContent = panel;
context.Title = fileName;
Task.Run(() =>
{
XdfFile file = null;
XdfOverviewViewModel vm = null;
// Phase 1: read the file structure and show the overview immediately. This must
// stay instant, so it only does the cheap structural parse (no sample decoding).
try
{
file = XdfReader.Read(path);
vm = file == null ? null : new XdfOverviewViewModel(file, fileName);
panel.Dispatcher.Invoke(() =>
{
panel.ShowModel(vm);
context.IsBusy = false;
});
}
catch (Exception ex)
{
panel.Dispatcher.Invoke(() =>
{
panel.ShowError(ex.Message);
context.IsBusy = false;
});
return;
}
if (file == null || vm == null) return;
// Phase 2: background sparkline pass. Runs after the overview is already on screen;
// a failure here must not disturb the overview that Phase 1 already showed, so it's
// isolated in its own try/catch and never calls ShowError.
try
{
panel.Dispatcher.Invoke(() => panel.SetDataSource(path, file));
var envs = XdfReader.FillEnvelopes(file, path, new EnvelopeOptions
{
Buckets = XdfReader.SparklineBuckets,
MaxSamplesPerStream = XdfReader.MaxEnvelopeSamplesPerStream
});
panel.Dispatcher.Invoke(() => panel.ApplyEnvelopes(envs));
}
catch (Exception)
{
// Swallow: the overview already succeeded and is on screen. No sparklines is a
// degraded-but-fine outcome, not an error worth surfacing over a good preview.
}
});
}
public void Cleanup()
{
_panel = null;
}
}
}