mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 20:16:54 +01:00
Add color palette implementation for Appearance settings
This commit is contained in:
parent
313d3df573
commit
959eef6a1a
@ -103,6 +103,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|||||||
UNUserNotificationCenter.current().delegate = self
|
UNUserNotificationCenter.current().delegate = self
|
||||||
userNotificationManager = UserNotificationManager()
|
userNotificationManager = UserNotificationManager()
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange), name: UserDefaults.didChangeNotification, object: nil)
|
||||||
|
|
||||||
|
|
||||||
// extensionContainersFile = ExtensionContainersFile()
|
// extensionContainersFile = ExtensionContainersFile()
|
||||||
// extensionFeedAddRequestFile = ExtensionFeedAddRequestFile()
|
// extensionFeedAddRequestFile = ExtensionFeedAddRequestFile()
|
||||||
|
|
||||||
@ -388,3 +391,29 @@ private extension AppDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension AppDelegate {
|
||||||
|
@objc func userDefaultsDidChange() {
|
||||||
|
updateUserInterfaceStyle()
|
||||||
|
}
|
||||||
|
|
||||||
|
var window: UIWindow? {
|
||||||
|
guard let scene = UIApplication.shared.connectedScenes.first,
|
||||||
|
let windowSceneDelegate = scene.delegate as? UIWindowSceneDelegate,
|
||||||
|
let window = windowSceneDelegate.window else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return window
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUserInterfaceStyle() {
|
||||||
|
switch AppDefaults.shared.userInterfaceColorPalette {
|
||||||
|
case .automatic:
|
||||||
|
window?.overrideUserInterfaceStyle = .unspecified
|
||||||
|
case .light:
|
||||||
|
window?.overrideUserInterfaceStyle = .light
|
||||||
|
case .dark:
|
||||||
|
window?.overrideUserInterfaceStyle = .dark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -155,12 +155,12 @@ struct SettingsView: View {
|
|||||||
var appearance: some View {
|
var appearance: some View {
|
||||||
Section(header: Text("Appearance"), content: {
|
Section(header: Text("Appearance"), content: {
|
||||||
NavigationLink(
|
NavigationLink(
|
||||||
destination: EmptyView(),
|
destination: ColorPaletteContainerView().environmentObject(settings),
|
||||||
label: {
|
label: {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Color Pallete")
|
Text("Color Palette")
|
||||||
Spacer()
|
Spacer()
|
||||||
Text("Automatic")
|
Text(settings.userInterfaceColorPalette.description)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
//
|
||||||
|
// ColorPaletteContainerView.swift
|
||||||
|
// Multiplatform iOS
|
||||||
|
//
|
||||||
|
// Created by Rizwan on 02/07/20.
|
||||||
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct ColorPaletteContainerView: View {
|
||||||
|
private let colorPalettes = UserInterfaceColorPalette.allCases
|
||||||
|
@EnvironmentObject private var appSettings: AppDefaults
|
||||||
|
@Environment(\.presentationMode) var presentationMode
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
List {
|
||||||
|
ForEach.init(0 ..< colorPalettes.count) { index in
|
||||||
|
Button(action: {
|
||||||
|
onTapColorPalette(at:index)
|
||||||
|
}) {
|
||||||
|
ColorPaletteView(colorPalette: colorPalettes[index])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.listStyle(InsetGroupedListStyle())
|
||||||
|
.navigationBarTitle("Color Palette", displayMode: .inline)
|
||||||
|
}
|
||||||
|
|
||||||
|
func onTapColorPalette(at index: Int) {
|
||||||
|
if let colorPalette = UserInterfaceColorPalette(rawValue: index) {
|
||||||
|
appSettings.userInterfaceColorPalette = colorPalette
|
||||||
|
}
|
||||||
|
presentationMode.wrappedValue.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ColorPaletteView: View {
|
||||||
|
var colorPalette: UserInterfaceColorPalette
|
||||||
|
@EnvironmentObject private var appSettings: AppDefaults
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
Text(colorPalette.description).foregroundColor(.primary)
|
||||||
|
Spacer()
|
||||||
|
if colorPalette == appSettings.userInterfaceColorPalette {
|
||||||
|
Image(systemName: "checkmark")
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ColorPaletteContainerView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
NavigationView {
|
||||||
|
ColorPaletteContainerView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,6 @@
|
|||||||
1776E88F24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; };
|
1776E88F24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; };
|
||||||
179DB1DFBCF9177104B12E0F /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
|
179DB1DFBCF9177104B12E0F /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
|
||||||
179DB3CE822BFCC2D774D9F4 /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
|
179DB3CE822BFCC2D774D9F4 /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
|
||||||
17B223DC24AC24D2001E4592 /* TimelineLayoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */; };
|
|
||||||
3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; };
|
3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; };
|
||||||
3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; };
|
3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; };
|
||||||
3B826DCC2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */; };
|
3B826DCC2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */; };
|
||||||
@ -621,6 +620,8 @@
|
|||||||
6581C73D20CED60100F4AD34 /* SafariExtensionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73B20CED60100F4AD34 /* SafariExtensionViewController.xib */; };
|
6581C73D20CED60100F4AD34 /* SafariExtensionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73B20CED60100F4AD34 /* SafariExtensionViewController.xib */; };
|
||||||
6581C74020CED60100F4AD34 /* netnewswire-subscribe-to-feed.js in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73F20CED60100F4AD34 /* netnewswire-subscribe-to-feed.js */; };
|
6581C74020CED60100F4AD34 /* netnewswire-subscribe-to-feed.js in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73F20CED60100F4AD34 /* netnewswire-subscribe-to-feed.js */; };
|
||||||
6581C74220CED60100F4AD34 /* ToolbarItemIcon.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 6581C74120CED60100F4AD34 /* ToolbarItemIcon.pdf */; };
|
6581C74220CED60100F4AD34 /* ToolbarItemIcon.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 6581C74120CED60100F4AD34 /* ToolbarItemIcon.pdf */; };
|
||||||
|
65CBAD3624AE02D50006DD91 /* TimelineLayoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */; };
|
||||||
|
65CBAD5A24AE03C20006DD91 /* ColorPaletteContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65CBAD5924AE03C20006DD91 /* ColorPaletteContainerView.swift */; };
|
||||||
65ED3FB7235DEF6C0081F399 /* ArticleArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F204DF1FAACBB30076E152 /* ArticleArray.swift */; };
|
65ED3FB7235DEF6C0081F399 /* ArticleArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F204DF1FAACBB30076E152 /* ArticleArray.swift */; };
|
||||||
65ED3FB8235DEF6C0081F399 /* CrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848B937121C8C5540038DC0D /* CrashReporter.swift */; };
|
65ED3FB8235DEF6C0081F399 /* CrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848B937121C8C5540038DC0D /* CrashReporter.swift */; };
|
||||||
65ED3FB9235DEF6C0081F399 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847CD6C9232F4CBF00FAC46D /* IconView.swift */; };
|
65ED3FB9235DEF6C0081F399 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847CD6C9232F4CBF00FAC46D /* IconView.swift */; };
|
||||||
@ -1985,6 +1986,7 @@
|
|||||||
6581C73F20CED60100F4AD34 /* netnewswire-subscribe-to-feed.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = "netnewswire-subscribe-to-feed.js"; sourceTree = "<group>"; };
|
6581C73F20CED60100F4AD34 /* netnewswire-subscribe-to-feed.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = "netnewswire-subscribe-to-feed.js"; sourceTree = "<group>"; };
|
||||||
6581C74120CED60100F4AD34 /* ToolbarItemIcon.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = ToolbarItemIcon.pdf; sourceTree = "<group>"; };
|
6581C74120CED60100F4AD34 /* ToolbarItemIcon.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = ToolbarItemIcon.pdf; sourceTree = "<group>"; };
|
||||||
6581C74320CED60100F4AD34 /* Subscribe_to_Feed.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Subscribe_to_Feed.entitlements; sourceTree = "<group>"; };
|
6581C74320CED60100F4AD34 /* Subscribe_to_Feed.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Subscribe_to_Feed.entitlements; sourceTree = "<group>"; };
|
||||||
|
65CBAD5924AE03C20006DD91 /* ColorPaletteContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPaletteContainerView.swift; sourceTree = "<group>"; };
|
||||||
65ED4083235DEF6C0081F399 /* NetNewsWire.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetNewsWire.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
65ED4083235DEF6C0081F399 /* NetNewsWire.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetNewsWire.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
65ED409D235DEF770081F399 /* Subscribe to Feed.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Subscribe to Feed.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
|
65ED409D235DEF770081F399 /* Subscribe to Feed.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Subscribe to Feed.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
65ED409F235DEFF00081F399 /* container-migration.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "container-migration.plist"; sourceTree = "<group>"; };
|
65ED409F235DEFF00081F399 /* container-migration.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "container-migration.plist"; sourceTree = "<group>"; };
|
||||||
@ -2389,6 +2391,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */,
|
17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */,
|
||||||
|
65CBAD5924AE03C20006DD91 /* ColorPaletteContainerView.swift */,
|
||||||
);
|
);
|
||||||
path = Submenus;
|
path = Submenus;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -4774,6 +4777,7 @@
|
|||||||
51E498F524A8085D00B667CB /* TodayFeedDelegate.swift in Sources */,
|
51E498F524A8085D00B667CB /* TodayFeedDelegate.swift in Sources */,
|
||||||
172952B024AA287100D65E66 /* CompactSidebarContainerView.swift in Sources */,
|
172952B024AA287100D65E66 /* CompactSidebarContainerView.swift in Sources */,
|
||||||
172199F124AB716900A31D04 /* SidebarToolbar.swift in Sources */,
|
172199F124AB716900A31D04 /* SidebarToolbar.swift in Sources */,
|
||||||
|
65CBAD5A24AE03C20006DD91 /* ColorPaletteContainerView.swift in Sources */,
|
||||||
51E4990B24A808C500B667CB /* ImageDownloader.swift in Sources */,
|
51E4990B24A808C500B667CB /* ImageDownloader.swift in Sources */,
|
||||||
51E498F424A8085D00B667CB /* SmartFeedDelegate.swift in Sources */,
|
51E498F424A8085D00B667CB /* SmartFeedDelegate.swift in Sources */,
|
||||||
514E6BFF24AD255D00AC6F6E /* PreviewArticles.swift in Sources */,
|
514E6BFF24AD255D00AC6F6E /* PreviewArticles.swift in Sources */,
|
||||||
@ -4805,6 +4809,7 @@
|
|||||||
51E4992624A80AAB00B667CB /* AppAssets.swift in Sources */,
|
51E4992624A80AAB00B667CB /* AppAssets.swift in Sources */,
|
||||||
514E6C0624AD2B5F00AC6F6E /* Image-Extensions.swift in Sources */,
|
514E6C0624AD2B5F00AC6F6E /* Image-Extensions.swift in Sources */,
|
||||||
51E4995624A8734D00B667CB /* TwitterFeedProvider-Extensions.swift in Sources */,
|
51E4995624A8734D00B667CB /* TwitterFeedProvider-Extensions.swift in Sources */,
|
||||||
|
65CBAD3624AE02D50006DD91 /* TimelineLayoutView.swift in Sources */,
|
||||||
51E4996824A8760C00B667CB /* ArticleStyle.swift in Sources */,
|
51E4996824A8760C00B667CB /* ArticleStyle.swift in Sources */,
|
||||||
51E4990024A808BB00B667CB /* FaviconGenerator.swift in Sources */,
|
51E4990024A808BB00B667CB /* FaviconGenerator.swift in Sources */,
|
||||||
51E4997124A8764C00B667CB /* ActivityType.swift in Sources */,
|
51E4997124A8764C00B667CB /* ActivityType.swift in Sources */,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user