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

Draft PR #224

Merged
merged 22 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b9616dc
Placeholder provided by media player
overflow-sudo Nov 3, 2024
07c540c
rewrite logic for detirmining when to change album art and when to us…
Alexander5015 Nov 5, 2024
ee9a937
Hide mini app icon when app icon is being used for artwork
Alexander5015 Nov 5, 2024
f8feb8a
Use the isPlaying function rather than guessing based on playback rat…
Alexander5015 Nov 7, 2024
db082e7
adjust states inside thread for new playing detection
Alexander5015 Nov 7, 2024
67184f6
Update bundle identifier logic for more accurate icon
Alexander5015 Nov 7, 2024
b56f9d6
allow timeline to update while paused, for the case when the back ski…
Alexander5015 Nov 7, 2024
cb02d44
More fixes
Alexander5015 Nov 7, 2024
d7b64c6
modify screen lock monitoring
Alexander5015 Nov 18, 2024
a2db151
temporary fix for repositioning problems
Alexander5015 Nov 18, 2024
1cb0152
Changed selectedScreen to preferredScreen and added a seperate select…
Alexander5015 Nov 18, 2024
77ed09c
Add a Default Key and settings for show on all displays
Alexander5015 Nov 18, 2024
d6b8825
Add all displays as a beta feature
Alexander5015 Nov 19, 2024
fb0454f
Dynamically change settings views based on preferences and fix deprec…
Alexander5015 Nov 17, 2024
f080019
Better sneak peek logic for song change and ignoring empty entries
Alexander5015 Nov 20, 2024
da41032
update timeline slider logic for better behaviour when paused
Alexander5015 Nov 20, 2024
b1417f0
Refactor the code by transferring certain elements from BoringViewMod…
Alexander5015 Nov 21, 2024
dd0189a
Use new BoringView Coordinator, refactor matters.swift and sizes, and…
Alexander5015 Nov 21, 2024
a64982d
Move BoringViewCoordinator into folder
Alexander5015 Nov 21, 2024
f15cbb0
Add the option to customize the size of the notch window on notched s…
Alexander5015 Nov 21, 2024
f993014
settings resize changes
Alexander5015 Nov 21, 2024
6c1580b
add opactity and blur to NotchHomeView
Alexander5015 Nov 21, 2024
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
4 changes: 4 additions & 0 deletions boringNotch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
112FB7352CCF16F70015238C /* NotchSpaceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112FB7342CCF16F70015238C /* NotchSpaceManager.swift */; };
11CC44A22CEE614100C7244B /* BoringViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11CC44A12CEE614100C7244B /* BoringViewCoordinator.swift */; };
14288DDC2C6E015000B9F80C /* AudioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14288DD62C6E015000B9F80C /* AudioPlayer.swift */; };
14288DE82C6E01C800B9F80C /* ProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14288DE72C6E01C800B9F80C /* ProgressIndicator.swift */; };
14288DFE2C6E9A4700B9F80C /* BoringSystemTiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14288DFD2C6E9A4700B9F80C /* BoringSystemTiles.swift */; };
Expand Down Expand Up @@ -113,6 +114,7 @@

/* Begin PBXFileReference section */
112FB7342CCF16F70015238C /* NotchSpaceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotchSpaceManager.swift; sourceTree = "<group>"; };
11CC44A12CEE614100C7244B /* BoringViewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoringViewCoordinator.swift; sourceTree = "<group>"; };
14288DD62C6E015000B9F80C /* AudioPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = "<group>"; };
14288DD72C6E015000B9F80C /* boringNotch-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "boringNotch-Bridging-Header.h"; sourceTree = "<group>"; };
14288DE72C6E01C800B9F80C /* ProgressIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressIndicator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -364,6 +366,7 @@
14CEF41E2C5CAED400855D72 /* boringNotch.entitlements */,
14CEF41B2C5CAED400855D72 /* Preview Content */,
112FB72F2CCF12CC0015238C /* private */,
11CC44A12CEE614100C7244B /* BoringViewCoordinator.swift */,
);
path = boringNotch;
sourceTree = "<group>";
Expand Down Expand Up @@ -647,6 +650,7 @@
files = (
14C08BB92C8DE4B1000F8AA0 /* BoringCalendar.swift in Sources */,
147163982C5D35B70068B555 /* MusicVisualizer.swift in Sources */,
11CC44A22CEE614100C7244B /* BoringViewCoordinator.swift in Sources */,
B186543C2C6F49AE000B926A /* ShortcutConstants.swift in Sources */,
B1D365CE2C6A979C0047BDBC /* LiveActivityModifier.swift in Sources */,
14D570C02C5EA5870011E668 /* AnimatedFace.swift in Sources */,
Expand Down
167 changes: 167 additions & 0 deletions boringNotch/BoringViewCoordinator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
//
// BoringViewCoordinator.swift
// boringNotch
//
// Created by Alexander on 2024-11-20.
//

import Combine
import SwiftUI
import TheBoringWorkerNotifier
import Defaults

enum SneakContentType {
case brightness
case volume
case backlight
case music
case mic
case battery
case download
}

struct sneakPeek {
var show: Bool = false
var type: SneakContentType = .music
var value: CGFloat = 0
var icon: String = ""
}

struct SharedSneakPeek: Codable {
var show: Bool
var type: String
var value: String
var icon: String
}

class BoringViewCoordinator: ObservableObject {
static let shared = BoringViewCoordinator()
var notifier: TheBoringWorkerNotifier = .init()

@Published var currentView: NotchViews = .home
private var sneakPeekDispatch: DispatchWorkItem?

@AppStorage("firstLaunch") var firstLaunch: Bool = true
@AppStorage("showWhatsNew") var showWhatsNew: Bool = true
@AppStorage("musicLiveActivity") var showMusicLiveActivityOnClosed: Bool = true
@AppStorage("currentMicStatus") var currentMicStatus: Bool = true

@AppStorage("alwaysShowTabs") var alwaysShowTabs: Bool = true {
didSet {
if !alwaysShowTabs {
openLastTabByDefault = false
if TrayDrop.shared.isEmpty || !Defaults[.openShelfByDefault] {
currentView = .home
}
}
}
}

@AppStorage("openLastTabByDefault") var openLastTabByDefault: Bool = false {
didSet {
if openLastTabByDefault {
alwaysShowTabs = true
}
}
}

@AppStorage("hudReplacement") var hudReplacement: Bool = true {
didSet {
notifier.postNotification(name: notifier.toggleHudReplacementNotification.name, userInfo: nil)
}
}

@AppStorage("preferred_screen_name") var preferredScreen = NSScreen.main?.localizedName ?? "Unknown" {
didSet {
selectedScreen = preferredScreen
NotificationCenter.default.post(name: Notification.Name.selectedScreenChanged, object: nil)
}
}

@Published var selectedScreen: String = NSScreen.main?.localizedName ?? "Unknown"

@Published var optionKeyPressed: Bool = true

private init() {
self.selectedScreen = preferredScreen
notifier = TheBoringWorkerNotifier()
}

func setupWorkersNotificationObservers() {
notifier.setupObserver(notification: notifier.micStatusNotification, handler: initialMicStatus)
notifier.setupObserver(notification: notifier.sneakPeakNotification, handler: sneakPeekEvent)
}

@objc func sneakPeekEvent(_ notification: Notification) {
let decoder = JSONDecoder()
if let decodedData = try? decoder.decode(SharedSneakPeek.self, from: notification.userInfo?.first?.value as! Data) {
let contentType = decodedData.type == "brightness" ? SneakContentType.brightness : decodedData.type == "volume" ? SneakContentType.volume : decodedData.type == "backlight" ? SneakContentType.backlight : decodedData.type == "mic" ? SneakContentType.mic : SneakContentType.brightness

let value = CGFloat((NumberFormatter().number(from: decodedData.value) ?? 0.0).floatValue)
let icon = decodedData.icon

print(decodedData)

toggleSneakPeek(status: decodedData.show, type: contentType, value: value, icon: icon)

} else {
print("Failed to decode JSON data")
}
}

func toggleSneakPeek(status: Bool, type: SneakContentType, duration: TimeInterval = 1.5, value: CGFloat = 0, icon: String = "") {
self.sneakPeekDuration = duration
if type != .music {
//close()
if !hudReplacement {
return
}
}
DispatchQueue.main.async {
withAnimation(.smooth) {
self.sneakPeek.show = status
self.sneakPeek.type = type
self.sneakPeek.value = value
self.sneakPeek.icon = icon
}
}

if type == .mic {
currentMicStatus = value == 1
}
}

private var sneakPeekDuration: TimeInterval = 1.5
@Published var sneakPeek: sneakPeek = .init() {
didSet {
if sneakPeek.show {
sneakPeekDispatch?.cancel()

sneakPeekDispatch = DispatchWorkItem { [weak self] in
guard let self = self else { return }
withAnimation {
self.toggleSneakPeek(status: false, type: SneakContentType.music)
self.sneakPeekDuration = 1.5
}
}
DispatchQueue.main
.asyncAfter(
deadline: .now() + self.sneakPeekDuration,
execute: sneakPeekDispatch!
)
}
}
}

@objc func initialMicStatus(_ notification: Notification) {
currentMicStatus = notification.userInfo?.first?.value as! Bool
}

func toggleMic() {
notifier.postNotification(name: notifier.toggleMicNotification.name, userInfo: nil)
}

func showEmpty() {
currentView = .home
}
}
Loading