Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Support for IINA on AppleScript #539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions LyricsX/Assets.xcassets/app_icon/iina_icon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "iina_icon.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "iina_icon_@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 62 additions & 25 deletions LyricsX/Base.lproj/Preferences.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class PreferenceGeneralViewController: NSViewController {
@IBOutlet weak var preferVox: NSButton!
@IBOutlet weak var preferAudirvana: NSButton!
@IBOutlet weak var preferSwinsian: NSButton!

@IBOutlet weak var preferIina: NSButton!

@IBOutlet weak var autoLaunchButton: NSButton!

@IBOutlet weak var savingPathPopUp: NSPopUpButton!
Expand All @@ -45,6 +46,8 @@ class PreferenceGeneralViewController: NSViewController {
loadHomonymLrcButton.isEnabled = false
case 4:
preferSwinsian.state = .on
case 5:
preferIina.state = .on
default:
preferAuto.state = .on
autoLaunchButton.isEnabled = false
Expand Down
1 change: 1 addition & 0 deletions LyricsX/Supporting Files/LyricsX.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string>com.audirvana.Audirvana-Plus</string>
<string>com.audirvana.Audirvana</string>
<string>com.swinsian.Swinsian</string>
<string>com.colliderli.iina</string>
<string>ddddxxx.LyricsXHelper</string>
</array>
</dict>
Expand Down
2 changes: 2 additions & 0 deletions LyricsX/Utility/Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension MusicPlayerName {
case 2: self = .vox
case 3: self = .audirvana
case 4: self = .swinsian
case 5: self = .iina
default: return nil
}
}
Expand All @@ -32,6 +33,7 @@ extension MusicPlayerName {
case .vox: return #imageLiteral(resourceName: "vox_icon")
case .audirvana: return #imageLiteral(resourceName: "audirvana_icon")
case .swinsian: return #imageLiteral(resourceName: "swinsian_icon")
case .iina: return #imageLiteral(resourceName: "iina_icon")
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions LyricsXHelper/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ScriptingBridge

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

var musicPlayers: [SBApplication] = []
var shouldWaitForPlayerQuit = false

Expand All @@ -21,24 +21,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSApplication.shared.terminate(nil)
abort() // fake invoking, just make compiler happy.
}

let index = groupDefaults.integer(forKey: preferredPlayerIndex)
let ident = playerBundleIdentifiers[index]
musicPlayers = ident.compactMap(SBApplication.init)

let event = NSAppleEventManager.shared().currentAppleEvent
let isLaunchedAsLoginItem = event?.eventID == kAEOpenApplication &&
event?.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem
let isLaunchedByMain = (groupDefaults.object(forKey: launchHelperTime) as? Date).map { Date().timeIntervalSince($0) < 10 } ?? false
shouldWaitForPlayerQuit = !isLaunchedAsLoginItem && isLaunchedByMain && musicPlayers.contains { $0.isRunning }

let wsnc = NSWorkspace.shared.notificationCenter
wsnc.addObserver(self, selector: #selector(checkTargetApplication), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
wsnc.addObserver(self, selector: #selector(checkTargetApplication), name: NSWorkspace.didTerminateApplicationNotification, object: nil)

checkTargetApplication()
}

@objc func checkTargetApplication() {
let isRunning = musicPlayers.contains { $0.isRunning }
if shouldWaitForPlayerQuit {
Expand Down Expand Up @@ -72,6 +72,7 @@ let playerBundleIdentifiers = [
["com.coppertino.Vox"],
["com.audirvana.Audirvana-Studio", "com.audirvana.Audirvana", "com.audirvana.Audirvana-Plus"],
["com.swinsian.Swinsian"],
["com.colliderli.iina"],
]

let groupDefaults = UserDefaults(suiteName: "3665V726AE.group.ddddxxx.LyricsX")!
Expand Down