Skip to content

Commit

Permalink
Fix connection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jun 25, 2024
1 parent 4de16b9 commit 9a4ce2b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
2 changes: 0 additions & 2 deletions Abyssal.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
Expand Down
Binary file not shown.
14 changes: 10 additions & 4 deletions Abyssal/Contents/Tip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Tip<Title> where Title: View {
var title: (() -> Title)? = nil
var content: (() -> String)? = nil

var permanent: Bool = false

private var popover: NSPopover
private var cachedSender: NSView?

Expand All @@ -39,7 +41,7 @@ class Tip<Title> where Title: View {
private var has: (title: Bool, content: Bool) {
(
title: title != nil,
content: content != nil && Defaults[.tipsEnabled]
content: content != nil && (permanent || Defaults[.tipsEnabled])
)
}

Expand All @@ -54,7 +56,7 @@ class Tip<Title> where Title: View {
}

var isAvailable: Bool {
has.title || has.content
has.title || has.content || permanent
}

var isShown: Bool {
Expand All @@ -66,13 +68,15 @@ class Tip<Title> where Title: View {
init(
preferredEdge: NSRectEdge = .minX,
delay: CGFloat = 0.5,
permanent: Bool = false,
rect positionRect: (() -> CGRect)? = nil,
offset positionOffset: (() -> CGPoint)? = nil,
title: (() -> Title)? = nil,
content: (() -> String)? = nil
) {
self.preferredEdge = preferredEdge
self.delay = delay
self.permanent = permanent

if let positionRect {
self.positionRect = positionRect
Expand All @@ -94,11 +98,12 @@ class Tip<Title> where Title: View {
convenience init(
preferredEdge: NSRectEdge = .minX,
delay: CGFloat = 0.5,
permanent: Bool = false,
title: (() -> Title)? = nil,
content: (() -> String)? = nil
) {
self.init(
preferredEdge: preferredEdge, delay: delay,
preferredEdge: preferredEdge, delay: delay, permanent: permanent,
rect: nil, offset: nil,
title: title, content: content
)
Expand All @@ -107,10 +112,11 @@ class Tip<Title> where Title: View {
convenience init(
preferredEdge: NSRectEdge = .minX,
delay: CGFloat = 0.5,
permanent: Bool = false,
content: (() -> String)? = nil
) where Title == EmptyView {
self.init(
preferredEdge: preferredEdge, delay: delay,
preferredEdge: preferredEdge, delay: delay, permanent: permanent,
title: nil, content: content
)
}
Expand Down
49 changes: 25 additions & 24 deletions Abyssal/Infrastructures/Managers/VersionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,35 @@ extension Version: Comparable {
struct VersionManager {
fileprivate static var remoteVersion: Version = .app

private static let task = URLSession.shared.dataTask(with: .releaseTags) { (data, response, error) in
print(data, response, error)
guard let data else { return }
private static var task: URLSessionTask?

static func fetchLatest() {
task?.cancel()
print("Started fetching latest version...")

do {
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
let tags = json
.compactMap { element in
element["name"] as? String
task = URLSession.shared.dataTask(with: .releaseTags) { (data, response, error) in
guard let data else { return }

do {
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
let tags = json
.compactMap { element in
element["name"] as? String
}
.compactMap { Version(from: $0) }
.sorted(by: >)

if let remote = tags.first, remote > .app {
VersionManager.remoteVersion = remote
print("Fetched latest version: \(remote)")
} else {
print("No newer version available.")
}
.compactMap { Version(from: $0) }
.sorted(by: >)

if let remote = tags.first, remote > .app {
VersionManager.remoteVersion = remote
print("Fetched latest version: \(remote)")
} else {
print("No newer version available.")
}
} catch {
print(error.localizedDescription)
}
} catch {
print(error.localizedDescription)
}
}

static func fetchLatest() {
task.cancel()
print("Started fetching latest version...")
task.resume()
task?.resume()
}
}
3 changes: 3 additions & 0 deletions Abyssal/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
}
}
}
},
"Click to check for updates." : {

},
"Dead zone" : {

Expand Down
6 changes: 3 additions & 3 deletions Abyssal/Settings/SettingsVersionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import SwiftUI

struct SettingsVersionView: View {
private let updateTip = Tip {
.init(localized: """
private let updateTip = Tip(permanent: true) {
Version.hasUpdate ? .init(localized: """
An update is available. Click to access the download page.
""")
""") : .init(localized: "Click to check for updates.")
}

var body: some View {
Expand Down
10 changes: 1 addition & 9 deletions Abyssal/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ struct SettingsView: View {
.padding(.vertical, 42)
}
.defaultScrollAnchor(.bottom)
#if DEBUG
.border(.green.opacity(0.1))
#endif

Form {
SettingsModifiersSection()
Expand All @@ -35,9 +32,6 @@ struct SettingsView: View {
}
.padding(1)
.defaultScrollAnchor(.bottom)
#if DEBUG
.border(.orange.opacity(0.1))
#endif
}
.frame(maxWidth: 370)

Expand All @@ -55,12 +49,10 @@ struct SettingsView: View {
.defaultScrollAnchor(.bottom)
.padding(1)
.padding(.top, -20)
#if DEBUG
.border(.blue.opacity(0.1))
#endif
}
.frame(maxWidth: 430)
}
.controlSize(.regular)
.formStyle(.grouped)
.scrollDisabled(true)
.padding(.horizontal, -12) // Don't know why, but needed
Expand Down

0 comments on commit 9a4ce2b

Please sign in to comment.