Skip to content

Commit

Permalink
Merge develop into master. v0.1-build4.
Browse files Browse the repository at this point in the history
  • Loading branch information
xjbeta committed Aug 5, 2018
2 parents ff1d2b8 + 3f9ef29 commit f9916a5
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 50 deletions.
4 changes: 3 additions & 1 deletion iina+.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
01479CD6210B35480046AAAD /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; };
014B447B210069FF00E7AA6A /* Bookmark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bookmark.swift; sourceTree = "<group>"; };
014B447C210069FF00E7AA6A /* BookmarkExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkExtension.swift; sourceTree = "<group>"; };
014FD3A42115CB3000F05399 /* Bookmark v0.2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Bookmark v0.2.xcdatamodel"; sourceTree = "<group>"; };
0161CAF9210E010200AB5D9A /* SubString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubString.swift; sourceTree = "<group>"; };
01AEC8A720EDFD01001406E8 /* iina+.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iina+.app"; sourceTree = BUILT_PRODUCTS_DIR; };
01AEC8AA20EDFD01001406E8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -550,9 +551,10 @@
010F0F1720FE4F0900F33553 /* DataModel.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
014FD3A42115CB3000F05399 /* Bookmark v0.2.xcdatamodel */,
010F0F1820FE4F0900F33553 /* Bookmark.xcdatamodel */,
);
currentVersion = 010F0F1820FE4F0900F33553 /* Bookmark.xcdatamodel */;
currentVersion = 014FD3A42115CB3000F05399 /* Bookmark v0.2.xcdatamodel */;
path = DataModel.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
23 changes: 23 additions & 0 deletions iina+/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {

lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "DataModel")
let shouldInitOrder = !checkForMigration()

container.loadPersistentStores { _, error in
if let error = error {
fatalError("Unresolved error \(error)")
}
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
}

if shouldInitOrder {
// set dafault value for orders
if container.managedObjectModel.entitiesByName["Bookmark"]?.versionHashModifier == "added order" {
try? container.viewContext.fetch(NSFetchRequest<NSFetchRequestResult>(entityName: "Bookmark")).enumerated().forEach {
if let bookmark = $0.element as? Bookmark {
bookmark.setValue($0.offset, forKey: "order")
}
}
try? container.viewContext.save()
}
}
return container
}()

Expand Down Expand Up @@ -118,5 +132,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return .terminateNow
}


func checkForMigration() -> Bool {
let container = NSPersistentContainer(name: "DataModel")
if let storeUrl = container.persistentStoreDescriptions.first?.url,
let metadata = try? NSPersistentStoreCoordinator.metadataForPersistentStore(ofType: NSSQLiteStoreType, at: storeUrl) {
return container.managedObjectModel.isConfiguration(withName: nil, compatibleWithStoreMetadata: metadata)
}
return false
}
}

9 changes: 5 additions & 4 deletions iina+/Core Data/BookmarkExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import CoreData


extension Bookmark {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Bookmark> {
return NSFetchRequest<Bookmark>(entityName: "Bookmark")
}


@NSManaged public var order: Double
@NSManaged public var remark: String?
@NSManaged public var url: String?

@NSManaged public var url: String
}
34 changes: 27 additions & 7 deletions iina+/Core Data/DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import Cocoa

class DataManager: NSObject {

var appDelegate: AppDelegate {
return NSApp.delegate as! AppDelegate
}
let context = (NSApp.delegate as! AppDelegate).persistentContainer.viewContext
let sortDescriptors = [NSSortDescriptor(key: #keyPath(Bookmark.order), ascending: true)]

func requestData() -> [Bookmark] {
let context = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Bookmark")

request.sortDescriptors = sortDescriptors
if let fetch = try? context.fetch(request),
let re = fetch as? [Bookmark] {
return re
Expand All @@ -26,19 +24,41 @@ class DataManager: NSObject {
}

func addBookmark(_ str: String) {
let context = appDelegate.persistentContainer.viewContext
let newBookmark = Bookmark(context: context)
newBookmark.url = str
if let last = requestData().last {
newBookmark.order = last.order + 1
} else {
newBookmark.order = 0
}
try? context.save()
}

func deleteBookmark(_ index: Int) {
let context = appDelegate.persistentContainer.viewContext
let bookmark = requestData()[index]
context.delete(bookmark)
try? context.save()
}

func moveBookmark(at oldIndex: Int, to newIndex: Int) {
let bookmarks = requestData()
let oldBookmark = bookmarks[oldIndex]

switch newIndex {
case 0:
oldBookmark.order = bookmarks[0].order - 1
case bookmarks.count - 1:
oldBookmark.order = bookmarks[newIndex].order + 1
case _ where newIndex > oldIndex:
oldBookmark.order = (bookmarks[newIndex].order + bookmarks[newIndex + 1].order) / 2
case _ where newIndex < oldIndex:
oldBookmark.order = (bookmarks[newIndex].order + bookmarks[newIndex - 1].order) / 2
default:
break
}
try? context.save()
}

func checkURL(_ url: String) -> Bool {
do {
let detector = try NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
Expand Down
8 changes: 8 additions & 0 deletions iina+/Core Data/DataModel.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Bookmark v0.2.xcdatamodel</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14315.2.4" systemVersion="17G65" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Bookmark" representedClassName=".Bookmark" versionHashModifier="added order" syncable="YES">
<attribute name="order" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="remark" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="url" optional="YES" attributeType="String" defaultValueString="https://live.bilibili.com/1010" syncable="YES"/>
</entity>
<elements>
<element name="Bookmark" positionX="-103.39453125" positionY="-9" width="177.39453125" height="90"/>
</elements>
</model>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14308.2" systemVersion="17G65" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14315.2.4" systemVersion="17G65" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Bookmark" representedClassName=".Bookmark" syncable="YES">
<attribute name="remark" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="url" optional="YES" attributeType="String" defaultValueString="https://live.bilibili.com/1010" syncable="YES"/>
Expand Down
2 changes: 1 addition & 1 deletion iina+/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.video</string>
<key>LSMinimumSystemVersion</key>
Expand Down
3 changes: 2 additions & 1 deletion iina+/Processes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Processes: NSObject {
func openWithPlayer(_ url: String, title: String) {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
// task.standardOutput = pipe
task.standardInput = pipe
var mpvArgs = ["\(MPVOption.Miscellaneous.forceMediaTitle)=\(title)"]

if url.contains("douyu") {
Expand Down
15 changes: 8 additions & 7 deletions iina+/Views/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@
<items>
<menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
<connections>
<action selector="undo:" target="Ady-hI-5gd" id="M6e-cu-g7V"/>
<action selector="undo:" target="XfU-aw-sKA" id="SBj-pe-RGV"/>
</connections>
</menuItem>
<menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
<connections>
<action selector="redo:" target="Ady-hI-5gd" id="oIA-Rs-6OD"/>
<action selector="redo:" target="XfU-aw-sKA" id="nfz-Bz-sfD"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
Expand Down Expand Up @@ -386,7 +386,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<searchField wantsLayer="YES" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fWl-HZ-9Tf">
<rect key="frame" x="24" y="575" width="402" height="22"/>
<rect key="frame" x="20" y="575" width="410" height="22"/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="Tmj-IU-6YE">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -450,7 +450,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView distribution="fill" orientation="horizontal" alignment="centerY" spacing="6" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ooL-0t-lJ1">
<rect key="frame" x="12" y="8" width="407" height="39"/>
<rect key="frame" x="8" y="8" width="407" height="39"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="kWK-JR-5PF">
<rect key="frame" x="0.0" y="0.0" width="39" height="39"/>
Expand Down Expand Up @@ -501,7 +501,7 @@
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="ooL-0t-lJ1" secondAttribute="trailing" constant="8" id="Qm4-bO-ffl"/>
<constraint firstItem="ooL-0t-lJ1" firstAttribute="leading" secondItem="OMv-zq-neh" secondAttribute="leading" constant="12" id="Uao-M1-Mhs"/>
<constraint firstItem="ooL-0t-lJ1" firstAttribute="leading" secondItem="OMv-zq-neh" secondAttribute="leading" constant="8" id="Uao-M1-Mhs"/>
<constraint firstItem="ooL-0t-lJ1" firstAttribute="centerY" secondItem="OMv-zq-neh" secondAttribute="centerY" id="nmZ-8h-1Gu"/>
</constraints>
<connections>
Expand Down Expand Up @@ -547,16 +547,17 @@
</scrollView>
</subviews>
<constraints>
<constraint firstItem="fWl-HZ-9Tf" firstAttribute="leading" secondItem="0fR-Ao-cHY" secondAttribute="leading" constant="24" id="2TC-2B-Tyo"/>
<constraint firstItem="fWl-HZ-9Tf" firstAttribute="leading" secondItem="0fR-Ao-cHY" secondAttribute="leading" constant="20" id="2TC-2B-Tyo"/>
<constraint firstItem="fWl-HZ-9Tf" firstAttribute="top" secondItem="0fR-Ao-cHY" secondAttribute="top" constant="30" id="2ZH-hl-ZAG"/>
<constraint firstAttribute="trailing" secondItem="fWl-HZ-9Tf" secondAttribute="trailing" constant="24" id="69S-dT-rzw"/>
<constraint firstAttribute="trailing" secondItem="fWl-HZ-9Tf" secondAttribute="trailing" constant="20" id="69S-dT-rzw"/>
<constraint firstAttribute="bottom" secondItem="txu-4A-pVl" secondAttribute="bottom" constant="15" id="CBr-NQ-kAf"/>
<constraint firstItem="txu-4A-pVl" firstAttribute="top" secondItem="fWl-HZ-9Tf" secondAttribute="bottom" constant="6" id="Nfd-Qi-mpS"/>
<constraint firstItem="txu-4A-pVl" firstAttribute="leading" secondItem="0fR-Ao-cHY" secondAttribute="leading" constant="20" id="Shn-Ji-3fT"/>
<constraint firstAttribute="trailing" secondItem="txu-4A-pVl" secondAttribute="trailing" constant="20" id="ewz-zC-rUc"/>
</constraints>
</visualEffectView>
<connections>
<outlet property="bookmarkArrayController" destination="VY8-9O-I1C" id="PeA-ZJ-S3Z"/>
<outlet property="bookmarkTableView" destination="9PD-kf-1gB" id="RGX-fP-nIe"/>
<outlet property="searchField" destination="fWl-HZ-9Tf" id="FnM-Mh-que"/>
<segue destination="Rej-VG-aRz" kind="sheet" identifier="showAddBookmarkViewController" id="iRV-tt-3nd"/>
Expand Down
32 changes: 32 additions & 0 deletions iina+/Views/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,40 @@
import Cocoa

class MainMenu: NSObject {
override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {

if let window = NSApp.keyWindow,
let appDelegate = NSApp.delegate as? AppDelegate,
let undoManager = appDelegate.persistentContainer.viewContext.undoManager {

if menuItem.action == #selector(undo) {
return window.windowController is MainWindowController && undoManager.canUndo
}
if menuItem.action == #selector(redo) {
return window.windowController is MainWindowController && undoManager.canRedo
}
}

if menuItem.action == #selector(reloadLiveStatus) {
return NSApp.keyWindow?.windowController is MainWindowController
}
return false
}

@IBAction func reloadLiveStatus(_ sender: Any) {
NotificationCenter.default.post(name: .reloadLiveStatus, object: nil)
}

@IBAction func undo(_ sender: Any) {
if let appDelegate = NSApp.delegate as? AppDelegate {
appDelegate.persistentContainer.viewContext.undo()
}
}

@IBAction func redo(_ sender: Any) {
if let appDelegate = NSApp.delegate as? AppDelegate {
appDelegate.persistentContainer.viewContext.redo()
}
}

}
35 changes: 34 additions & 1 deletion iina+/Views/MainWindow/LiveStatusTableCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ class LiveStatusTableCellView: NSTableCellView {
@IBOutlet weak var liveStatusImageView: NSImageView!
@IBOutlet weak var titleTextField: NSTextField!
@IBOutlet weak var nameTextField: NSTextField!

var isSelected: Bool = false {
didSet {
needsDisplay = true
}
}

override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)

// Drawing code here.
let selectionRect = NSInsetRect(bounds, 0, 0)
let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 6, yRadius: 6)
if isSelected {
NSColor.selectedControlColor.setFill()
} else {
NSColor.white.setFill()
}
selectionPath.fill()
}

func resetInfo() {
Expand All @@ -36,4 +50,23 @@ class LiveStatusTableCellView: NSTableCellView {
}
}


func screenshot(_ rect: CGRect? = nil) -> NSImage {
let image = NSImage()
let rect = rect ?? self.bounds

if let bitmap = self.bitmapImageRepForCachingDisplay( in: rect ) {
self.cacheDisplay( in: rect, to: bitmap )
image.addRepresentation( bitmap )
}

return image
}

}

extension NSColor {
public class var customBackgroundColor: NSColor {
return NSColor(calibratedRed: 0.97, green: 0.95, blue: 0.94, alpha: 1)
}
}
26 changes: 6 additions & 20 deletions iina+/Views/MainWindow/LiveStatusTableRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,19 @@ class LiveStatusTableRowView: NSTableRowView {

override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
drawSelection(in: bounds)
}

override var isSelected: Bool {
didSet {
drawSelection(in: bounds)
needsDisplay = true
if let cell = subviews.first as? LiveStatusTableCellView {
cell.isSelected = isSelected
}
}
}

override func drawSelection(in dirtyRect: NSRect) {
let selectionRect = NSInsetRect(bounds, 4, 4)
let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 6, yRadius: 6)
if isSelected {
NSColor.selectedControlColor.setFill()
} else {
NSColor.white.setFill()
}
selectionPath.fill()
}

let defaultRowColor = NSColor(catalogName: "System", colorName: "controlAlternatingRowColor")

}

extension NSColor {
public class var customBackgroundColor: NSColor {
return NSColor(calibratedRed: 0.97, green: 0.95, blue: 0.94, alpha: 1)
override func drawFocusRingMask() {
let selectionRect = NSInsetRect(bounds, 0, 0)
NSBezierPath(roundedRect: selectionRect, xRadius: 6, yRadius: 6).fill()
}
}
Loading

0 comments on commit f9916a5

Please sign in to comment.