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

Commit 0dbe660

Browse files
committed
Start Spotify in background
1 parent 1af1cc9 commit 0dbe660

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

MuteSpotifyAds/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.8.1</string>
20+
<string>1.8.2</string>
2121
<key>CFBundleVersion</key>
2222
<string>1</string>
2323
<key>LSMinimumSystemVersion</key>

MuteSpotifyAds/SpotifyManager.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SpotifyManager: NSObject {
4747

4848

4949
DispatchQueue.global(qos: .default).async {
50-
self.startSpotify()
50+
self.startSpotify(foreground: true)
5151

5252
_ = self.trackChanged()
5353
}
@@ -86,11 +86,18 @@ class SpotifyManager: NSObject {
8686
FSEventStreamStart(fileEventStream!)
8787
}
8888

89-
func startSpotify() {
89+
func startSpotify(foreground: Bool) {
9090
let process = Process()
9191
// Open application with bundle identifier
9292
process.launchPath = "/usr/bin/open"
93-
process.arguments = ["--hide", "-b", "com.spotify.client"]
93+
94+
var arguments: [String] = []
95+
if (!foreground) {
96+
arguments += ["--hide", "--background"]
97+
}
98+
arguments += ["-b", "com.spotify.client"]
99+
100+
process.arguments = arguments
94101
process.launch()
95102
process.waitUntilExit()
96103
}
@@ -225,7 +232,7 @@ class SpotifyManager: NSObject {
225232
isRestarting = true
226233
titleChangeHandler(.ad)
227234
_ = runAppleScript(script: SpotifyManager.appleScriptSpotifyPrefix + "quit")
228-
startSpotify()
235+
startSpotify(foreground: false)
229236
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
230237
self.spotifyPlay()
231238
DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: {

0 commit comments

Comments
 (0)