Skip to content

Commit

Permalink
fix marquee text, fix music live activity toggle, implement lottie an…
Browse files Browse the repository at this point in the history
…imations
  • Loading branch information
richardkunkli committed Nov 1, 2024
1 parent f805152 commit a6d0cca
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 39 deletions.
21 changes: 21 additions & 0 deletions boringNotch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
B186543C2C6F49AE000B926A /* ShortcutConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = B186543B2C6F49AE000B926A /* ShortcutConstants.swift */; };
B19016222CC15B3D00E3F12E /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = B19016212CC15B3D00E3F12E /* Defaults */; };
B19016242CC15B5000E3F12E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = B19016232CC15B4D00E3F12E /* Constants.swift */; };
B19424092CD0FF01003E5DC2 /* LottieAnimationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B19424082CD0FEFE003E5DC2 /* LottieAnimationView.swift */; };
B194240B2CD10017003E5DC2 /* LottieUI in Frameworks */ = {isa = PBXBuildFile; productRef = B194240A2CD10017003E5DC2 /* LottieUI */; };
B1A78C822C8BA08100BD51B0 /* FullscreenMediaDetection.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1A78C812C8BA08100BD51B0 /* FullscreenMediaDetection.swift */; };
B1A78C842C8C65ED00BD51B0 /* MediaRemote.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B1A78C832C8C65ED00BD51B0 /* MediaRemote.framework */; };
B1B1128F2C6A56E800093D8F /* DynamicNotch.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1B1128E2C6A56E800093D8F /* DynamicNotch.swift */; };
Expand Down Expand Up @@ -191,6 +193,7 @@
B17C3C242C7DAD0C0082390A /* OSD.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OSD.framework; path = ../../../../../System/Library/PrivateFrameworks/OSD.framework; sourceTree = "<group>"; };
B186543B2C6F49AE000B926A /* ShortcutConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutConstants.swift; sourceTree = "<group>"; };
B19016232CC15B4D00E3F12E /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
B19424082CD0FEFE003E5DC2 /* LottieAnimationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LottieAnimationView.swift; sourceTree = "<group>"; };
B1A78C812C8BA08100BD51B0 /* FullscreenMediaDetection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullscreenMediaDetection.swift; sourceTree = "<group>"; };
B1A78C832C8C65ED00BD51B0 /* MediaRemote.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaRemote.framework; path = ../../../../../System/Library/PrivateFrameworks/MediaRemote.framework; sourceTree = "<group>"; };
B1B1128E2C6A56E800093D8F /* DynamicNotch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicNotch.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -220,6 +223,7 @@
9A987A102C73CA8D005CA465 /* Collections in Frameworks */,
1485442F2C8F049C00943381 /* TheBoringWorkerNotifier in Frameworks */,
14D0321D2C68F3350096E6A1 /* Sparkle in Frameworks */,
B194240B2CD10017003E5DC2 /* LottieUI in Frameworks */,
14D0321A2C68F32E0096E6A1 /* LaunchAtLogin in Frameworks */,
B1A78C842C8C65ED00BD51B0 /* MediaRemote.framework in Frameworks */,
B18654392C6F4990000B926A /* KeyboardShortcuts in Frameworks */,
Expand Down Expand Up @@ -482,6 +486,7 @@
B186542E2C6F453B000B926A /* Music */ = {
isa = PBXGroup;
children = (
B19424082CD0FEFE003E5DC2 /* LottieAnimationView.swift */,
147163972C5D35B70068B555 /* MusicVisualizer.swift */,
);
path = Music;
Expand Down Expand Up @@ -570,6 +575,7 @@
1485442E2C8F049C00943381 /* TheBoringWorkerNotifier */,
B19016212CC15B3D00E3F12E /* Defaults */,
B1628B912CC260C0003D8DF3 /* SwiftUIIntrospect */,
B194240A2CD10017003E5DC2 /* LottieUI */,
);
productName = dynamicNotch;
productReference = 14CEF4122C5CAED300855D72 /* boringNotch.app */;
Expand Down Expand Up @@ -609,6 +615,7 @@
1485442D2C8F049C00943381 /* XCRemoteSwiftPackageReference "TheBoringWorkerNotifier" */,
B19016202CC15B3D00E3F12E /* XCRemoteSwiftPackageReference "Defaults" */,
B1628B902CC260C0003D8DF3 /* XCRemoteSwiftPackageReference "swiftui-introspect" */,
B19424072CD0DB52003E5DC2 /* XCRemoteSwiftPackageReference "LottieUI" */,
);
productRefGroup = 14CEF4132C5CAED300855D72 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -651,6 +658,7 @@
B141C23F2CA5F51E00AC8CC8 /* ProOnboarding.swift in Sources */,
B141C2412CA5F53F00AC8CC8 /* SparkleView.swift in Sources */,
14D570B92C5E98A20011E668 /* drop.swift in Sources */,
B19424092CD0FF01003E5DC2 /* LottieAnimationView.swift in Sources */,
9A987A072C73CA66005CA465 /* Ext+NSImage.swift in Sources */,
B1C974342C642B6D0000E707 /* MarqueeTextView.swift in Sources */,
9A987A052C73CA66005CA465 /* Ext+FileProvider.swift in Sources */,
Expand Down Expand Up @@ -1023,6 +1031,14 @@
kind = branch;
};
};
B19424072CD0DB52003E5DC2 /* XCRemoteSwiftPackageReference "LottieUI" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/jasudev/LottieUI.git";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -1061,6 +1077,11 @@
package = B19016202CC15B3D00E3F12E /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
B194240A2CD10017003E5DC2 /* LottieUI */ = {
isa = XCSwiftPackageProductDependency;
package = B19424072CD0DB52003E5DC2 /* XCRemoteSwiftPackageReference "LottieUI" */;
productName = LottieUI;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 14CEF40A2C5CAED200855D72 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "7cdc1f3bd18c54561dd174b285f645b3029f5a2147bf6d2ab4a408088e2a45e9",
"originHash" : "aae72b9079c2044604a3d1a8185d269560dd640056d837546f4c964ea61652f0",
"pins" : [
{
"identity" : "defaults",
Expand Down Expand Up @@ -28,6 +28,24 @@
"revision" : "a04ec1c363be3627734f6dad757d82f5d4fa8fcc"
}
},
{
"identity" : "lottie-spm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-spm.git",
"state" : {
"branch" : "main",
"revision" : "b7f41dd0b33c61577a4f0c8dd3674e5933719da0"
}
},
{
"identity" : "lottieui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jasudev/LottieUI.git",
"state" : {
"branch" : "main",
"revision" : "0cd5b54a1c8467b19c01f56395aec179087b62e2"
}
},
{
"identity" : "pow",
"kind" : "remoteSourceControl",
Expand Down
28 changes: 18 additions & 10 deletions boringNotch/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ struct ContentView: View {

@Namespace var albumArtNamespace

@Default(.useMusicVisualizer) var useMusicVisualizer

var body: some View {
ZStack(alignment: .top) {
NotchLayout()
.padding(.horizontal, vm.notchState == .open ? Defaults[.cornerRadiusScaling] ? (vm.sizes.cornerRadius.opened.inset! - 5) : (vm.sizes.cornerRadius.closed.inset! - 5) : 12)
.padding(.horizontal, vm.notchState == .open ? Defaults[.cornerRadiusScaling] ? (vm.sizes.cornerRadius.opened.inset!) : (vm.sizes.cornerRadius.closed.inset! - 5) : 12)
.padding([.horizontal, .bottom], vm.notchState == .open ? 12 : 0)
.frame(maxWidth: (((musicManager.isPlaying || !musicManager.isPlayerIdle) && vm.notchState == .closed && vm.showMusicLiveActivityOnClosed) || (vm.expandingView.show && (vm.expandingView.type == .battery)) || Defaults[.inlineHUD]) ? nil : vm.notchSize.width + ((hoverAnimation || (vm.notchState == .closed)) ? 20 : 0) + gestureProgress, maxHeight: ((vm.sneakPeek.show && vm.sneakPeek.type != .music) || (vm.sneakPeek.show && vm.sneakPeek.type == .music && vm.notchState == .closed)) ? nil : vm.notchSize.height + (hoverAnimation ? 8 : 0) + gestureProgress / 3, alignment: .top)
.background(.black)
Expand Down Expand Up @@ -234,7 +236,7 @@ struct ContentView: View {
HStack(alignment: .center) {
Image(systemName: "music.note")
GeometryReader { geo in
MarqueeText(musicManager.songTitle + " - " + musicManager.artistName, textColor: .gray, minDuration: 1, frameWidth: geo.size.width)
MarqueeText(.constant(musicManager.songTitle + " - " + musicManager.artistName), textColor: .gray, minDuration: 1, frameWidth: geo.size.width)
}
}
.foregroundStyle(.gray)
Expand Down Expand Up @@ -263,6 +265,7 @@ struct ContentView: View {
.zIndex(1)
.allowsHitTesting(vm.notchState == .open)
.blur(radius: abs(gestureProgress) > 0.3 ? min(abs(gestureProgress), 8) : 0)
.opacity(abs(gestureProgress) > 0.3 ? min(abs(gestureProgress * 2), 0.8) : 1)
}
}

Expand All @@ -289,14 +292,19 @@ struct ContentView: View {
.frame(width: Sizes().size.closed.width! - 20)

HStack {
Rectangle()
.fill(Defaults[.coloredSpectrogram] ? Color(nsColor: musicManager.avgColor).gradient : Color.gray.gradient)
.mask {
AudioSpectrumView(
isPlaying: $musicManager.isPlaying
)
.frame(width: 16, height: 12)
}
if useMusicVisualizer {
Rectangle()
.fill(Defaults[.coloredSpectrogram] ? Color(nsColor: musicManager.avgColor).gradient : Color.gray.gradient)
.mask {
AudioSpectrumView(
isPlaying: $musicManager.isPlaying
)
.frame(width: 16, height: 12)
}
} else {
LottieAnimationView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
.frame(width: max(0, Sizes().size.closed.height! - (hoverAnimation ? 0 : 12) + gestureProgress / 2),
height: max(0,Sizes().size.closed.height! - (hoverAnimation ? 0 : 12)), alignment: .center)
Expand Down
45 changes: 36 additions & 9 deletions boringNotch/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
},
"• New feature 1" : {

},
"⚠️ Important" : {

},
"About" : {
"localizations" : {
Expand Down Expand Up @@ -72,9 +69,15 @@
},
"Activation" : {

},
"Add" : {

},
"Add manually" : {

},
"Add new visualizer" : {

},
"Additional features" : {

Expand Down Expand Up @@ -220,9 +223,15 @@
},
"Custom height" : {

},
"Custom music live activity animation" : {

},
"Custom notch size - %.0f" : {

},
"Custom vizualizers (Lottie)" : {

},
"Default" : {

Expand Down Expand Up @@ -386,12 +395,6 @@
},
"High" : {

},
"Hover over the notch after changing the height to see the effect." : {

},
"Hover over the notch after changing the screen to adapt the new size" : {

},
"HUD style" : {

Expand Down Expand Up @@ -424,6 +427,9 @@
},
"License key" : {

},
"Lottie JSON URL" : {

},
"Low" : {

Expand Down Expand Up @@ -508,9 +514,18 @@
},
"muted" : {

},
"Name" : {

},
"Need Restart" : {

},
"No custom animation available" : {

},
"No custom visualizer" : {

},
"No events today" : {

Expand Down Expand Up @@ -649,6 +664,12 @@
}
}
}
},
"selected" : {

},
"Selected animation" : {

},
"Settings" : {
"localizations" : {
Expand Down Expand Up @@ -728,6 +749,9 @@
}
}
}
},
"Speed" : {

},
"Square" : {

Expand Down Expand Up @@ -771,6 +795,9 @@
},
"Upgrade to Pro" : {

},
"Use music visualizer spectrogram" : {

},
"Version" : {
"localizations" : {
Expand Down
47 changes: 36 additions & 11 deletions boringNotch/components/Live activities/MarqueeTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct MeasureSizeModifier: ViewModifier {
}

struct MarqueeText: View {
let text: String
@Binding var text: String
let font: Font
let nsFont: NSFont.TextStyle
let textColor: Color
Expand All @@ -33,9 +33,10 @@ struct MarqueeText: View {

@State private var animate = false
@State private var textSize: CGSize = .zero
@State private var offset: CGFloat = 0

init(_ text: String, font: Font = .body, nsFont: NSFont.TextStyle = .body, textColor: Color = .primary, backgroundColor: Color = .clear, minDuration: Double = 3.0, frameWidth: CGFloat = 200) {
self.text = text
init(_ text: Binding<String>, font: Font = .body, nsFont: NSFont.TextStyle = .body, textColor: Color = .primary, backgroundColor: Color = .clear, minDuration: Double = 3.0, frameWidth: CGFloat = 200) {
_text = text
self.font = font
self.nsFont = nsFont
self.textColor = textColor
Expand All @@ -44,32 +45,56 @@ struct MarqueeText: View {
self.frameWidth = frameWidth
}

private var needsScrolling: Bool {
textSize.width > frameWidth
}

var body: some View {
GeometryReader { geometry in
ZStack(alignment: .leading) {
HStack(spacing: 20) {
Text(text)
Text(text)
.opacity((textSize.width > frameWidth) ? 1 : 0)
.opacity(needsScrolling ? 1 : 0)
}
.font(font)
.foregroundColor(textColor)
.fixedSize(horizontal: true, vertical: false)
.offset(x: animate ? -textSize.width - 10 : 0)
.offset(x: animate ? offset : 0)
.animation(
.linear(duration: Double(textSize.width / 30))
.delay(minDuration)
.repeatForever(autoreverses: false),
animate ?
.linear(duration: Double(textSize.width / 30))
.delay(minDuration)
.repeatForever(autoreverses: false) : .none,
value: animate
)
.background(backgroundColor)
.modifier(MeasureSizeModifier())
.onPreferenceChange(SizePreferenceKey.self) { size in
self.textSize = CGSize(width: size.width / 2, height: NSFont.preferredFont(forTextStyle: nsFont).pointSize)
if textSize.width > frameWidth {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
}
.onChange(of: text) {

offset = 0
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if needsScrolling {
offset = -(textSize.width + 10)
withAnimation {
animate = true
}
}
}
}
.onAppear {
withAnimation {
animate = false
}
offset = 0
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if needsScrolling {
offset = -(textSize.width + 10)
withAnimation {
self.animate = true
animate = true
}
}
}
Expand Down
Loading

0 comments on commit a6d0cca

Please sign in to comment.