Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  update: layout
  update: text
  remove redundant instance variable from karaoke lyrics
  fix: update karaoke lyrics at very beginning
  update: Chinese converter also affect menubar lyrics
  • Loading branch information
ddddxxx committed Apr 15, 2018
2 parents cfa9d88 + 8228f39 commit 5b9a2b6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
7 changes: 5 additions & 2 deletions LyricsX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,12 @@
</scroller>
</scrollView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WCj-2B-3nx">
<rect key="frame" x="126" y="131" width="68" height="19"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="No Lyrics" id="aRw-yQ-GNX">
<rect key="frame" x="52" y="112" width="217" height="57"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" id="aRw-yQ-GNX">
<font key="font" metaFont="system" size="15"/>
<string key="title">No Lyrics

Drag &amp; Drop to import LRC file</string>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand Down
7 changes: 4 additions & 3 deletions LyricsX/Base.lproj/Perference.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1053,17 +1053,18 @@
<action selector="insert:" target="0dY-rB-aBJ" id="6n6-mw-7xL"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="12H-lM-uSV">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="12H-lM-uSV">
<rect key="frame" x="18" y="348" width="466" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Lyrics lines maching following rules will be ignored. Use &quot;/&quot; to start a regular expression." id="19E-DG-Q23">
<font key="font" metaFont="system" size="11"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Lyrics lines maching following rules will be ignored. Use &quot;/&quot; to start a regular expression." id="19E-DG-Q23">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="K5Z-h7-BAg" firstAttribute="leading" secondItem="Vz7-Vi-Uvh" secondAttribute="leading" id="11l-Du-OP6"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="12H-lM-uSV" secondAttribute="trailing" constant="20" id="1aD-JI-T18"/>
<constraint firstAttribute="bottom" secondItem="Vz7-Vi-Uvh" secondAttribute="bottom" constant="72" id="42x-R9-Xwv"/>
<constraint firstItem="8CL-CP-GqX" firstAttribute="leading" secondItem="K5Z-h7-BAg" secondAttribute="trailing" constant="-1" id="660-Ks-BUg"/>
<constraint firstItem="12H-lM-uSV" firstAttribute="leading" secondItem="XfX-or-1LJ" secondAttribute="leading" id="BZH-xK-SuH"/>
Expand Down
8 changes: 1 addition & 7 deletions LyricsX/Controller/KaraokeLyricsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class KaraokeLyricsWindowController: NSWindowController {

private var lyricsView = KaraokeLyricsView(frame: .zero)

var currentLineIndex: Int?

var defaultObservations: [DefaultsObservation] = []
var notifications: [NSObjectProtocol] = []

Expand All @@ -54,6 +52,7 @@ class KaraokeLyricsWindowController: NSWindowController {
lyricsView.displayLrc("LyricsX")
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
self.lyricsView.displayLrc("")
self.handleLyricsDisplay()
NotificationCenter.default.addObserver(self, selector: #selector(self.handleLyricsDisplay), name: .lyricsShouldDisplay, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.handleLyricsDisplay), name: .currentLyricsChange, object: nil)
}
Expand Down Expand Up @@ -116,16 +115,11 @@ class KaraokeLyricsWindowController: NSWindowController {
!defaults[.DisableLyricsWhenPaused] || AppController.shared.playerManager.player?.playbackState == .playing,
let lyrics = AppController.shared.currentLyrics,
let index = AppController.shared.currentLineIndex else {
currentLineIndex = nil
DispatchQueue.main.async {
self.lyricsView.displayLrc("", secondLine: "")
}
return
}
guard currentLineIndex != index else {
return
}
currentLineIndex = index

let lrc = lyrics.lines[index]
let next = lyrics.lines[(index+1)...].first { $0.enabled }
Expand Down
22 changes: 13 additions & 9 deletions LyricsX/Controller/MenuBarLyrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Cocoa
import LyricsProvider
import MusicPlayer
import GenericID
import OpenCC

class MenuBarLyrics: NSObject {

Expand All @@ -32,7 +33,7 @@ class MenuBarLyrics: NSObject {
var buttonImage = #imageLiteral(resourceName: "status_bar_icon")
var buttonlength: CGFloat = 30

private var displayLyrics = ""
private var screenLyrics = ""

var statusItemObservation: DefaultsObservation?

Expand All @@ -53,20 +54,23 @@ class MenuBarLyrics: NSObject {
guard !defaults[.DisableLyricsWhenPaused] || AppController.shared.playerManager.player?.playbackState == .playing,
let lyrics = AppController.shared.currentLyrics,
let index = AppController.shared.currentLineIndex else {
displayLyrics = ""
screenLyrics = ""
updateStatusItem()
return
}
let lrc = lyrics.lines[index].content
if lrc == displayLyrics {
var newScreenLyrics = lyrics.lines[index].content
if let converter = ChineseConverter.shared {
newScreenLyrics = converter.convert(newScreenLyrics)
}
if newScreenLyrics == screenLyrics {
return
}
displayLyrics = lrc
screenLyrics = newScreenLyrics
updateStatusItem()
}

@objc func updateStatusItem() {
guard defaults[.MenuBarLyricsEnabled], !displayLyrics.isEmpty else {
guard defaults[.MenuBarLyricsEnabled], !screenLyrics.isEmpty else {
setImageStatusItem()
lyricsItem = nil
return
Expand All @@ -86,19 +90,19 @@ class MenuBarLyrics: NSObject {
lyricsItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
lyricsItem?.highlightMode = false
}
lyricsItem?.title = displayLyrics
lyricsItem?.title = screenLyrics
}

func updateCombinedStatusLyrics() {
lyricsItem = nil

setTextStatusItem(string: displayLyrics)
setTextStatusItem(string: screenLyrics)
if statusItem.isVisibe {
return
}

// truncation
var components = displayLyrics.components(options: [.byWords])
var components = screenLyrics.components(options: [.byWords])
while !components.isEmpty, !statusItem.isVisibe {
components.removeLast()
let proposed = components.joined() + "..."
Expand Down
2 changes: 1 addition & 1 deletion LyricsX/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.3.0</string>
<key>CFBundleVersion</key>
<string>1670</string>
<string>1677</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
4 changes: 2 additions & 2 deletions LyricsX/en.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
/* Class = "NSMenuItem"; title = "Enable Menu Bar Lyrics"; ObjectID = "Z7d-yp-uRx"; */
"Z7d-yp-uRx.title" = "Enable Menu Bar Lyrics";

/* Class = "NSTextFieldCell"; title = "No Lyrics"; ObjectID = "aRw-yQ-GNX"; */
"aRw-yQ-GNX.title" = "No Lyrics";
/* Class = "NSTextFieldCell"; title = "No Lyrics\n\nDrag & Drop to import LRC file"; ObjectID = "aRw-yQ-GNX"; */
"aRw-yQ-GNX.title" = "No Lyrics\n\nDrag & Drop to import LRC file";

/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "c9V-Dh-f1D"; */
"c9V-Dh-f1D.title" = "Text Cell";
Expand Down
4 changes: 2 additions & 2 deletions LyricsX/zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
/* Class = "NSMenuItem"; title = "Enable Menu Bar Lyrics"; ObjectID = "Z7d-yp-uRx"; */
"Z7d-yp-uRx.title" = "启用菜单栏歌词";

/* Class = "NSTextFieldCell"; title = "No Lyrics"; ObjectID = "aRw-yQ-GNX"; */
"aRw-yQ-GNX.title" = "没有歌词";
/* Class = "NSTextFieldCell"; title = "No Lyrics\n\nDrag & Drop to import LRC file"; ObjectID = "aRw-yQ-GNX"; */
"aRw-yQ-GNX.title" = "没有歌词\n\n拖拽以导入 LRC 歌词";

/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "c9V-Dh-f1D"; */
"c9V-Dh-f1D.title" = "Text Cell";
Expand Down

0 comments on commit 5b9a2b6

Please sign in to comment.