1
0
mirror of https://github.com/yattee/yattee.git synced 2025-04-28 07:50:33 +05:30

Fix share actions

This commit is contained in:
Arkadiusz Fal 2022-11-10 21:58:45 +01:00
parent 6be5342183
commit 50479d6b2f
2 changed files with 36 additions and 17 deletions

View File

@ -128,6 +128,8 @@ struct OpenVideosView: View {
.fontWeight(.bold)
.padding(.vertical, 10)
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.horizontal, 20)
}
.foregroundColor(.accentColor)
@ -152,6 +154,8 @@ struct OpenVideosView: View {
.fontWeight(.bold)
.padding(.vertical, 10)
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.horizontal, 20)
}
.foregroundColor(.accentColor)
@ -174,6 +178,7 @@ struct OpenVideosView: View {
.padding(.vertical, 10)
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.horizontal, 20)
}
.foregroundColor(.accentColor)

View File

@ -11,20 +11,26 @@ struct ShareButton: View {
self.contentItem = contentItem
}
var body: some View {
Menu {
instanceActions
Divider()
if !accounts.isDemo {
youtubeActions
@ViewBuilder var body: some View {
if let video = contentItem.video, !video.localStreamIsFile {
Menu {
if video.localStreamIsRemoteURL {
remoteURLAction
} else {
instanceActions
Divider()
if !accounts.isDemo {
youtubeActions
}
}
} label: {
Label("Share...", systemImage: "square.and.arrow.up")
}
} label: {
Label("Share...", systemImage: "square.and.arrow.up")
.menuStyle(.borderlessButton)
#if os(macOS)
.frame(maxWidth: 35)
#endif
}
.menuStyle(.borderlessButton)
#if os(macOS)
.frame(maxWidth: 35)
#endif
}
private var instanceActions: some View {
@ -79,6 +85,14 @@ struct ShareButton: View {
contentItem.contentType == .video && contentItem.video?.videoID == player.currentVideo?.videoID
}
@ViewBuilder private var remoteURLAction: some View {
if let url = contentItem.video.localStream?.localURL {
Button(labelForShareURL()) {
shareAction(url)
}
}
}
private func shareAction(_ url: URL) {
#if os(macOS)
NSPasteboard.general.clearContents()
@ -90,18 +104,18 @@ struct ShareButton: View {
#endif
}
private func labelForShareURL(_ app: String, withTime: Bool = false) -> String {
private func labelForShareURL(_ app: String? = nil, withTime: Bool = false) -> String {
if withTime {
#if os(macOS)
return String(format: "Copy %@ link with time".localized(), app)
return String(format: "Copy %@ link with time".localized(), app ?? "")
#else
return String(format: "Share %@ link with time".localized(), app)
return String(format: "Share %@ link with time".localized(), app ?? "")
#endif
} else {
#if os(macOS)
return String(format: "Copy %@ link".localized(), app)
return String(format: "Copy%@link".localized(), app == nil ? " " : " \(app!) ")
#else
return String(format: "Share %@ link".localized(), app)
return String(format: "Share%@link".localized(), app == nil ? " " : " \(app!) ")
#endif
}
}