Merge branch 'mac-release'
This commit is contained in:
commit
9e18361043
|
@ -62,6 +62,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||
private var addFeedController: AddFeedController?
|
||||
private var addFolderWindowController: AddFolderWindowController?
|
||||
private var importOPMLController: ImportOPMLWindowController?
|
||||
private var importNNW3Controller: ImportNNW3WindowController?
|
||||
private var exportOPMLController: ExportOPMLWindowController?
|
||||
private var keyboardShortcutsWindowController: WebViewWindowController?
|
||||
private var inspectorWindowController: InspectorWindowController?
|
||||
|
@ -135,6 +136,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||
logDebugMessage("Is first run.")
|
||||
}
|
||||
let localAccount = AccountManager.shared.defaultAccount
|
||||
NNW3FeedsImporter.importIfNeeded(isFirstRun, account: localAccount)
|
||||
DefaultFeedsImporter.importIfNeeded(isFirstRun, account: localAccount)
|
||||
|
||||
let tempDirectory = NSTemporaryDirectory()
|
||||
|
@ -422,7 +424,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||
}
|
||||
|
||||
@IBAction func toggleInspectorWindow(_ sender: Any?) {
|
||||
|
||||
if inspectorWindowController == nil {
|
||||
inspectorWindowController = (windowControllerWithName("Inspector") as! InspectorWindowController)
|
||||
}
|
||||
|
@ -437,7 +438,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||
}
|
||||
|
||||
@IBAction func importOPMLFromFile(_ sender: Any?) {
|
||||
|
||||
createAndShowMainWindow()
|
||||
if mainWindowController!.isDisplayingSheet {
|
||||
return
|
||||
|
@ -445,11 +445,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||
|
||||
importOPMLController = ImportOPMLWindowController()
|
||||
importOPMLController?.runSheetOnWindow(mainWindowController!.window!)
|
||||
}
|
||||
|
||||
@IBAction func importNNW3FromFile(_ sender: Any?) {
|
||||
createAndShowMainWindow()
|
||||
if mainWindowController!.isDisplayingSheet {
|
||||
return
|
||||
}
|
||||
|
||||
importNNW3Controller = ImportNNW3WindowController()
|
||||
importNNW3Controller?.runSheetOnWindow(mainWindowController!.window!)
|
||||
}
|
||||
|
||||
@IBAction func exportOPML(_ sender: Any?) {
|
||||
|
||||
createAndShowMainWindow()
|
||||
if mainWindowController!.isDisplayingSheet {
|
||||
return
|
||||
|
@ -457,11 +465,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||
|
||||
exportOPMLController = ExportOPMLWindowController()
|
||||
exportOPMLController?.runSheetOnWindow(mainWindowController!.window!)
|
||||
|
||||
}
|
||||
|
||||
@IBAction func addAppNews(_ sender: Any?) {
|
||||
|
||||
if AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -92,6 +92,12 @@
|
|||
<action selector="importOPMLFromFile:" target="Ady-hI-5gd" id="eGY-fm-uvK"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Import NNW 3 Subscriptions ..." id="ely-yi-STg">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="importNNW3FromFile:" target="Voe-Tx-rLC" id="mu3-gN-7uA"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Export Subscriptions…" keyEquivalent="e" id="Xy2-v8-Lj8">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15504"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="ImportNNW3WindowController" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="accountPopUpButton" destination="sEU-ot-DE2" id="9W3-o6-YsH"/>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="KF3-y6-Xy7"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g">
|
||||
<windowStyleMask key="styleMask" titled="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="433" height="183"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
<view key="contentView" wantsLayer="YES" misplaced="YES" id="EiT-Mj-1SZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="433" height="183"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="vE6-sv-BA0">
|
||||
<rect key="frame" x="18" y="100" width="405" height="32"/>
|
||||
<textFieldCell key="cell" selectable="YES" title="Choose the account to get the imported subscriptions. This requires a NetNewsWire 3 Subscriptions.plist file." id="1Vu-Te-PGl">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kZ4-y9-lYy">
|
||||
<rect key="frame" x="18" y="64" width="63" height="16"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Account:" id="e9g-7H-VWa">
|
||||
<font key="font" metaFont="systemBold"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="sEU-ot-DE2" userLabel="Account Popup">
|
||||
<rect key="frame" x="85" y="58" width="339" height="25"/>
|
||||
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="xsd-12-2yb" id="NuO-Hk-nk3">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<menu key="menu" id="8LY-np-ij1">
|
||||
<items>
|
||||
<menuItem title="Item 1" state="on" id="xsd-12-2yb"/>
|
||||
<menuItem title="Item 2" id="JGa-5R-SV5"/>
|
||||
<menuItem title="Item 3" id="92e-hX-kYj"/>
|
||||
</items>
|
||||
</menu>
|
||||
</popUpButtonCell>
|
||||
</popUpButton>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ceu-mM-EKm">
|
||||
<rect key="frame" x="81" y="13" width="173" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="9ab-cB-hex">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
Gw
|
||||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="cancel:" target="-2" id="TTV-OR-P3d"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="et6-I1-6wB">
|
||||
<rect key="frame" x="254" y="13" width="173" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Import from NNW 3 …" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="dhV-on-ayM">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
DQ
|
||||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="importNNW3:" target="-2" id="C33-8m-XQA"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="vE6-sv-BA0" secondAttribute="trailing" constant="20" symbolic="YES" id="2UM-dU-XgH"/>
|
||||
<constraint firstItem="kZ4-y9-lYy" firstAttribute="top" secondItem="vE6-sv-BA0" secondAttribute="bottom" constant="20" id="8Wf-Iv-teA"/>
|
||||
<constraint firstItem="sEU-ot-DE2" firstAttribute="firstBaseline" secondItem="kZ4-y9-lYy" secondAttribute="firstBaseline" id="EPd-vD-8pa"/>
|
||||
<constraint firstItem="et6-I1-6wB" firstAttribute="width" secondItem="ceu-mM-EKm" secondAttribute="width" id="Ldw-C8-F5X"/>
|
||||
<constraint firstItem="vE6-sv-BA0" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" constant="20" symbolic="YES" id="M8o-2f-uax"/>
|
||||
<constraint firstItem="et6-I1-6wB" firstAttribute="top" secondItem="sEU-ot-DE2" secondAttribute="bottom" constant="20" symbolic="YES" id="OXm-Ns-r9Z"/>
|
||||
<constraint firstItem="kZ4-y9-lYy" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" constant="20" symbolic="YES" id="SZo-1P-yYA"/>
|
||||
<constraint firstAttribute="bottom" secondItem="et6-I1-6wB" secondAttribute="bottom" constant="20" symbolic="YES" id="T9O-XC-wdY"/>
|
||||
<constraint firstItem="et6-I1-6wB" firstAttribute="leading" secondItem="ceu-mM-EKm" secondAttribute="trailing" constant="12" symbolic="YES" id="Y8m-P8-JQh"/>
|
||||
<constraint firstItem="sEU-ot-DE2" firstAttribute="leading" secondItem="kZ4-y9-lYy" secondAttribute="trailing" constant="8" symbolic="YES" id="a0f-Ak-Zdq"/>
|
||||
<constraint firstAttribute="trailing" secondItem="et6-I1-6wB" secondAttribute="trailing" constant="20" symbolic="YES" id="chg-8b-D51"/>
|
||||
<constraint firstItem="ceu-mM-EKm" firstAttribute="centerY" secondItem="et6-I1-6wB" secondAttribute="centerY" id="eKt-vM-3wn"/>
|
||||
<constraint firstItem="ceu-mM-EKm" firstAttribute="leading" secondItem="sEU-ot-DE2" secondAttribute="leading" id="gb5-bZ-0R6"/>
|
||||
<constraint firstItem="vE6-sv-BA0" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" constant="20" symbolic="YES" id="ggA-m1-5pj"/>
|
||||
<constraint firstAttribute="trailing" secondItem="sEU-ot-DE2" secondAttribute="trailing" constant="20" symbolic="YES" id="sFO-00-DR0"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<point key="canvasLocation" x="99.5" y="103.5"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
|
@ -0,0 +1,110 @@
|
|||
//
|
||||
// ImportNNW3WindowController.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import Account
|
||||
|
||||
class ImportNNW3WindowController: NSWindowController {
|
||||
|
||||
@IBOutlet weak var accountPopUpButton: NSPopUpButton!
|
||||
private weak var hostWindow: NSWindow?
|
||||
|
||||
convenience init() {
|
||||
self.init(windowNibName: NSNib.Name("ImportNNW3Sheet"))
|
||||
}
|
||||
|
||||
override func windowDidLoad() {
|
||||
accountPopUpButton.removeAllItems()
|
||||
|
||||
let menu = NSMenu()
|
||||
accountPopUpButton.menu = menu
|
||||
|
||||
for oneAccount in AccountManager.shared.sortedActiveAccounts {
|
||||
|
||||
let oneMenuItem = NSMenuItem()
|
||||
oneMenuItem.title = oneAccount.nameForDisplay
|
||||
oneMenuItem.representedObject = oneAccount
|
||||
menu.addItem(oneMenuItem)
|
||||
|
||||
if oneAccount.accountID == AppDefaults.importOPMLAccountID {
|
||||
accountPopUpButton.select(oneMenuItem)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
|
||||
self.hostWindow = hostWindow
|
||||
|
||||
if AccountManager.shared.activeAccounts.count == 1 {
|
||||
let account = AccountManager.shared.activeAccounts.first!
|
||||
importNNW3(account: account)
|
||||
} else {
|
||||
hostWindow.beginSheet(window!)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
@IBAction func cancel(_ sender: Any) {
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
|
||||
}
|
||||
|
||||
@IBAction func importNNW3(_ sender: Any) {
|
||||
|
||||
guard let menuItem = accountPopUpButton.selectedItem else {
|
||||
return
|
||||
}
|
||||
|
||||
let account = menuItem.representedObject as! Account
|
||||
AppDefaults.importOPMLAccountID = account.accountID
|
||||
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
importNNW3(account: account)
|
||||
|
||||
}
|
||||
|
||||
func importNNW3(account: Account) {
|
||||
|
||||
let panel = NSOpenPanel()
|
||||
panel.canDownloadUbiquitousContents = true
|
||||
panel.canResolveUbiquitousConflicts = true
|
||||
panel.canChooseFiles = true
|
||||
panel.allowsMultipleSelection = false
|
||||
panel.canChooseDirectories = false
|
||||
panel.resolvesAliases = true
|
||||
panel.directoryURL = URL(fileURLWithPath: NNW3PlistConverter.defaultFilePath)
|
||||
panel.allowedFileTypes = ["plist"]
|
||||
panel.allowsOtherFileTypes = false
|
||||
|
||||
panel.beginSheetModal(for: hostWindow!) { modalResult in
|
||||
if modalResult == NSApplication.ModalResponse.OK, let url = panel.url {
|
||||
|
||||
guard let opmlURL = NNW3PlistConverter.convertToOPML(url: url) else {
|
||||
return
|
||||
}
|
||||
|
||||
account.importOPML(opmlURL) { result in
|
||||
try? FileManager.default.removeItem(at: opmlURL)
|
||||
switch result {
|
||||
case .success:
|
||||
break
|
||||
case .failure(let error):
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// NNW3Document.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class NNW3Document: NNW3Entry {
|
||||
|
||||
init(plist: [[String: Any]]) {
|
||||
super.init(title: "NNW3")
|
||||
|
||||
for child in plist {
|
||||
if child["isContainer"] as? Bool ?? false {
|
||||
entries.append(NNW3Entry(plist: child, parent: self))
|
||||
} else {
|
||||
entries.append(NNW3Feed(plist: child, parent: self))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override func makeXML(indentLevel: Int) -> String {
|
||||
|
||||
var s =
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<opml version="1.1">
|
||||
<head>
|
||||
<title>\(title ?? "")</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
"""
|
||||
|
||||
for entry in entries {
|
||||
s += entry.makeXML(indentLevel: indentLevel + 1)
|
||||
}
|
||||
|
||||
s +=
|
||||
"""
|
||||
</body>
|
||||
</opml>
|
||||
"""
|
||||
|
||||
return s
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// NNW3Entry.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSCore
|
||||
|
||||
class NNW3Entry {
|
||||
|
||||
var title: String?
|
||||
var entries = [NNW3Entry]()
|
||||
|
||||
weak var parent: NNW3Entry?
|
||||
|
||||
var isFolder: Bool {
|
||||
return type(of: self) == NNW3Entry.self
|
||||
}
|
||||
|
||||
init(title: String?, parent: NNW3Entry? = nil) {
|
||||
self.title = title
|
||||
self.parent = parent
|
||||
}
|
||||
|
||||
convenience init(plist: [String: Any], parent: NNW3Entry? = nil) {
|
||||
let title = plist["name"] as? String
|
||||
self.init(title: title, parent: parent)
|
||||
|
||||
guard let childrenArray = plist["childrenArray"] as? [[String: AnyObject]] else {
|
||||
return
|
||||
}
|
||||
|
||||
for child in childrenArray {
|
||||
if child["isContainer"] as? Bool ?? false {
|
||||
entries.append(NNW3Entry(plist: child, parent: self))
|
||||
} else {
|
||||
entries.append(NNW3Feed(plist: child, parent: self))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func makeXML(indentLevel: Int) -> String {
|
||||
|
||||
let t = title?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
|
||||
var s = "<outline text=\"\(t)\" title=\"\(t)\">\n".rs_string(byPrependingNumberOfTabs: indentLevel)
|
||||
|
||||
for entry in entries {
|
||||
s += entry.makeXML(indentLevel: indentLevel + 1)
|
||||
}
|
||||
|
||||
s += "</outline>\n".rs_string(byPrependingNumberOfTabs: indentLevel)
|
||||
|
||||
return s
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// NNW3Feed.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSCore
|
||||
|
||||
class NNW3Feed: NNW3Entry {
|
||||
|
||||
var pageURL: String?
|
||||
var feedURL: String?
|
||||
|
||||
init(feedURL: String) {
|
||||
super.init(title: nil)
|
||||
self.feedURL = feedURL
|
||||
}
|
||||
|
||||
init(title: String?, pageURL: String?, feedURL: String?, parent: NNW3Entry? = nil) {
|
||||
super.init(title: title, parent: parent)
|
||||
self.pageURL = pageURL
|
||||
self.feedURL = feedURL
|
||||
}
|
||||
|
||||
convenience init(plist: [String: Any], parent: NNW3Entry? = nil) {
|
||||
let title = plist["name"] as? String
|
||||
let pageURL = plist["home"] as? String
|
||||
let feedURL = plist["rss"] as? String
|
||||
self.init(title: title, pageURL: pageURL, feedURL: feedURL, parent: parent)
|
||||
}
|
||||
|
||||
override func makeXML(indentLevel: Int) -> String {
|
||||
|
||||
let t = title?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
|
||||
let p = pageURL?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
|
||||
let f = feedURL?.rs_stringByEscapingSpecialXMLCharacters() ?? ""
|
||||
|
||||
var s = "<outline text=\"\(t)\" title=\"\(t)\" description=\"\" type=\"rss\" version=\"RSS\" htmlUrl=\"\(p)\" xmlUrl=\"\(f)\"/>\n"
|
||||
s = s.rs_string(byPrependingNumberOfTabs: indentLevel)
|
||||
|
||||
return s
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// NNW3FeedsImporter.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
struct NNW3FeedsImporter {
|
||||
|
||||
static func importIfNeeded(_ isFirstRun: Bool, account: Account) {
|
||||
guard shouldImportDefaultFeeds(isFirstRun) else {
|
||||
return
|
||||
}
|
||||
|
||||
if !FileManager.default.fileExists(atPath: NNW3PlistConverter.defaultFilePath) {
|
||||
return
|
||||
}
|
||||
|
||||
appDelegate.logDebugMessage("Importing NNW3 feeds.")
|
||||
|
||||
let url = URL(fileURLWithPath: NNW3PlistConverter.defaultFilePath)
|
||||
guard let opmlURL = NNW3PlistConverter.convertToOPML(url: url) else {
|
||||
return
|
||||
}
|
||||
|
||||
account.importOPML(opmlURL) { result in
|
||||
try? FileManager.default.removeItem(at: opmlURL)
|
||||
switch result {
|
||||
case .success:
|
||||
appDelegate.logDebugMessage("Importing NNW3 feeds succeeded.")
|
||||
case .failure(let error):
|
||||
appDelegate.logDebugMessage("Importing NNW3 feeds failed. \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static func shouldImportDefaultFeeds(_ isFirstRun: Bool) -> Bool {
|
||||
if !isFirstRun || AccountManager.shared.anyAccountHasAtLeastOneFeed() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// NNW3Importer.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 10/14/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class NNW3PlistConverter {
|
||||
|
||||
static var defaultFilePath: String {
|
||||
return ("~/Library/Application Support/NetNewsWire/Subscriptions.plist" as NSString).expandingTildeInPath
|
||||
}
|
||||
|
||||
static func convertToOPML(url: URL) -> URL? {
|
||||
guard let data = try? Data(contentsOf: url) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let nnw3plist = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [[String: AnyObject]] else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let opmlURL = FileManager.default.temporaryDirectory.appendingPathComponent("NNW3.opml")
|
||||
let doc = NNW3Document(plist: nnw3plist)
|
||||
let opml = doc.makeXML(indentLevel: 0)
|
||||
do {
|
||||
try opml.write(to: opmlURL, atomically: true, encoding: .utf8)
|
||||
} catch let error as NSError {
|
||||
NSApplication.shared.presentError(error)
|
||||
return nil
|
||||
}
|
||||
|
||||
return opmlURL
|
||||
}
|
||||
|
||||
}
|
|
@ -96,6 +96,13 @@
|
|||
5183CCE6226F4E110010922C /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; };
|
||||
5183CCE8226F68D90010922C /* AccountRefreshTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE7226F68D90010922C /* AccountRefreshTimer.swift */; };
|
||||
5183CCE9226F68D90010922C /* AccountRefreshTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE7226F68D90010922C /* AccountRefreshTimer.swift */; };
|
||||
518651AC23555EB20078E021 /* ImportNNW3WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651A523555EB20078E021 /* ImportNNW3WindowController.swift */; };
|
||||
518651AD23555EB20078E021 /* NNW3PlistConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651A623555EB20078E021 /* NNW3PlistConverter.swift */; };
|
||||
518651AE23555EB20078E021 /* ImportNNW3Sheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 518651A723555EB20078E021 /* ImportNNW3Sheet.xib */; };
|
||||
518651AF23555EB20078E021 /* NNW3Entry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651A823555EB20078E021 /* NNW3Entry.swift */; };
|
||||
518651B023555EB20078E021 /* NNW3FeedsImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651A923555EB20078E021 /* NNW3FeedsImporter.swift */; };
|
||||
518651B123555EB20078E021 /* NNW3Feed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651AA23555EB20078E021 /* NNW3Feed.swift */; };
|
||||
518651B223555EB20078E021 /* NNW3Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = 518651AB23555EB20078E021 /* NNW3Document.swift */; };
|
||||
518B2EE82351B45600400001 /* NetNewsWire_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840D61952029031D009BC708 /* NetNewsWire_iOSTests.swift */; };
|
||||
51934CCB230F599B006127BE /* ThemedNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CC1230F5963006127BE /* ThemedNavigationController.swift */; };
|
||||
51934CCE2310792F006127BE /* ActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CCD2310792F006127BE /* ActivityManager.swift */; };
|
||||
|
@ -784,6 +791,13 @@
|
|||
5183CCDE226F1FCC0010922C /* UINavigationController+Progress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Progress.swift"; sourceTree = "<group>"; };
|
||||
5183CCE4226F4DFA0010922C /* RefreshInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshInterval.swift; sourceTree = "<group>"; };
|
||||
5183CCE7226F68D90010922C /* AccountRefreshTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRefreshTimer.swift; sourceTree = "<group>"; };
|
||||
518651A523555EB20078E021 /* ImportNNW3WindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportNNW3WindowController.swift; sourceTree = "<group>"; };
|
||||
518651A623555EB20078E021 /* NNW3PlistConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NNW3PlistConverter.swift; sourceTree = "<group>"; };
|
||||
518651A723555EB20078E021 /* ImportNNW3Sheet.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ImportNNW3Sheet.xib; sourceTree = "<group>"; };
|
||||
518651A823555EB20078E021 /* NNW3Entry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NNW3Entry.swift; sourceTree = "<group>"; };
|
||||
518651A923555EB20078E021 /* NNW3FeedsImporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NNW3FeedsImporter.swift; sourceTree = "<group>"; };
|
||||
518651AA23555EB20078E021 /* NNW3Feed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NNW3Feed.swift; sourceTree = "<group>"; };
|
||||
518651AB23555EB20078E021 /* NNW3Document.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NNW3Document.swift; sourceTree = "<group>"; };
|
||||
518B2ED22351B3DD00400001 /* NetNewsWire-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "NetNewsWire-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
518B2EE92351B4C200400001 /* NetNewsWire_iOSTests_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_iOSTests_target.xcconfig; sourceTree = "<group>"; };
|
||||
51934CC1230F5963006127BE /* ThemedNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemedNavigationController.swift; sourceTree = "<group>"; };
|
||||
|
@ -1259,6 +1273,20 @@
|
|||
path = Settings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
518651A423555EB20078E021 /* NNW3 */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
518651A523555EB20078E021 /* ImportNNW3WindowController.swift */,
|
||||
518651A623555EB20078E021 /* NNW3PlistConverter.swift */,
|
||||
518651A723555EB20078E021 /* ImportNNW3Sheet.xib */,
|
||||
518651A823555EB20078E021 /* NNW3Entry.swift */,
|
||||
518651A923555EB20078E021 /* NNW3FeedsImporter.swift */,
|
||||
518651AA23555EB20078E021 /* NNW3Feed.swift */,
|
||||
518651AB23555EB20078E021 /* NNW3Document.swift */,
|
||||
);
|
||||
path = NNW3;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
51934CCC231078DC006127BE /* Activity */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -1507,6 +1535,7 @@
|
|||
849A97551ED9EAC3007D329B /* Add Feed */,
|
||||
849A97411ED9EAA9007D329B /* Add Folder */,
|
||||
5144EA39227A377700D19003 /* OPML */,
|
||||
518651A423555EB20078E021 /* NNW3 */,
|
||||
);
|
||||
path = MainWindow;
|
||||
sourceTree = "<group>";
|
||||
|
@ -2572,6 +2601,7 @@
|
|||
files = (
|
||||
844B5B651FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist in Resources */,
|
||||
5127B23A222B4849006D641D /* DetailKeyboardShortcuts.plist in Resources */,
|
||||
518651AE23555EB20078E021 /* ImportNNW3Sheet.xib in Resources */,
|
||||
845479881FEB77C000AD8B59 /* TimelineKeyboardShortcuts.plist in Resources */,
|
||||
848362FF2262A30E00DA1D35 /* template.html in Resources */,
|
||||
9EA33BBA2318F8C10097B644 /* AccountsFeedlyWeb.xib in Resources */,
|
||||
|
@ -2941,10 +2971,12 @@
|
|||
845A29221FC9251E007B49E3 /* SidebarCellLayout.swift in Sources */,
|
||||
84AD1EBA2031649C00BC20B7 /* SmartFeedPasteboardWriter.swift in Sources */,
|
||||
84CC88181FE59CBF00644329 /* SmartFeedsController.swift in Sources */,
|
||||
518651AF23555EB20078E021 /* NNW3Entry.swift in Sources */,
|
||||
849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */,
|
||||
9EA33BB92318F8C10097B644 /* AccountsFeedlyWebWindowController.swift in Sources */,
|
||||
849A97641ED9EB96007D329B /* SidebarOutlineView.swift in Sources */,
|
||||
5127B238222B4849006D641D /* DetailKeyboardDelegate.swift in Sources */,
|
||||
518651AC23555EB20078E021 /* ImportNNW3WindowController.swift in Sources */,
|
||||
8405DD9922153B6B008CE1BF /* TimelineContainerView.swift in Sources */,
|
||||
D5A2678C20130ECF00A8D3C0 /* Author+Scriptability.swift in Sources */,
|
||||
84F2D5371FC22FCC00998D64 /* PseudoFeed.swift in Sources */,
|
||||
|
@ -2972,6 +3004,7 @@
|
|||
849A97891ED9ECEF007D329B /* ArticleStyle.swift in Sources */,
|
||||
84FF69B11FC3793300DC198E /* FaviconURLFinder.swift in Sources */,
|
||||
84B7178C201E66580091657D /* SidebarViewController+ContextualMenus.swift in Sources */,
|
||||
518651AD23555EB20078E021 /* NNW3PlistConverter.swift in Sources */,
|
||||
5144EA43227A380F00D19003 /* ExportOPMLWindowController.swift in Sources */,
|
||||
842611A21FCB769D0086A189 /* RSHTMLMetadata+Extension.swift in Sources */,
|
||||
84A1500520048DDF0046AD9A /* SendToMarsEditCommand.swift in Sources */,
|
||||
|
@ -3013,6 +3046,7 @@
|
|||
849A97431ED9EAA9007D329B /* AddFolderWindowController.swift in Sources */,
|
||||
8405DDA522168C62008CE1BF /* TimelineContainerViewController.swift in Sources */,
|
||||
844B5B671FEA18E300C7C76A /* MainWIndowKeyboardHandler.swift in Sources */,
|
||||
518651B123555EB20078E021 /* NNW3Feed.swift in Sources */,
|
||||
848D578E21543519005FFAD5 /* PasteboardFeed.swift in Sources */,
|
||||
5144EA2F2279FAB600D19003 /* AccountsDetailViewController.swift in Sources */,
|
||||
849A97801ED9EC42007D329B /* DetailViewController.swift in Sources */,
|
||||
|
@ -3026,6 +3060,7 @@
|
|||
849A97771ED9EC04007D329B /* TimelineCellData.swift in Sources */,
|
||||
841ABA6020145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift in Sources */,
|
||||
D5E4CC54202C1361009B4FFC /* AppDelegate+Scriptability.swift in Sources */,
|
||||
518651B223555EB20078E021 /* NNW3Document.swift in Sources */,
|
||||
D5F4EDB5200744A700B9E363 /* ScriptingObject.swift in Sources */,
|
||||
D5F4EDB920074D7C00B9E363 /* Folder+Scriptability.swift in Sources */,
|
||||
849A97781ED9EC04007D329B /* TimelineCellLayout.swift in Sources */,
|
||||
|
@ -3047,6 +3082,7 @@
|
|||
84C9FC7C22629E1200D921D6 /* AccountsPreferencesViewController.swift in Sources */,
|
||||
51EC114C2149FE3300B296E3 /* FolderTreeMenu.swift in Sources */,
|
||||
849A97A31ED9F180007D329B /* FolderTreeControllerDelegate.swift in Sources */,
|
||||
518651B023555EB20078E021 /* NNW3FeedsImporter.swift in Sources */,
|
||||
51126DA4225FDE2F00722696 /* RSImage-Extensions.swift in Sources */,
|
||||
845A29091FC74B8E007B49E3 /* SingleFaviconDownloader.swift in Sources */,
|
||||
D5F4EDB720074D6500B9E363 /* Feed+Scriptability.swift in Sources */,
|
||||
|
|
Loading…
Reference in New Issue