Show office exception instead of crash

This commit is contained in:
ema
2025-06-12 15:31:28 +08:00
parent e2e5885fd5
commit f897ce46ea
3 changed files with 17 additions and 11 deletions

View File

@@ -134,11 +134,22 @@ public class Plugin : IViewer
} }
} }
try
{
_panel = new PreviewPanel(); _panel = new PreviewPanel();
context.ViewerContent = _panel; context.ViewerContent = _panel;
context.Title = Path.GetFileName(path); context.Title = Path.GetFileName(path);
_panel.PreviewFile(path, context); _panel.PreviewFile(path, context);
}
catch (Exception e)
{
context.ViewerContent = new Label()
{
Content = e.ToString(),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
};
}
context.IsBusy = false; context.IsBusy = false;
} }

View File

@@ -102,9 +102,7 @@ public class PreviewHandlerHost : Control
CurrentPreviewHandler = guid; CurrentPreviewHandler = guid;
var o = Activator.CreateInstance(Type.GetTypeFromCLSID(CurrentPreviewHandler, true)); var o = Activator.CreateInstance(Type.GetTypeFromCLSID(CurrentPreviewHandler, true));
var fileInit = o as IInitializeWithFile; if (o is not IInitializeWithFile fileInit)
if (fileInit == null)
return false; return false;
fileInit.Initialize(path, 0); fileInit.Initialize(path, 0);

View File

@@ -44,9 +44,6 @@ public class PreviewPanel : WindowsFormsHost, IDisposable
_control = new PreviewHandlerHost(); _control = new PreviewHandlerHost();
Child = _control; Child = _control;
_control.Open(file); _control.Open(file);
//SetForegroundWindow(new WindowInteropHelper(context.ViewerWindow).Handle);
//SetActiveWindow(presenter.Handle);
} }
[DllImport("user32.dll")] [DllImport("user32.dll")]