Merge branch 'main' into feature/nib_localisation

This commit is contained in:
Stuart Breckenridge
2023-05-29 05:20:04 +08:00
committed by GitHub
50 changed files with 257 additions and 240 deletions

View File

@@ -167,7 +167,10 @@ struct AppAssets {
}()
static var preferencesToolbarExtensionsImage: RSImage = {
return RSImage(named: "preferencesToolbarExtensions")!
if #unavailable(macOS 12.0) {
return RSImage(named: "preferencesToolbarExtensions")!
}
return NSImage(systemSymbolName: "puzzlepiece.extension", accessibilityDescription: nil)!
}()
static var preferencesToolbarGeneralImage: RSImage = {

View File

@@ -0,0 +1,64 @@
//
// AboutHTML.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 28/05/2023.
// Copyright © 2023 Ranchero Software. All rights reserved.
//
import Html
@available(macOS 12, *)
struct AboutHTML: LoadableAboutData {
private func stylesheet() -> StaticString {
"""
body {
margin: 2em;
color: #333333;
background-color: white;
line-height: 1.1em;
font-family: -apple-system;
text-align: center;
font-size: 12px;
}
h3 { padding-top: 10px; padding-bottom: 8px; }
@media (prefers-color-scheme: dark) {
body {
color: white;
background-color: #333333;
}
a { color: rgba(94, 158, 244, 1); }
}
"""
}
private func document() -> Node {
return Node.document(
.html(
.head(
.style(safe: stylesheet())
),
.body(
Node.h3(.text(NSLocalizedString("label.text.primary-contributors", comment: "Primary Contributors"))),
Node.fragment(about.PrimaryContributors.map { .p(.a(attributes: [.href($0.url ?? "")], "\($0.name)")) }),
Node.h3(.text(NSLocalizedString("label.text.additional-contributors", comment: "Additional Contributors"))),
Node.fragment(about.AdditionalContributors.map { .p(.a(attributes: [.href($0.url ?? "")], "\($0.name)")) }),
Node.h3(.text(NSLocalizedString("label.text.thanks", comment: "Thanks"))),
Node.raw(NSLocalizedString("label.text.thanks-details", comment: "Thanks details"))
)
)
)
}
func renderedDocument() -> String {
return render(document())
}
}

View File

@@ -1,55 +0,0 @@
//
// AboutNetNewsWireView.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 03/10/2022.
// Copyright © 2022 Ranchero Software. All rights reserved.
//
import SwiftUI
@available(macOS 12, *)
struct AboutNetNewsWireView: View {
var body: some View {
HStack {
Spacer()
VStack(spacing: 8) {
Spacer()
Image("About")
.resizable()
.frame(width: 75, height: 75)
Text(verbatim: "NetNewsWire")
.font(.headline)
Text("\(Bundle.main.versionNumber) (\(Bundle.main.buildNumber))")
.foregroundColor(.secondary)
.font(.callout)
Text("label.text.netnewswire-byline", comment: "By Brent Simmons and the NetNewsWire team.")
.font(.subheadline)
Text("label.markdown.netnewswire-website", comment: "Markdown formatted link to netnewswire.com")
.font(.callout)
Spacer()
Text(verbatim: "Copyright © Brent Simmons 2002 - \(Calendar.current.component(.year, from: .now))")
.font(.callout)
.foregroundColor(.secondary)
.padding(.bottom)
}
Spacer()
}
.multilineTextAlignment(.center)
.frame(width: 400, height: 400)
}
}
@available(macOS 12, *)
struct AboutNetNewsWireView_Previews: PreviewProvider {
static var previews: some View {
AboutNetNewsWireView()
}
}

View File

@@ -0,0 +1,93 @@
//
// AboutNewNewsWireView.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 03/10/2022.
// Copyright © 2022 Ranchero Software. All rights reserved.
//
import SwiftUI
import WebKit
import Html
@available(macOS 12, *)
fileprivate struct WebView: NSViewRepresentable {
var htmlString: String
func makeNSView(context: Context) -> DetailWebView {
let view = DetailWebView()
view.loadHTMLString(htmlString, baseURL: nil)
return view
}
func updateNSView(_ webView: DetailWebView, context: Context) {
webView.navigationDelegate = context.coordinator
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, WKNavigationDelegate {
var parent: WebView!
init(_ parent: WebView) {
self.parent = parent
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.navigationType == .linkActivated {
if let url = navigationAction.request.url {
Task { @MainActor in Browser.open(url.absoluteString) }
}
decisionHandler(.cancel)
return
}
decisionHandler(.allow)
}
}
}
@available(macOS 12, *)
struct AboutNewNewsWireView: View, LoadableAboutData {
var body: some View {
VStack(spacing: 4) {
Image("About")
.resizable()
.frame(width: 70, height: 70)
.padding(.top)
Text(verbatim: "NetNewsWire")
.font(.title3)
.bold()
Text("\(Bundle.main.versionNumber) (\(Bundle.main.buildNumber))")
.font(.body)
.padding(.bottom)
WebView(htmlString: AboutHTML().renderedDocument())
.overlay(Divider(), alignment: .top)
.overlay(Divider(), alignment: .bottom)
HStack(alignment: .center) {
Spacer()
Text(verbatim: "Copyright © Brent Simmons 2002 - \(Calendar.current.component(.year, from: .now))")
.font(.caption2)
.padding(.bottom, 6)
.padding(.top, 2)
Spacer()
}
}
.frame(width: 425, height: 550)
}
}
@available(macOS 12, *)
struct AboutNetNewsWireView_Previews: PreviewProvider {
static var previews: some View {
AboutNewNewsWireView()
}
}

View File

@@ -10,10 +10,6 @@ import AppKit
import SwiftUI
import RSCore
extension NSToolbarItem.Identifier {
static let aboutGroup = NSToolbarItem.Identifier("about.toolbar.group")
}
extension NSUserInterfaceItemIdentifier {
static let aboutNetNewsWire = NSUserInterfaceItemIdentifier("about.netnewswire")
}
@@ -21,19 +17,19 @@ extension NSUserInterfaceItemIdentifier {
// MARK: - AboutWindowController
@available(macOS 12, *)
class AboutWindowController: NSWindowController, NSToolbarDelegate {
class AboutWindowController: NSWindowController {
var hostingController: AboutHostingController
override init(window: NSWindow?) {
self.hostingController = AboutHostingController(rootView: AnyView(AboutNetNewsWireView()))
self.hostingController = AboutHostingController(rootView: AnyView(AboutNewNewsWireView()))
super.init(window: window)
let window = NSWindow(contentViewController: hostingController)
window.identifier = .aboutNetNewsWire
window.standardWindowButton(.zoomButton)?.isEnabled = false
window.standardWindowButton(.miniaturizeButton)?.isEnabled = false
window.titleVisibility = .hidden
self.window = window
self.hostingController.configureToolbar()
}
required init?(coder: NSCoder) {
@@ -49,17 +45,7 @@ class AboutWindowController: NSWindowController, NSToolbarDelegate {
// MARK: - AboutHostingController
@available(macOS 12, *)
class AboutHostingController: NSHostingController<AnyView>, NSToolbarDelegate {
private lazy var segmentedControl: NSSegmentedControl = {
let control = NSSegmentedControl(labels: ["About", "Credits"],
trackingMode: .selectOne,
target: self,
action: #selector(segmentedControlSelectionChanged(_:)))
control.segmentCount = 2
control.setSelected(true, forSegment: 0)
return control
}()
class AboutHostingController: NSHostingController<AnyView> {
override init(rootView: AnyView) {
super.init(rootView: rootView)
@@ -68,63 +54,6 @@ class AboutHostingController: NSHostingController<AnyView>, NSToolbarDelegate {
@MainActor required dynamic init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func configureToolbar() {
let toolbar = NSToolbar(identifier: NSToolbar.Identifier("netnewswire.about.toolbar"))
toolbar.delegate = self
toolbar.autosavesConfiguration = false
toolbar.allowsUserCustomization = false
view.window?.toolbar = toolbar
view.window?.toolbarStyle = .unified
toolbar.insertItem(withItemIdentifier: .flexibleSpace, at: 0)
toolbar.insertItem(withItemIdentifier: .flexibleSpace, at: 2)
}
// MARK: NSToolbarDelegate
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
switch itemIdentifier {
case .aboutGroup:
let toolbarItem = NSToolbarItem(itemIdentifier: .aboutGroup)
toolbarItem.view = segmentedControl
toolbarItem.autovalidates = true
return toolbarItem
default:
return nil
}
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.aboutGroup]
}
func toolbarWillAddItem(_ notification: Notification) {
//
}
func toolbarDidRemoveItem(_ notification: Notification) {
//
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.aboutGroup]
}
func toolbarSelectableItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return []
}
// MARK: - Target/Action
@objc
func segmentedControlSelectionChanged(_ sender: NSSegmentedControl) {
if sender.selectedSegment == 0 {
rootView = AnyView(AboutNetNewsWireView())
} else {
rootView = AnyView(CreditsNetNewsWireView())
}
}
}

View File

@@ -1,82 +0,0 @@
//
// CreditsNetNewsWireView.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 03/10/2022.
// Copyright © 2022 Ranchero Software. All rights reserved.
//
import SwiftUI
@available(macOS 12, *)
struct CreditsNetNewsWireView: View, LoadableAboutData {
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
Spacer()
.frame(height: 12)
Section("Primary Contributors") {
GroupBox {
ForEach(0..<about.PrimaryContributors.count, id: \.self) { i in
contributorView(about.PrimaryContributors[i])
.padding(.vertical, 2)
.listRowInsets(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 12))
}
}
}
Section("Additional Contributors") {
GroupBox {
ForEach(0..<about.AdditionalContributors.count, id: \.self) { i in
contributorView(about.AdditionalContributors[i])
.padding(.vertical, 2)
.listRowInsets(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 12))
}
}
}
Section("Thanks") {
GroupBox {
Text(about.ThanksMarkdown)
.multilineTextAlignment(.center)
.font(.callout)
.padding(.vertical, 2)
}
}
Spacer()
.frame(height: 12)
}
.padding(.horizontal)
.frame(width: 400, height: 400)
}
func contributorView(_ appCredit: AboutData.Contributor) -> some View {
HStack {
Text(appCredit.name)
Spacer()
if let role = appCredit.role {
Text(role)
.foregroundColor(.secondary)
}
Image(systemName: "info.circle")
.foregroundColor(.secondary)
}
.onTapGesture {
guard let url = appCredit.url else { return }
if let _ = URL(string: url) {
Task { @MainActor in
Browser.open(url, inBackground: false)
}
}
}
}
}
@available(macOS 12, *)
struct CreditsNetNewsWireView_Previews: PreviewProvider {
static var previews: some View {
CreditsNetNewsWireView()
}
}

View File

@@ -454,6 +454,12 @@
/* You've added all available extensions. */
"label.text.added-all-extensions" = "You've added all available extensions.";
/* Primary Contributors */
"label.text.primary-contributors" = "Primary Contributors";
/* Additional Contributors */
"label.text.additional-contributors" = "Additional Contributors";
/* Article */
"label.text.article" = "Article";
@@ -586,6 +592,15 @@
/* Subreddit */
"label.text.subreddit" = "Subreddit";
/* Thanks */
"label.text.thanks" = "Thanks";
/* Thanks - Dedication */
"label.text.thanks-details" = "
<p>Thanks to Sheila and my family; thanks to my friends in Seattle and around the globe; thanks to the ever-patient and ever-awesome NetNewsWire beta testers. </p>
<p>Thanks to <a href=\"https://shapeof.com/\">Gus Mueller</a> for <a href=\"https://github.com/ccgus/fmdb\">FMDB</a> by <a href=\"http://flyingmeat.com/\">Flying Meat Software</a>. Thanks to <a href=\"https://github.com\">GitHub</a> and <a href=\"https://slack.com\">Slack</a> for making open source collaboration easy and fun. Thanks to <a href=\"https://benubois.com/\">Ben Ubois</a> at <a href=\"https://feedbin.com/\">Feedbin</a> for all the extra help with syncing and article rendering — and for <a href=\"https://feedbin.com/blog/2019/03/11/the-future-of-full-content/\">hosting the server for the Reader view</a>.</p>
<p>NetNewsWire 6 is dedicated to everyone working to save democracy around the world.</p>";
/* Built-in */
"label.text.themes-builtin" = "Built-in Themes";

View File

@@ -447,6 +447,12 @@
/* You've added all available extensions. */
"label.text.added-all-extensions" = "You've added all available extensions.";
/* Primary Contributors */
"label.text.primary-contributors" = "Primary Contributors";
/* Additional Contributors */
"label.text.additional-contributors" = "Additional Contributors";
/* Article */
"label.text.article" = "Article";
@@ -579,6 +585,15 @@
/* Subreddit */
"label.text.subreddit" = "Subreddit";
/* Thanks */
"label.text.thanks" = "Thanks";
/* Thanks - Dedication */
"label.text.thanks-details" = "
<p>Thanks to Sheila and my family; thanks to my friends in Seattle and around the globe; thanks to the ever-patient and ever-awesome NetNewsWire beta testers. </p>
<p>Thanks to <a href=\"https://shapeof.com/\">Gus Mueller</a> for <a href=\"https://github.com/ccgus/fmdb\">FMDB</a> by <a href=\"http://flyingmeat.com/\">Flying Meat Software</a>. Thanks to <a href=\"https://github.com\">GitHub</a> and <a href=\"https://slack.com\">Slack</a> for making open source collaboration easy and fun. Thanks to <a href=\"https://benubois.com/\">Ben Ubois</a> at <a href=\"https://feedbin.com/\">Feedbin</a> for all the extra help with syncing and article rendering — and for <a href=\"https://feedbin.com/blog/2019/03/11/the-future-of-full-content/\">hosting the server for the Reader view</a>.</p>
<p>NetNewsWire 6 is dedicated to everyone working to save democracy around the world.</p>";
/* Built-in */
"label.text.themes-builtin" = "Built-in Themes";