diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/30.imageset/30.png b/SpotifyLyricsInMenubar/Assets.xcassets/30.imageset/30.png new file mode 100644 index 0000000..797cd9e Binary files /dev/null and b/SpotifyLyricsInMenubar/Assets.xcassets/30.imageset/30.png differ diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/30.imageset/Contents.json b/SpotifyLyricsInMenubar/Assets.xcassets/30.imageset/Contents.json new file mode 100644 index 0000000..2118fee --- /dev/null +++ b/SpotifyLyricsInMenubar/Assets.xcassets/30.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "30.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/40.imageset/40.png b/SpotifyLyricsInMenubar/Assets.xcassets/40.imageset/40.png new file mode 100644 index 0000000..0cec67b Binary files /dev/null and b/SpotifyLyricsInMenubar/Assets.xcassets/40.imageset/40.png differ diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/40.imageset/Contents.json b/SpotifyLyricsInMenubar/Assets.xcassets/40.imageset/Contents.json new file mode 100644 index 0000000..35a5963 --- /dev/null +++ b/SpotifyLyricsInMenubar/Assets.xcassets/40.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "40.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/50.imageset/50.png b/SpotifyLyricsInMenubar/Assets.xcassets/50.imageset/50.png new file mode 100644 index 0000000..a53e6e6 Binary files /dev/null and b/SpotifyLyricsInMenubar/Assets.xcassets/50.imageset/50.png differ diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/50.imageset/Contents.json b/SpotifyLyricsInMenubar/Assets.xcassets/50.imageset/Contents.json new file mode 100644 index 0000000..4332cac --- /dev/null +++ b/SpotifyLyricsInMenubar/Assets.xcassets/50.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "50.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/60.imageset/60.png b/SpotifyLyricsInMenubar/Assets.xcassets/60.imageset/60.png new file mode 100644 index 0000000..05836b5 Binary files /dev/null and b/SpotifyLyricsInMenubar/Assets.xcassets/60.imageset/60.png differ diff --git a/SpotifyLyricsInMenubar/Assets.xcassets/60.imageset/Contents.json b/SpotifyLyricsInMenubar/Assets.xcassets/60.imageset/Contents.json new file mode 100644 index 0000000..85717be --- /dev/null +++ b/SpotifyLyricsInMenubar/Assets.xcassets/60.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "60.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SpotifyLyricsInMenubar/OnboardingWindow.swift b/SpotifyLyricsInMenubar/OnboardingWindow.swift index e3c15d8..1bdeb01 100644 --- a/SpotifyLyricsInMenubar/OnboardingWindow.swift +++ b/SpotifyLyricsInMenubar/OnboardingWindow.swift @@ -66,7 +66,7 @@ struct ZeroView: View { NSWorkspace.shared.open(url) }) Spacer() - NavigationLink(destination: FirstView(), isActive: $isShowingDetailView) {EmptyView()} + NavigationLink(destination: BetweenZeroAndFirstView(), isActive: $isShowingDetailView) {EmptyView()} .hidden() if error && !isLoading { Text("WRONG SP DC COOKIE TRY AGAIN ⚠️") @@ -80,11 +80,7 @@ struct ZeroView: View { Button("Next") { Task { isLoading = true - if spDcCookie.count != 159 { - error = true - isLoading = false - } - else if let url = URL(string: "https://open.spotify.com/get_access_token?reason=transport&productType=web_player") { + if let url = URL(string: "https://open.spotify.com/get_access_token?reason=transport&productType=web_player") { do { var request = URLRequest(url: url) request.setValue("sp_dc=\(spDcCookie)", forHTTPHeaderField: "Cookie") @@ -132,6 +128,56 @@ struct ZeroView: View { } } +struct BetweenZeroAndFirstView: View { + @Environment(\.dismiss) var dismiss + //@AppStorage("truncationLength") var truncationLength: Int = 50 + @State var truncationLength: Int = UserDefaults.standard.integer(forKey: "truncationLength") + @Environment(\.controlActiveState) var controlActiveState + let allTruncations = [30,40,50,60] + var body: some View { + VStack(alignment: .leading, spacing: 16) { + StepView(title: "2. Set the Lyric Size", description: "This depends on how much free space you have in your menu bar!") + + Image("\(truncationLength)") + .resizable() + .scaledToFit() + + HStack { + Spacer() + Picker("Truncation Length", selection: $truncationLength) { + ForEach(allTruncations, id:\.self) { oneThing in + Text("\(oneThing) Characters") + } + } + .pickerStyle(.radioGroup) + Spacer() + } + + HStack { + Button("Back") { + dismiss() + } + Spacer() + NavigationLink("Next", destination: FirstView()) + .buttonStyle(.borderedProminent) + } + + } + .onChange(of: truncationLength) { newLength in + UserDefaults.standard.set(newLength, forKey: "truncationLength") + } + .padding(.horizontal, 20) + .navigationBarBackButtonHidden(true) + .onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { newValue in + dismiss() + dismiss() + } + .onReceive(NotificationCenter.default.publisher(for: NSWindow.willMiniaturizeNotification)) { newValue in + dismiss() + dismiss() + } + } +} struct FirstView: View { @Environment(\.dismiss) var dismiss @@ -139,7 +185,7 @@ struct FirstView: View { @State var isAnimating = true var body: some View { VStack(alignment: .leading, spacing: 16) { - StepView(title: "2. Make sure you give Automation permission", description: "We need this permission to read the current song from Spotify, so that we can play the correct lyrics! Watch the following gif to correctly give permission.") + StepView(title: "3. Make sure you give Automation permission", description: "We need this permission to read the current song from Spotify, so that we can play the correct lyrics! Watch the following gif to correctly give permission.") HStack { Spacer() @@ -168,10 +214,12 @@ struct FirstView: View { .onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { newValue in dismiss() dismiss() + dismiss() } .onReceive(NotificationCenter.default.publisher(for: NSWindow.willMiniaturizeNotification)) { newValue in dismiss() dismiss() + dismiss() } .onChange(of: controlActiveState) { newState in if newState == .inactive { @@ -189,7 +237,7 @@ struct SecondView: View { @State var isAnimating = true var body: some View { VStack(alignment: .leading, spacing: 16) { - StepView(title: "3. Make sure you disable crossfades", description: "Because of a glitch within Spotify, crossfades make the lyrics appear out-of-sync on occasion.") + StepView(title: "4. Make sure you disable crossfades", description: "Because of a glitch within Spotify, crossfades make the lyrics appear out-of-sync on occasion.") HStack { Spacer() diff --git a/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift b/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift index a9e6dc5..7d71751 100644 --- a/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift +++ b/SpotifyLyricsInMenubar/SpotifyLyricsInMenubarApp.swift @@ -7,12 +7,14 @@ import SwiftUI import ServiceManagement + @main struct SpotifyLyricsInMenubarApp: App { @StateObject var viewmodel = viewModel.shared @AppStorage("launchOnLogin") var launchOnLogin: Bool = false @AppStorage("showLyrics") var showLyrics: Bool = true @AppStorage("hasOnboarded") var hasOnboarded: Bool = false + @AppStorage("truncationLength") var truncationLength: Int = 50 @Environment(\.openWindow) var openWindow var body: some Scene { MenuBarExtra(content: { @@ -147,9 +149,9 @@ struct SpotifyLyricsInMenubarApp: App { var menuBarTitle: String { if viewmodel.isPlaying, showLyrics, let currentlyPlayingLyricsIndex = viewmodel.currentlyPlayingLyricsIndex { - return viewmodel.currentlyPlayingLyrics[currentlyPlayingLyricsIndex].words.trunc(length: 50) + return viewmodel.currentlyPlayingLyrics[currentlyPlayingLyricsIndex].words.trunc(length: truncationLength) } else if let currentlyPlayingName = viewmodel.currentlyPlayingName { - return "Now \(viewmodel.isPlaying ? "Playing" : "Paused"): \(currentlyPlayingName.trunc(length: 50))" + return "Now \(viewmodel.isPlaying ? "Playing" : "Paused"): \(currentlyPlayingName)".trunc(length: truncationLength) } return "Nothing Playing on Spotify" } diff --git a/SpotifyLyricsInMenubar/viewModel.swift b/SpotifyLyricsInMenubar/viewModel.swift index 475d81e..187051f 100644 --- a/SpotifyLyricsInMenubar/viewModel.swift +++ b/SpotifyLyricsInMenubar/viewModel.swift @@ -164,11 +164,11 @@ import SwiftUI decoder.userInfo[CodingUserInfoKey.trackName] = trackName decoder.userInfo[CodingUserInfoKey.duration] = TimeInterval(intDuration+10) /* - check if saved access token is bigger than current time, then continue with url shit + check if saved access token is bigger than current time, then continue with lyric fetch else check if we have spdc cookie, then access token stuff then save access token in this observable object - then continue with url shit + then continue with lyric fetch otherwise [] */ if accessToken == nil || (accessToken!.accessTokenExpirationTimestampMs <= Date().timeIntervalSince1970*1000) {