-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from iamharshdev/humans
Humans
- Loading branch information
Showing
8 changed files
with
220 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |