Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 52efade

Browse files
committed
Stop syncing for non authenticated users
1 parent 7a4adbf commit 52efade

File tree

2 files changed

+77
-66
lines changed

2 files changed

+77
-66
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11
1111

1212
## [Download from mac App Store](https://apps.apple.com/us/app/id1527428847)
1313

14-
![black_light_theme](https://user-images.githubusercontent.com/1506323/101370529-e48ce700-38a9-11eb-8a53-6cabada85a7e.png)
15-
14+
![black_light_theme](https://user-images.githubusercontent.com/1506323/110323754-5560ae00-8015-11eb-98a3-7822772cbe00.png)
1615

1716
## Features
1817

@@ -28,18 +27,21 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11
2827
* Light & Dark Mode
2928
* Theme selection
3029
* Atom file icons
30+
* Share snippet via [carbon.now.sh](https://carbon.now.sh/)
3131
* Create snippets via deeplinks from StackOverflow via [a Chrome Extension](https://chrome.google.com/webstore/detail/snip-extractor/fioamfejealgknedajclejcnbilifopf)
3232

3333

3434
## Editor
3535

3636
[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.
3737

38-
* CodeMirror v5.57.0
38+
* CodeMirror v5.59.4
3939
* Show/Hide invisible characters
4040
* Font size
4141
* Line Wrapping
4242
* 100+ themes available
43+
* Autocompletion hints (ctrl+space)
44+
* Reindent (ctrl+i)
4345

4446

4547
# Incoming
@@ -49,6 +51,12 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11
4951
- Search
5052

5153

54+
## Contributors
55+
56+
* [DKeu](https://dkeu.de/) for german Translation
57+
58+
5259
## Contributing
5360

5461
Contributions are always welcome!
62+

Snip/Components/Sidebar/SnipItemsListAction.swift

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -143,76 +143,79 @@ struct SnipItemsListAction {
143143
static func syncGists() -> SnipItemsListAction {
144144
return .init { current in
145145

146-
let currentSnips = current
147-
148-
DispatchQueue.global().async {
149-
SyncManager.shared.pullGists()
150-
.sink(receiveCompletion: { (_) in },
151-
receiveValue: { (gists) in
152-
153-
Publishers.MergeMany(gists.map( { SyncManager.shared.pullGist(id: $0.id) }))
154-
.collect()
155-
.sink(receiveCompletion: { (_) in},
156-
receiveValue: { (gists) in
157-
158-
var syncedSnips: [SnipItem] = []
159-
160-
// Transform all Gists to snipItems
161-
gists.forEach { (gist) in
162-
gist.files.forEach { (_, file) in
163-
let snipItem = file.toSnipItem()
164-
snipItem.gistNodeId = gist.nodeId
165-
snipItem.gistId = gist.id
166-
snipItem.gistURL = gist.url
167-
snipItem.remoteURL = gist.url
168-
snipItem.syncState = .synced
169-
syncedSnips.append(snipItem)
170-
}
171-
}
172-
173-
// Remove synced state of snips absent from Gists
174-
currentSnips.allGist.forEach { (snipItem) in
175-
let syncedSnip = syncedSnips.first(where: { $0.gistId == snipItem.gistId && $0.name == snipItem.name })
176-
if let syncedSnip = syncedSnip {
177-
DispatchQueue.main.async {
178-
let snipToSync = snipItem
179-
snipToSync.snippet = syncedSnip.snippet
180-
snipToSync.syncState = .synced
181-
snipToSync.gistId = syncedSnip.gistId
182-
snipToSync.gistURL = syncedSnip.gistURL
183-
snipToSync.gistNodeId = syncedSnip.gistNodeId
184-
snipToSync.remoteURL = syncedSnip.remoteURL
185-
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
146+
if SyncManager.shared.isAuthenticated {
147+
let currentSnips = current
148+
149+
DispatchQueue.global().async {
150+
SyncManager.shared.pullGists()
151+
.sink(receiveCompletion: { (_) in },
152+
receiveValue: { (gists) in
153+
154+
Publishers.MergeMany(gists.map( { SyncManager.shared.pullGist(id: $0.id) }))
155+
.collect()
156+
.sink(receiveCompletion: { (_) in},
157+
receiveValue: { (gists) in
158+
159+
var syncedSnips: [SnipItem] = []
160+
161+
// Transform all Gists to snipItems
162+
gists.forEach { (gist) in
163+
gist.files.forEach { (_, file) in
164+
let snipItem = file.toSnipItem()
165+
snipItem.gistNodeId = gist.nodeId
166+
snipItem.gistId = gist.id
167+
snipItem.gistURL = gist.url
168+
snipItem.remoteURL = gist.url
169+
snipItem.syncState = .synced
170+
syncedSnips.append(snipItem)
186171
}
187172
}
188-
else {
189-
DispatchQueue.main.async {
190-
let snipToSync = snipItem
191-
snipToSync.gistId = nil
192-
snipToSync.gistURL = nil
193-
snipToSync.gistNodeId = nil
194-
snipToSync.syncState = .local
195-
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
173+
174+
// Remove synced state of snips absent from Gists
175+
currentSnips.allGist.forEach { (snipItem) in
176+
let syncedSnip = syncedSnips.first(where: { $0.gistId == snipItem.gistId && $0.name == snipItem.name })
177+
if let syncedSnip = syncedSnip {
178+
DispatchQueue.main.async {
179+
let snipToSync = snipItem
180+
snipToSync.snippet = syncedSnip.snippet
181+
snipToSync.syncState = .synced
182+
snipToSync.gistId = syncedSnip.gistId
183+
snipToSync.gistURL = syncedSnip.gistURL
184+
snipToSync.gistNodeId = syncedSnip.gistNodeId
185+
snipToSync.remoteURL = syncedSnip.remoteURL
186+
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
187+
}
188+
}
189+
else {
190+
DispatchQueue.main.async {
191+
let snipToSync = snipItem
192+
snipToSync.gistId = nil
193+
snipToSync.gistURL = nil
194+
snipToSync.gistNodeId = nil
195+
snipToSync.syncState = .local
196+
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
197+
}
196198
}
197199
}
198-
}
199-
200-
// Add Gists
201-
syncedSnips.forEach { (syncedSnip) in
202-
let snipItem = currentSnips.first(where: { $0.gistId == syncedSnip.gistId })
203-
if snipItem == nil {
204-
DispatchQueue.main.async {
205-
SnippetManager.shared.trigger(action: .addSnippet(syncedSnip))
200+
201+
// Add Gists
202+
syncedSnips.forEach { (syncedSnip) in
203+
let snipItem = currentSnips.first(where: { $0.gistId == syncedSnip.gistId })
204+
if snipItem == nil {
205+
DispatchQueue.main.async {
206+
SnippetManager.shared.trigger(action: .addSnippet(syncedSnip))
207+
}
206208
}
207209
}
208-
}
209-
210-
})
211-
.store(in: &stores)
212-
213-
})
214-
.store(in: &stores)
210+
211+
})
212+
.store(in: &stores)
213+
214+
})
215+
.store(in: &stores)
216+
}
215217
}
218+
216219
}
217220
}
218221

0 commit comments

Comments
 (0)