Stop media playback when the main window is closed. Issue #1646
This commit is contained in:
parent
a465045888
commit
85bd20ca80
@ -56,6 +56,10 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
|||||||
currentWebViewController = webViewController(for: mode)
|
currentWebViewController = webViewController(for: mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stopMediaPlayback() {
|
||||||
|
currentWebViewController.stopMediaPlayback()
|
||||||
|
}
|
||||||
|
|
||||||
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
||||||
currentWebViewController.canScrollDown(callback)
|
currentWebViewController.canScrollDown(callback)
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,12 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
|
|||||||
reloadHTML()
|
reloadHTML()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Media Functions
|
||||||
|
|
||||||
|
func stopMediaPlayback() {
|
||||||
|
webView.evaluateJavaScript("stopMediaPlayback();")
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Scrolling
|
// MARK: Scrolling
|
||||||
|
|
||||||
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
||||||
|
@ -376,6 +376,14 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: NSWindowDelegate
|
||||||
|
|
||||||
|
extension MainWindowController: NSWindowDelegate {
|
||||||
|
func windowWillClose(_ notification: Notification) {
|
||||||
|
detailViewController?.stopMediaPlayback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - SidebarDelegate
|
// MARK: - SidebarDelegate
|
||||||
|
|
||||||
extension MainWindowController: SidebarDelegate {
|
extension MainWindowController: SidebarDelegate {
|
||||||
|
@ -358,6 +358,17 @@ private extension ArticleRenderer {
|
|||||||
window.webkit.messageHandlers.mouseDidExit.postMessage(anchor.href);
|
window.webkit.messageHandlers.mouseDidExit.postMessage(anchor.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stopMediaPlayback() {
|
||||||
|
document.querySelectorAll("iframe").forEach(element => {
|
||||||
|
var iframeSrc = element.src;
|
||||||
|
element.src = iframeSrc;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll("video, audio").forEach(element => {
|
||||||
|
element.pause();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user