Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Commit

Permalink
Start Spotify in background
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmeusel committed Jun 18, 2019
1 parent 1af1cc9 commit 0dbe660
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MuteSpotifyAds/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.8.1</string>
<string>1.8.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
Expand Down
15 changes: 11 additions & 4 deletions MuteSpotifyAds/SpotifyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SpotifyManager: NSObject {


DispatchQueue.global(qos: .default).async {
self.startSpotify()
self.startSpotify(foreground: true)

_ = self.trackChanged()
}
Expand Down Expand Up @@ -86,11 +86,18 @@ class SpotifyManager: NSObject {
FSEventStreamStart(fileEventStream!)
}

func startSpotify() {
func startSpotify(foreground: Bool) {
let process = Process()
// Open application with bundle identifier
process.launchPath = "/usr/bin/open"
process.arguments = ["--hide", "-b", "com.spotify.client"]

var arguments: [String] = []
if (!foreground) {
arguments += ["--hide", "--background"]
}
arguments += ["-b", "com.spotify.client"]

process.arguments = arguments
process.launch()
process.waitUntilExit()
}
Expand Down Expand Up @@ -225,7 +232,7 @@ class SpotifyManager: NSObject {
isRestarting = true
titleChangeHandler(.ad)
_ = runAppleScript(script: SpotifyManager.appleScriptSpotifyPrefix + "quit")
startSpotify()
startSpotify(foreground: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
self.spotifyPlay()
DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: {
Expand Down

0 comments on commit 0dbe660

Please sign in to comment.