Skip to content

Commit c7fa014

Browse files
committed
基础设施
1 parent fa03d17 commit c7fa014

10 files changed

Lines changed: 355 additions & 231 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
dotnet-quality: ga
2222

2323
- name: Restore
24-
run: dotnet restore InkCanvasX.sln -r win-x64
24+
run: dotnet restore InkCanvasX.sln
2525

2626
- name: Build
27-
run: dotnet build InkCanvasX.sln --configuration Debug --no-restore -p:Platform=x64 -r win-x64
27+
run: dotnet build InkCanvasX.sln --configuration Debug --no-restore -p:Platform=x64

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,8 @@ FodyWeavers.xsd
455455
telemetry_dsn.txt
456456
**/telemetry_dsn.txt
457457
/.claude
458+
/.tmp-jalium-controls
459+
/.tmp-jalium-core
460+
*.zip
461+
/.tmp-jalium-media
462+
/.tmp-jalium-input

InkCanvasX/App.xaml.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
using System;
2-
using System.Windows;
2+
using Jalium.UI;
3+
using Jalium.UI.Controls;
34
using SkiaAnnotate.Services;
45
using SkiaAnnotate.ViewModels;
56

67
namespace SkiaAnnotate;
78

8-
public partial class App : Application
9+
public sealed class App : Application
910
{
1011
private AnnotateViewModel? _backgroundViewModel;
1112

12-
static App()
13-
{
14-
// Use the modern Pointer pipeline for stylus input to improve WPF ink stability/smoothing.
15-
AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.EnablePointerSupport", true);
16-
}
17-
1813
protected override void OnStartup(StartupEventArgs e)
1914
{
2015
base.OnStartup(e);
@@ -40,15 +35,8 @@ protected override void OnExit(ExitEventArgs e)
4035
base.OnExit(e);
4136
}
4237

43-
private void RegisterGlobalExceptionHandlers()
38+
private static void RegisterGlobalExceptionHandlers()
4439
{
45-
DispatcherUnhandledException += (_, args) =>
46-
{
47-
AppLogger.Error("UI 线程未处理异常。", args.Exception);
48-
// Prevent crash for recoverable errors (COM busy etc.)
49-
args.Handled = true;
50-
};
51-
5240
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
5341
{
5442
if (args.ExceptionObject is Exception ex)
@@ -62,4 +50,3 @@ private void RegisterGlobalExceptionHandlers()
6250
};
6351
}
6452
}
65-

InkCanvasX/AssemblyInfo.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
using System.Windows;
2-
3-
[assembly:ThemeInfo(
4-
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5-
//(used if a resource is not found in the page,
6-
// or application resource dictionaries)
7-
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8-
//(used if a resource is not found in the page,
9-
// app, or any theme specific resource dictionaries)
10-
)]

InkCanvasX/InkCanvasX.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<TargetFramework>net10.0-windows</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
8-
<UseWPF>true</UseWPF>
98
<Platforms>AnyCPU;x64;x86</Platforms>
109
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
1110
<PublishSingleFile Condition="'$(PublishSingleFile)' == ''">true</PublishSingleFile>
@@ -14,15 +13,18 @@
1413

1514
<ItemGroup>
1615
<Compile Remove="Controls\SkiaInkCanvas.cs" />
16+
<Page Remove="App.xaml" />
1717
<Page Remove="Pages\AnnotatePage.xaml" />
1818
<Compile Remove="Pages\AnnotatePage.xaml.cs" />
1919
<Page Remove="MainWindow.xaml" />
2020
<Compile Remove="MainWindow.xaml.cs" />
21+
<Page Remove="Windows\AnnotationOverlayWindow.xaml" />
2122
</ItemGroup>
2223

2324
<ItemGroup>
2425
<PackageReference Include="Jalium.UI.Desktop" Version="26.10.3" />
2526
<PackageReference Include="Microsoft.Office.Interop.PowerPoint" Version="15.0.4420.1018" />
27+
<PackageReference Include="System.ObjectModel" Version="4.3.0" />
2628
</ItemGroup>
2729

2830
</Project>

InkCanvasX/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Jalium.UI.Controls;
2+
3+
namespace SkiaAnnotate;
4+
5+
internal static class Program
6+
{
7+
[System.STAThread]
8+
private static int Main(string[] args)
9+
{
10+
var app = new App
11+
{
12+
ShutdownMode = ShutdownMode.OnExplicitShutdown
13+
};
14+
return app.Run(args);
15+
}
16+
}

InkCanvasX/Services/PptInteropService.cs

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Runtime.InteropServices;
4-
using System.Windows;
5-
using System.Windows.Media.Imaging;
4+
using Jalium.UI;
65

76
namespace SkiaAnnotate.Services;
87

@@ -24,6 +23,12 @@ private struct RECT
2423
[DllImport("user32.dll", SetLastError = true)]
2524
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
2625

26+
[DllImport("user32.dll")]
27+
private static extern int GetSystemMetrics(int nIndex);
28+
29+
private const int smCxScreen = 0;
30+
private const int smCyScreen = 1;
31+
2732
private dynamic? _application;
2833
private dynamic? _presentation;
2934
private bool _ownsApplication;
@@ -91,47 +96,6 @@ public int GetSlideCount()
9196
return (int)_presentation!.Slides.Count;
9297
}
9398

94-
public BitmapImage RenderSlideToImage(int slideIndex, int width = 1600, int height = 900)
95-
{
96-
EnsurePresentation();
97-
var presentation = _presentation!;
98-
99-
if (slideIndex < 1 || slideIndex > presentation.Slides.Count)
100-
{
101-
throw new ArgumentOutOfRangeException(nameof(slideIndex), "幻灯片索引超出范围。");
102-
}
103-
104-
var tempFile = Path.Combine(Path.GetTempPath(), $"SkiaAnnotate_{Guid.NewGuid():N}.png");
105-
dynamic? slide = null;
106-
107-
try
108-
{
109-
slide = presentation.Slides[slideIndex];
110-
slide.Export(tempFile, "PNG", width, height);
111-
112-
var image = new BitmapImage();
113-
using var stream = File.OpenRead(tempFile);
114-
image.BeginInit();
115-
image.CacheOption = BitmapCacheOption.OnLoad;
116-
image.StreamSource = stream;
117-
image.EndInit();
118-
image.Freeze();
119-
return image;
120-
}
121-
finally
122-
{
123-
if (slide is not null)
124-
{
125-
Marshal.FinalReleaseComObject(slide);
126-
}
127-
128-
if (File.Exists(tempFile))
129-
{
130-
File.Delete(tempFile);
131-
}
132-
}
133-
}
134-
13599
public bool TryRefreshActivePresentation()
136100
{
137101
try
@@ -244,7 +208,7 @@ public Rect GetSlideShowBounds()
244208
var slideShowWindow = GetSlideShowWindowOrNull();
245209
if (slideShowWindow is null)
246210
{
247-
return new Rect(0, 0, SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);
211+
return new Rect(0, 0, GetSystemMetrics(smCxScreen), GetSystemMetrics(smCyScreen));
248212
}
249213

250214
try

InkCanvasX/Services/PresentationModeService.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Windows;
2-
using System.Windows.Input;
3-
using System.Windows.Ink;
4-
using System.Windows.Threading;
1+
using System.Runtime.InteropServices;
2+
using Jalium.UI;
3+
using Jalium.UI.Controls.Ink;
4+
using Jalium.UI.Threading;
55
using SkiaAnnotate.Windows;
66

77
namespace SkiaAnnotate.Services;
@@ -103,19 +103,31 @@ private void Enter(PptInteropService pptInteropService, Rect bounds, int current
103103
_overlayWindow = overlayWindow;
104104
overlayWindow.Show();
105105
overlayWindow.Activate();
106-
Keyboard.Focus(overlayWindow);
107106
_activeSlideNumber = currentSlideNumber;
108107
_isSlideContentInitialized = false;
109108
SyncStrokesForSlide(currentSlideNumber);
110109
}
111110

112111
private static Rect GetFullscreenCanvasBounds()
113112
{
113+
return GetSystemMetricsBounds();
114+
}
115+
116+
[DllImport("user32.dll")]
117+
private static extern int GetSystemMetrics(int nIndex);
118+
119+
private static Rect GetSystemMetricsBounds()
120+
{
121+
const int smXVirtualScreen = 76;
122+
const int smYVirtualScreen = 77;
123+
const int smCxVirtualScreen = 78;
124+
const int smCyVirtualScreen = 79;
125+
114126
return new Rect(
115-
SystemParameters.VirtualScreenLeft,
116-
SystemParameters.VirtualScreenTop,
117-
SystemParameters.VirtualScreenWidth,
118-
SystemParameters.VirtualScreenHeight);
127+
GetSystemMetrics(smXVirtualScreen),
128+
GetSystemMetrics(smYVirtualScreen),
129+
GetSystemMetrics(smCxVirtualScreen),
130+
GetSystemMetrics(smCyVirtualScreen));
119131
}
120132

121133
private void SyncStrokesForSlide(int currentSlideNumber)
@@ -174,7 +186,6 @@ private void HandlePreviousSlideRequested(PptInteropService pptInteropService)
174186

175187
private void ScheduleSlideSync(PptInteropService pptInteropService)
176188
{
177-
// First sync immediately, then retry a few short ticks to catch transition lag.
178189
var currentSlideNumber = pptInteropService.GetCurrentSlideNumberInShow();
179190
SyncStrokesForSlide(currentSlideNumber);
180191

InkCanvasX/ViewModels/AnnotateViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Runtime.CompilerServices;
5-
using System.Windows.Threading;
5+
using Jalium.UI.Threading;
66
using SkiaAnnotate.Commands;
77
using SkiaAnnotate.Services;
88

0 commit comments

Comments
 (0)