diff --git a/README.md b/README.md index 22cea7b..32f27e7 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11 ## [Download from mac App Store](https://apps.apple.com/us/app/id1527428847) -![black_light_theme](https://user-images.githubusercontent.com/1506323/101370529-e48ce700-38a9-11eb-8a53-6cabada85a7e.png) - +![black_light_theme](https://user-images.githubusercontent.com/1506323/110323754-5560ae00-8015-11eb-98a3-7822772cbe00.png) ## Features @@ -28,6 +27,7 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11 * Light & Dark Mode * Theme selection * Atom file icons +* Share snippet via [carbon.now.sh](https://carbon.now.sh/) * Create snippets via deeplinks from StackOverflow via [a Chrome Extension](https://chrome.google.com/webstore/detail/snip-extractor/fioamfejealgknedajclejcnbilifopf) @@ -35,11 +35,13 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11 [CodeMirror-SwiftUI](https://github.com/Pictarine/CodeMirror-SwiftUI) is a fork from [CodeMirror-Swift](https://github.com/ProxymanApp/CodeMirror-Swift) by [NghiaTranUIT](https://github.com/NghiaTranUIT) 🙏, repackaged for SwiftUI. -* CodeMirror v5.57.0 +* CodeMirror v5.59.4 * Show/Hide invisible characters * Font size * Line Wrapping * 100+ themes available +* Autocompletion hints (ctrl+space) +* Reindent (ctrl+i) # Incoming @@ -49,6 +51,12 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11 - Search +## Contributors + +* [DKeu](https://dkeu.de/) for german Translation + + ## Contributing Contributions are always welcome! + diff --git a/Snip/Components/Sidebar/SnipItemsListAction.swift b/Snip/Components/Sidebar/SnipItemsListAction.swift index 85209e5..a00f7dd 100644 --- a/Snip/Components/Sidebar/SnipItemsListAction.swift +++ b/Snip/Components/Sidebar/SnipItemsListAction.swift @@ -143,76 +143,79 @@ struct SnipItemsListAction { static func syncGists() -> SnipItemsListAction { return .init { current in - let currentSnips = current - - DispatchQueue.global().async { - SyncManager.shared.pullGists() - .sink(receiveCompletion: { (_) in }, - receiveValue: { (gists) in - - Publishers.MergeMany(gists.map( { SyncManager.shared.pullGist(id: $0.id) })) - .collect() - .sink(receiveCompletion: { (_) in}, - receiveValue: { (gists) in - - var syncedSnips: [SnipItem] = [] - - // Transform all Gists to snipItems - gists.forEach { (gist) in - gist.files.forEach { (_, file) in - let snipItem = file.toSnipItem() - snipItem.gistNodeId = gist.nodeId - snipItem.gistId = gist.id - snipItem.gistURL = gist.url - snipItem.remoteURL = gist.url - snipItem.syncState = .synced - syncedSnips.append(snipItem) - } - } - - // Remove synced state of snips absent from Gists - currentSnips.allGist.forEach { (snipItem) in - let syncedSnip = syncedSnips.first(where: { $0.gistId == snipItem.gistId && $0.name == snipItem.name }) - if let syncedSnip = syncedSnip { - DispatchQueue.main.async { - let snipToSync = snipItem - snipToSync.snippet = syncedSnip.snippet - snipToSync.syncState = .synced - snipToSync.gistId = syncedSnip.gistId - snipToSync.gistURL = syncedSnip.gistURL - snipToSync.gistNodeId = syncedSnip.gistNodeId - snipToSync.remoteURL = syncedSnip.remoteURL - SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync)) + if SyncManager.shared.isAuthenticated { + let currentSnips = current + + DispatchQueue.global().async { + SyncManager.shared.pullGists() + .sink(receiveCompletion: { (_) in }, + receiveValue: { (gists) in + + Publishers.MergeMany(gists.map( { SyncManager.shared.pullGist(id: $0.id) })) + .collect() + .sink(receiveCompletion: { (_) in}, + receiveValue: { (gists) in + + var syncedSnips: [SnipItem] = [] + + // Transform all Gists to snipItems + gists.forEach { (gist) in + gist.files.forEach { (_, file) in + let snipItem = file.toSnipItem() + snipItem.gistNodeId = gist.nodeId + snipItem.gistId = gist.id + snipItem.gistURL = gist.url + snipItem.remoteURL = gist.url + snipItem.syncState = .synced + syncedSnips.append(snipItem) } } - else { - DispatchQueue.main.async { - let snipToSync = snipItem - snipToSync.gistId = nil - snipToSync.gistURL = nil - snipToSync.gistNodeId = nil - snipToSync.syncState = .local - SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync)) + + // Remove synced state of snips absent from Gists + currentSnips.allGist.forEach { (snipItem) in + let syncedSnip = syncedSnips.first(where: { $0.gistId == snipItem.gistId && $0.name == snipItem.name }) + if let syncedSnip = syncedSnip { + DispatchQueue.main.async { + let snipToSync = snipItem + snipToSync.snippet = syncedSnip.snippet + snipToSync.syncState = .synced + snipToSync.gistId = syncedSnip.gistId + snipToSync.gistURL = syncedSnip.gistURL + snipToSync.gistNodeId = syncedSnip.gistNodeId + snipToSync.remoteURL = syncedSnip.remoteURL + SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync)) + } + } + else { + DispatchQueue.main.async { + let snipToSync = snipItem + snipToSync.gistId = nil + snipToSync.gistURL = nil + snipToSync.gistNodeId = nil + snipToSync.syncState = .local + SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync)) + } } } - } - - // Add Gists - syncedSnips.forEach { (syncedSnip) in - let snipItem = currentSnips.first(where: { $0.gistId == syncedSnip.gistId }) - if snipItem == nil { - DispatchQueue.main.async { - SnippetManager.shared.trigger(action: .addSnippet(syncedSnip)) + + // Add Gists + syncedSnips.forEach { (syncedSnip) in + let snipItem = currentSnips.first(where: { $0.gistId == syncedSnip.gistId }) + if snipItem == nil { + DispatchQueue.main.async { + SnippetManager.shared.trigger(action: .addSnippet(syncedSnip)) + } } } - } - - }) - .store(in: &stores) - - }) - .store(in: &stores) + + }) + .store(in: &stores) + + }) + .store(in: &stores) + } } + } }