From 10dd331251de6cc947c5ccc22b9daa089cbb2485 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Tue, 22 Aug 2023 00:14:47 +0200 Subject: [PATCH] feat: add reload event work on issue #22 --- .../Sources/CodeViewer/CodeWebView+Mode.swift | 1 - PlantUMLEditor/Sources/CodeViewer/CodeWebView.swift | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/PlantUMLEditor/Sources/CodeViewer/CodeWebView+Mode.swift b/PlantUMLEditor/Sources/CodeViewer/CodeWebView+Mode.swift index 2aa773a..3599d75 100644 --- a/PlantUMLEditor/Sources/CodeViewer/CodeWebView+Mode.swift +++ b/PlantUMLEditor/Sources/CodeViewer/CodeWebView+Mode.swift @@ -125,7 +125,6 @@ extension CodeWebView { case php_laravel_blade = "php_laravel_blade" case pig = "pig" case plain_text = "plain_text" - case plantuml = "plantuml" case powershell = "powershell" case praat = "praat" case prisma = "prisma" diff --git a/PlantUMLEditor/Sources/CodeViewer/CodeWebView.swift b/PlantUMLEditor/Sources/CodeViewer/CodeWebView.swift index 9001bde..a7f870f 100644 --- a/PlantUMLEditor/Sources/CodeViewer/CodeWebView.swift +++ b/PlantUMLEditor/Sources/CodeViewer/CodeWebView.swift @@ -7,6 +7,7 @@ // import WebKit +import Combine #if os(OSX) import AppKit @@ -63,7 +64,8 @@ public class CodeWebView: CustomView { private var pageLoaded = false private var pendingFunctions = [JavascriptFunction]() - + private var reloadCancellation:Cancellable? + var navigationDelegate:WKNavigationDelegate? { get { return webview.navigationDelegate @@ -145,6 +147,12 @@ public class CodeWebView: CustomView { extension CodeWebView { private func initWebView() { + + reloadCancellation = NotificationCenter.default.publisher(for: NSNotification.Name("reload")) + .sink(receiveValue: { [unowned self] _ in + webview.reloadFromOrigin() + }) + webview.translatesAutoresizingMaskIntoConstraints = false addSubview(webview) webview.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true