aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2024-02-02 11:53:39 -0700
committerNavan Chauhan <navanchauhan@gmail.com>2024-02-02 11:53:39 -0700
commitb45b238b1daf22ee7e01f93834385a377a9319ed (patch)
tree7ac204217df5d8da1c5de0738f11c60f32160053
parentceaec6c4056438671cb2a3db51ee3689d0bb93b6 (diff)
customize colours
-rw-r--r--iGopherBrowser/BrowserView.swift16
-rw-r--r--iGopherBrowser/SettingsView.swift63
2 files changed, 71 insertions, 8 deletions
diff --git a/iGopherBrowser/BrowserView.swift b/iGopherBrowser/BrowserView.swift
index aea4980..aa46818 100644
--- a/iGopherBrowser/BrowserView.swift
+++ b/iGopherBrowser/BrowserView.swift
@@ -20,6 +20,9 @@ func openURL(url: URL) {
struct BrowserView: View {
@AppStorage("homeURL") var homeURL: URL = URL(string: "gopher://gopher.navan.dev:70/")!
+ @AppStorage("accentColour", store: .standard) var accentColour: Color = Color(.blue)
+ @AppStorage("linkColour", store: .standard) var linkColour: Color = Color(.white)
+
@State var homeURLString = "gopher://gopher.navan.dev:70/"
@State var url: String = ""
@@ -64,7 +67,7 @@ struct BrowserView: View {
Text(Image(systemName: "folder"))
Text(item.message)
Spacer()
- }
+ }.foregroundStyle(linkColour)
}.buttonStyle(PlainButtonStyle())
} else if item.parsedItemType == .search {
@@ -76,7 +79,7 @@ struct BrowserView: View {
Text(Image(systemName: "magnifyingglass"))
Text(item.message)
Spacer()
- }
+ }.foregroundStyle(linkColour)
}.buttonStyle(PlainButtonStyle())
} else if item.parsedItemType == .text {
@@ -85,7 +88,7 @@ struct BrowserView: View {
Text(Image(systemName: "doc.plaintext"))
Text(item.message)
Spacer()
- }
+ }.foregroundStyle(linkColour)
}
} else if item.selector.hasPrefix("URL:") {
if let url = URL(string: item.selector.replacingOccurrences(of: "URL:", with: ""))
@@ -98,7 +101,7 @@ struct BrowserView: View {
Image(systemName: "link")
Text(item.message)
Spacer()
- }
+ }.foregroundStyle(linkColour)
}.buttonStyle(PlainButtonStyle())
}
} else if [.doc, .image, .gif, .movie, .sound, .bitmap].contains(
@@ -109,7 +112,7 @@ struct BrowserView: View {
Text(Image(systemName: itemToImageType(item)))
Text(item.message)
Spacer()
- }
+ }.foregroundStyle(linkColour)
}
} else {
Button(action: {
@@ -122,7 +125,7 @@ struct BrowserView: View {
Text(Image(systemName: "questionmark.app.dashed"))
Text(item.message)
Spacer()
- }
+ }.foregroundStyle(linkColour)
}.buttonStyle(PlainButtonStyle())
}
@@ -361,6 +364,7 @@ struct BrowserView: View {
SettingsView()
#endif
}
+ .accentColor(accentColour)
}
private func performGopherRequest(
diff --git a/iGopherBrowser/SettingsView.swift b/iGopherBrowser/SettingsView.swift
index 0dda622..24ece75 100644
--- a/iGopherBrowser/SettingsView.swift
+++ b/iGopherBrowser/SettingsView.swift
@@ -7,7 +7,59 @@
import SwiftUI
+extension Color: RawRepresentable {
+
+ public init?(rawValue: String) {
+
+ guard let data = Data(base64Encoded: rawValue) else {
+ self = .black
+ return
+ }
+
+ do {
+ #if os(macOS)
+ let color =
+ try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? NSColor ?? .black
+ #else
+ let color =
+ try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? UIColor ?? .black
+ #endif
+ self = Color(color)
+ } catch {
+ self = .black
+ }
+
+ }
+
+ public var rawValue: String {
+
+ do {
+ #if os(macOS)
+ let data =
+ try NSKeyedArchiver.archivedData(
+ withRootObject: NSColor(self), requiringSecureCoding: false) as Data
+ #else
+ let data =
+ try NSKeyedArchiver.archivedData(
+ withRootObject: UIColor(self), requiringSecureCoding: false) as Data
+ #endif
+ return data.base64EncodedString()
+
+ } catch {
+
+ return ""
+
+ }
+
+ }
+
+}
+
struct SettingsView: View {
+
+ @AppStorage("accentColour", store: .standard) var accentColour: Color = Color(.blue)
+ @AppStorage("linkColour", store: .standard) var linkColour: Color = Color(.white)
+
#if os(iOS)
@Binding var homeURL: URL
@Binding var homeURLString: String
@@ -18,7 +70,6 @@ struct SettingsView: View {
#endif
@State private var showAlert = false
@State private var alertMessage: String = ""
-
@Environment(\.dismiss) var dismiss
var body: some View {
@@ -64,10 +115,18 @@ struct SettingsView: View {
}
}
}
+ Section(header: Text("UI Settings")) {
+ ColorPicker("Link Colour", selection: $linkColour)
+ ColorPicker("Accent Colour", selection: $accentColour)
+ Button("Reset Colours") {
+ self.linkColour = Color(.white)
+ self.accentColour = Color(.blue)
+ }
+ }
}
#if os(OSX)
.padding(20)
- .frame(width: 350, height: 100)
+ .frame(width: 350, height: 350)
#endif
.alert(isPresented: $showAlert) {
Alert(