Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions resources/ios/ShareFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@ enum ShareFunctions {
return ["error": "URL parameter is required"]
}

var shareItems: [Any] = []

if let urlObj = URL(string: url) {
shareItems.append(urlObj)
} else {
shareItems.append(url)
}

if !title.isEmpty {
shareItems.append(title)
}

if !text.isEmpty {
shareItems.append(text)
}
let shareText = text.isEmpty ? url : "\(text)\n\n\(url)"
let shareItems: [Any] = [shareText]

DispatchQueue.main.async {
guard let windowScene = UIApplication.shared.connectedScenes
Expand Down Expand Up @@ -90,14 +77,15 @@ enum ShareFunctions {
print("Share requested - title: '\(title)', message: '\(message)', filePath: '\(filePath ?? "nil")'")

var shareItems: [Any] = []
var shouldAppendTitle = true
var shouldAppendMessage = true

if let filePath = filePath, !filePath.isEmpty {
if isURL(filePath) {
if let url = URL(string: filePath) {
shareItems.append(url)
} else {
shareItems.append(filePath)
}
let textToShare = message.isEmpty ? filePath : "\(message)\n\n\(filePath)"
shareItems.append(textToShare)
shouldAppendTitle = false
shouldAppendMessage = false
} else {
let fileURL = URL(fileURLWithPath: filePath)

Expand All @@ -108,18 +96,19 @@ enum ShareFunctions {
print("File not found at path: \(filePath)")
if !message.isEmpty {
shareItems.append("\(message)\n\n\(filePath)")
shouldAppendMessage = false
} else {
shareItems.append(filePath)
}
}
}
}

if !title.isEmpty && !shareItems.contains(where: { $0 as? String == title }) {
if shouldAppendTitle && !title.isEmpty && !shareItems.contains(where: { $0 as? String == title }) {
shareItems.append(title)
}

if !message.isEmpty && !shareItems.contains(where: { $0 as? String == message }) {
if shouldAppendMessage && !message.isEmpty && !shareItems.contains(where: { $0 as? String == message }) {
shareItems.append(message)
}

Expand Down