Fix: Refactor Collabora iframe setup for improved readability and maintainability

This commit is contained in:
Leon Bösche
2026-01-12 10:26:25 +01:00
parent 8e06e7e17d
commit ef60983534

View File

@@ -406,10 +406,11 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
// Build Collabora Online viewer URL with WOPISrc
// The WOPISrc must be URL-encoded and kept encoded
// We use a double-encoding approach: encodeComponent keeps it encoded through iframe.src
final baseUrl = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html';
final collaboraUrl = Uri.parse(baseUrl)
.replace(queryParameters: {'WOPISrc': wopiSession.wopisrc})
.toString();
final baseUrl =
'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html';
final collaboraUrl = Uri.parse(
baseUrl,
).replace(queryParameters: {'WOPISrc': wopiSession.wopisrc}).toString();
// Use WebView to display Collabora Online
return _buildWebView(collaboraUrl);
@@ -461,9 +462,7 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
// Create an iframe and submit a form to load the document
const String viewType = 'collabora-form';
ui.platformViewRegistry.registerViewFactory(
viewType,
(int viewId) {
ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) {
// Extract the WOPISrc from the URL
final uri = Uri.parse(collaboraUrl);
final wopisrc = uri.queryParameters['WOPISrc'] ?? '';
@@ -517,8 +516,7 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
});
return container;
},
);
});
return HtmlElementView(viewType: viewType);
}