Skip to content

Commit

Permalink
update single items from popup, re-check for updates from popup #145
Browse files Browse the repository at this point in the history
  • Loading branch information
quoid committed Aug 16, 2021
1 parent 0858b70 commit 3cc8211
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 96 deletions.
35 changes: 35 additions & 0 deletions extension/Userscripts Extension/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,41 @@ func getPopupBadgeCount(_ url: String, _ subframeUrls: [String]) -> Int? {
return matches.count
}

func popupUpdateSingle(_ filename: String, _ url: String, _ subframeUrls: [String]) -> [[String: Any]]? {
guard let saveLocation = getSaveLocation() else {
err("updateSingleItem failed at (1)")
return nil
}
// security scope
let didStartAccessing = saveLocation.startAccessingSecurityScopedResource()
defer {
if didStartAccessing { saveLocation.stopAccessingSecurityScopedResource() }
}
let fileUrl = saveLocation.appendingPathComponent(filename)
guard
let content = try? String(contentsOf: fileUrl, encoding: .utf8),
let parsed = parse(content),
let metadata = parsed["metadata"] as? [String: [String]],
let updateUrl = metadata["updateURL"]?[0]
else {
err("updateSingleItem failed at (2)")
return nil
}
let downloadUrl = metadata["downloadURL"] != nil ? metadata["downloadURL"]![0] : updateUrl
guard
let remoteFileContents = getRemoteFileContents(downloadUrl),
((try? remoteFileContents.write(to: fileUrl, atomically: false, encoding: .utf8)) != nil)
else {
err("updateSingleItem failed at (3)")
return nil
}
guard let matches = getPopupMatches(url, subframeUrls, true) else {
err("updateSingleItem failed at (4)")
return nil
}
return matches
}

// page
func getInitData() -> [String: Any]? {
let manifest = getManifest()
Expand Down
2 changes: 1 addition & 1 deletion extension/Userscripts Extension/Resources/popup.html

Large diffs are not rendered by default.

Loading

0 comments on commit 3cc8211

Please sign in to comment.