Get the URL of the current page on macOS

This commit is contained in:
Balazs Perlaki-Horvath 2025-05-08 10:10:29 +02:00 committed by Kelson
parent ba6f34fc53
commit 1fa79ec5dd
4 changed files with 43 additions and 4 deletions

View File

@ -44,6 +44,11 @@ struct BrowserTab: View {
goForward: { [weak browser] in
browser?.webView.goForward()
})
if let url = browser.url {
CopyPasteMenu(url: url)
.keyboardShortcut("c", modifiers: [.command, .shift])
}
}
#elseif os(iOS)
ToolbarItemGroup(placement: .navigationBarLeading) {

View File

@ -18,15 +18,15 @@ import UniformTypeIdentifiers
struct CopyPasteMenu: View {
let downloadURL: URL
let url: URL
var body: some View {
Button {
#if os(macOS)
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(downloadURL.absoluteString, forType: .string)
NSPasteboard.general.setString(url.absoluteString, forType: .string)
#elseif os(iOS)
UIPasteboard.general.setValue(downloadURL.absoluteString, forPasteboardType: UTType.url.identifier)
UIPasteboard.general.setValue(url.absoluteString, forPasteboardType: UTType.url.identifier)
#endif
} label: {
Label(LocalString.library_zim_file_context_copy_url, systemImage: "doc.on.doc")

View File

@ -23,7 +23,7 @@ struct ZimFileContextMenu: View {
Section { ArticleActions(zimFileID: zimFile.fileID) }
}
if let downloadURL = zimFile.downloadURL {
Section { CopyPasteMenu(downloadURL: downloadURL) }
Section { CopyPasteMenu(url: downloadURL) }
}
}
}

View File

@ -0,0 +1,34 @@
// This file is part of Kiwix for iOS & macOS.
//
// Kiwix is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// any later version.
//
// Kiwix is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
#if os(macOS)
import SwiftUI
struct CopyURLContext: ViewModifier {
@State var url: URL?
func body(content: Content) -> some View {
if let url {
content.contextMenu {
CopyPasteMenu(url: url)
}
} else {
content
}
}
}
#endif