1
0
mirror of https://github.com/yattee/yattee.git synced 2025-04-28 16:00: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) .fontWeight(.bold)
.padding(.vertical, 10) .padding(.vertical, 10)
} }
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.horizontal, 20) .padding(.horizontal, 20)
} }
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
@ -152,6 +154,8 @@ struct OpenVideosView: View {
.fontWeight(.bold) .fontWeight(.bold)
.padding(.vertical, 10) .padding(.vertical, 10)
} }
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.horizontal, 20) .padding(.horizontal, 20)
} }
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
@ -174,6 +178,7 @@ struct OpenVideosView: View {
.padding(.vertical, 10) .padding(.vertical, 10)
} }
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.horizontal, 20) .padding(.horizontal, 20)
} }
.foregroundColor(.accentColor) .foregroundColor(.accentColor)

View File

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