Skip to content

Commit

Permalink
Merge pull request #12 from iamharshdev/humans
Browse files Browse the repository at this point in the history
Humans
  • Loading branch information
theboringhumane authored Aug 6, 2024
2 parents a039d50 + 36df914 commit 7e85d5e
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 25 deletions.
8 changes: 6 additions & 2 deletions boringNotch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
147163982C5D35B70068B555 /* MusicVisualizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147163972C5D35B70068B555 /* MusicVisualizer.swift */; };
1471639A2C5D35FF0068B555 /* MusicManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 147163992C5D35FF0068B555 /* MusicManager.swift */; };
1471639F2C5D368B0068B555 /* BoringNotch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1471639E2C5D368B0068B555 /* BoringNotch.swift */; };
1471A8592C6281BD0058408D /* BoringNotchWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1471A8582C6281BD0058408D /* BoringNotchWindow.swift */; };
14CEF4162C5CAED300855D72 /* boringNotchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14CEF4152C5CAED300855D72 /* boringNotchApp.swift */; };
14CEF4182C5CAED300855D72 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14CEF4172C5CAED300855D72 /* ContentView.swift */; };
14CEF41A2C5CAED400855D72 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14CEF4192C5CAED400855D72 /* Assets.xcassets */; };
Expand All @@ -36,6 +37,7 @@
147163972C5D35B70068B555 /* MusicVisualizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicVisualizer.swift; sourceTree = "<group>"; };
147163992C5D35FF0068B555 /* MusicManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicManager.swift; sourceTree = "<group>"; };
1471639E2C5D368B0068B555 /* BoringNotch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoringNotch.swift; sourceTree = "<group>"; };
1471A8582C6281BD0058408D /* BoringNotchWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoringNotchWindow.swift; sourceTree = "<group>"; };
14CEF4122C5CAED300855D72 /* boringNotch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = boringNotch.app; sourceTree = BUILT_PRODUCTS_DIR; };
14CEF4152C5CAED300855D72 /* boringNotchApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = boringNotchApp.swift; sourceTree = "<group>"; };
14CEF4172C5CAED300855D72 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +90,7 @@
14D570C52C5F38210011E668 /* BoringHeader.swift */,
14D570CC2C5F4BB70011E668 /* BoringBattery.swift */,
14D570D12C5F6C6A0011E668 /* BoringExtrasMenu.swift */,
1471A8582C6281BD0058408D /* BoringNotchWindow.swift */,
);
path = components;
sourceTree = "<group>";
Expand Down Expand Up @@ -265,6 +268,7 @@
14D570CD2C5F4BB70011E668 /* BoringBattery.swift in Sources */,
1443E7F32C609DCE0027C1FC /* matters.swift in Sources */,
14D570D52C5F710B0011E668 /* constants.swift in Sources */,
1471A8592C6281BD0058408D /* BoringNotchWindow.swift in Sources */,
1471639F2C5D368B0068B555 /* BoringNotch.swift in Sources */,
14CEF4182C5CAED300855D72 /* ContentView.swift in Sources */,
14D570B62C5E961A0011E668 /* NotchShape.swift in Sources */,
Expand Down Expand Up @@ -422,7 +426,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.2;
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.4;
PRODUCT_BUNDLE_IDENTIFIER = electronlabsdev.boringNotch;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -457,7 +461,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.2;
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.4;
PRODUCT_BUNDLE_IDENTIFIER = electronlabsdev.boringNotch;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
57 changes: 37 additions & 20 deletions boringNotch/boringNotchApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {


func applicationDidFinishLaunching(_ notification: Notification) {

// Create the status bar item
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

Expand All @@ -43,27 +44,39 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem?.menu = menu


// Create the window content
let contentView = ContentView(onHover: adjustWindowPosition, vm: .init(), batteryModel: .init())
NotificationCenter.default.addObserver(
self,
selector: #selector(adjustWindowPosition),
name: NSApplication.didChangeScreenParametersNotification,
object: nil
)


window = BoringNotchWindow(
contentRect: NSRect(x: 0, y: 0, width: sizing.size.opened.width!, height: sizing.size.opened.height!), styleMask: [.borderless], backing: .buffered, defer: false
)

// Initialize the window
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: sizing.size.opened.width!, height: sizing.size.opened.height!),
styleMask: [.borderless],
backing: .buffered, defer: false)
window.isOpaque = false
window.backgroundColor = .clear
window.level = .statusBar
window.isReleasedWhenClosed = false
window.contentView = NSHostingView(rootView: contentView)
window.contentView = NSHostingView(rootView: ContentView(onHover: adjustWindowPosition, vm: .init(), batteryModel: .init()))

// Set the initial window position
adjustWindowPosition()

window.orderFrontRegardless()
}

func adjustWindowPosition() {
func deviceHasNotch() -> Bool {
if #available(macOS 12.0, *) {
for screen in NSScreen.screens {
if screen.safeAreaInsets.top > 0 {
return true
}
}
}
return false
}


@objc func adjustWindowPosition() {
if let screenFrame = NSScreen.main?.frame {
let windowWidth = window.frame.width
let windowHeight = window.frame.height
Expand All @@ -76,13 +89,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

@objc func quitAction() {
NSApplication.shared.terminate(nil)
}

@objc func showMenu() {
statusItem?.menu?.popUp(positioning: nil, at: NSEvent.mouseLocation, in: nil)
}

@objc func togglePopover(_ sender: Any?) {
if window.isVisible {
Expand All @@ -91,4 +97,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
window.orderFrontRegardless()
}
}

@objc func showMenu() {
statusItem!.menu?.popUp(positioning: nil, at: NSEvent.mouseLocation, in: nil)
}

@objc func quitAction() {
NSApplication.shared.terminate(nil)
}



}
2 changes: 1 addition & 1 deletion boringNotch/components/BoringBattery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ struct BoringBatteryView: View {
}

#Preview {
BatteryView(percentage: 100, isCharging: true).frame(width: 100)
BatteryView(percentage: 70, isCharging: true).frame(width: 100)
}
9 changes: 8 additions & 1 deletion boringNotch/components/BoringNotch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ struct BoringNotch: View {
}
if (musicManager.isPlaying || musicManager.lastUpdated.timeIntervalSinceNow > -vm.waitInterval) && (!batteryModel.showChargingInfo || vm.notchState == .open) && vm.currentView != .menu {

Image(nsImage: musicManager.albumArt).frame(width: vm.notchState == .open ? vm.musicPlayerSizes.image.size.opened.width: vm.musicPlayerSizes.image.size.closed.width, height:vm.notchState == .open ?vm.musicPlayerSizes.image.size.opened.height: vm.musicPlayerSizes.image.size.closed.height).cornerRadius(vm.notchState == .open ? vm.musicPlayerSizes.image.corderRadius.opened.inset! : vm.musicPlayerSizes.image.corderRadius.closed.inset!)
Image(nsImage: musicManager.albumArt)
.resizable()
.aspectRatio(contentMode: .fill).frame(
width: vm.notchState == .open ? vm.musicPlayerSizes.image.size.opened.width : vm.musicPlayerSizes.image.size.closed.width,
height: vm.notchState == .open ? vm.musicPlayerSizes.image.size.opened.height : vm.musicPlayerSizes.image.size.closed.height
)
.cornerRadius(vm.notchState == .open ? vm.musicPlayerSizes.image.corderRadius.opened.inset! : vm.musicPlayerSizes.image.corderRadius.closed.inset!)
.scaledToFit()
// Fit the image within the frame
}

Expand Down
48 changes: 48 additions & 0 deletions boringNotch/components/BoringNotchWindow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// BoringNotchWindow.swift
// boringNotch
//
// Created by Harsh Vardhan Goswami on 06/08/24.
//

import Cocoa

class BoringNotchWindow: NSWindow {
override init(
contentRect: NSRect,
styleMask: NSWindow.StyleMask,
backing: NSWindow.BackingStoreType,
defer flag: Bool
) {
super.init(
contentRect: contentRect,
styleMask: styleMask,
backing: backing,
defer: flag
)

isOpaque = false
alphaValue = 1
titleVisibility = .hidden
titlebarAppearsTransparent = true
backgroundColor = .clear
isMovable = false
collectionBehavior = [
.fullScreenAuxiliary,
.stationary,
.canJoinAllSpaces,
.ignoresCycle,
]
isReleasedWhenClosed = false
level = .statusBar
hasShadow = true
}

override var canBecomeKey: Bool {
true
}

override var canBecomeMain: Bool {
true
}
}
1 change: 0 additions & 1 deletion boringNotch/managers/MusicManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class MusicManager: ObservableObject {
self.isPlaying = state == 1
playbackManager.isPlaying = state == 1


}

// check if the song is same as the previous one
Expand Down
24 changes: 24 additions & 0 deletions boringNotch/menu/StatusBarMenu.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Cocoa

class BoringStatusMenu: NSMenu {

var statusItem: NSStatusItem!

override init() {
super.init()

// Initialize the status item
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

if let button = statusItem.button {
button.image = NSImage(systemSymbolName: "music.note", accessibilityDescription: "BoringNotch")
button.action = #selector(showMenu)
}

// Set up the menu
let menu = NSMenu()
menu.addItem(NSMenuItem(title: "Quit", action: #selector(quitAction), keyEquivalent: "q"))
statusItem.menu = menu
}

}
96 changes: 96 additions & 0 deletions boringNotch/observers/SystemDownloadObserver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Foundation
import Combine
import SwiftUI

struct DownloadEvent: Identifiable {
let id = UUID()
let path: String
let eventFlags: FSEventStreamEventFlags
let eventID: FSEventStreamEventId
let timestamp: Date
var progress: Double = 0.0
}

class ObservingClass: NSObject, ObservableObject, NSFilePresenter {
var presentedItemURL: URL?
var snapshotPath: String?

lazy var presentedItemOperationQueue: OperationQueue = .main
@Published var recentFiles: [String] = []

override init() {
super.init()
self.presentedItemURL = URL(fileURLWithPath: NSHomeDirectory() + "/Downloads")
print(NSHomeDirectory())
// Set the URL to the Downloads folder
if let downloadsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first {
self.presentedItemURL = downloadsURL
NSFileCoordinator.addFilePresenter(self)
}
}

deinit {
NSFileCoordinator.removeFilePresenter(self)
}

private func presentedSubitemDidChangeAtURL(url: NSURL) {
refreshFiles()
}

func presentedItemDidChange() {
refreshFiles()
}

func refreshFiles() {
print("refreshFiles")
guard let path = snapshotPath else { return }

var isDirectory: ObjCBool = false

if FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory), isDirectory.boolValue {
do {
let list = try FileManager.default.contentsOfDirectory(atPath: path)
DispatchQueue.main.async {
self.recentFiles = list
}
} catch {
// Error handling
print("Error reading contents of directory: \(error)")
}
}
}
}


struct DownloadView: View {
@StateObject private var observingClass = ObservingClass()

var body: some View {
VStack {
Text("Monitoring User Folder")
.font(.headline)

VStack {
Text("Monitoring User Downloads Folder")
.font(.headline)

List(observingClass.recentFiles, id: \.self) { file in
Text(file)
}
}
.padding()
.onAppear {
print("sOME SHIT IS HAPPENING HERE")
// Set the snapshot path to the desired directory i want to monitor downloads folder
observingClass.snapshotPath = observingClass.presentedItemURL?.path
observingClass.refreshFiles()
}
}
.padding()
}
}


#Preview {
DownloadView()
}

0 comments on commit 7e85d5e

Please sign in to comment.