Skip to content

Commit

Permalink
Fix #2424
Browse files Browse the repository at this point in the history
  • Loading branch information
saagarjha committed May 29, 2019
1 parent 425f221 commit 818b436
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions iina/MenuController.swift
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -396,12 +396,21 @@ class MenuController: NSObject, NSMenuDelegate {
private func updateChapterList() { private func updateChapterList() {
chapterMenu.removeAllItems() chapterMenu.removeAllItems()
let info = PlayerCore.active.info let info = PlayerCore.active.info
let padder = { (time: String) -> String in
let standard = (info.chapters.last?.time.stringRepresentation ?? "").reversed()
return String((time.reversed() + standard[standard.index(standard.startIndex, offsetBy: time.count)...].map {
$0 == ":" ? ":" : "0"
}).reversed())
}
for (index, chapter) in info.chapters.enumerated() { for (index, chapter) in info.chapters.enumerated() {
let menuTitle = "\(chapter.time.stringRepresentation) - \(chapter.title)" let menuTitle = "\(padder(chapter.time.stringRepresentation)) \(chapter.title)"
let nextChapterTime = info.chapters[at: index+1]?.time ?? Constants.Time.infinite let nextChapterTime = info.chapters[at: index+1]?.time ?? Constants.Time.infinite
let isPlaying = info.videoPosition?.between(chapter.time, nextChapterTime) ?? false let isPlaying = info.videoPosition?.between(chapter.time, nextChapterTime) ?? false
chapterMenu.addItem(withTitle: menuTitle, action: #selector(MainMenuActionHandler.menuChapterSwitch(_:)), let menuItem = NSMenuItem(title: menuTitle, action: #selector(MainMenuActionHandler.menuChapterSwitch(_:)), keyEquivalent: "")
tag: index, obj: nil, stateOn: isPlaying) menuItem.tag = index
menuItem.state = isPlaying ? .on : .off
menuItem.attributedTitle = NSAttributedString(string: menuTitle, attributes: [.font: NSFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular)])
chapterMenu.addItem(menuItem)
} }
} }


Expand Down

0 comments on commit 818b436

Please sign in to comment.