Restored files from old Mac, force pushing

This commit is contained in:
Hariharan Mudaliar 2025-07-13 20:26:03 +05:30
commit 5040381840
126 changed files with 10431 additions and 67 deletions

View file

@ -0,0 +1,67 @@
//
// AppIcons.swift
// boringNotch
//
// Created by Harsh Vardhan Goswami on 16/08/24.
//
import SwiftUI
import AppKit
struct AppIcons {
func getIcon(file path: String) -> NSImage? {
guard FileManager.default.fileExists(atPath: path)
else { return nil }
return NSWorkspace.shared.icon(forFile: path)
}
func getIcon(bundleID: String) -> NSImage? {
guard let path = NSWorkspace.shared.urlForApplication(
withBundleIdentifier: bundleID
)?.absoluteString
else { return nil }
return getIcon(file: path)
}
func getIcon(application: String) -> NSImage? {
guard let path = NSWorkspace.shared.fullPath(forApplication: application)
else { return nil }
return getIcon(file: path)
}
/// Easily read Info.plist as a Dictionary from any bundle by accessing .infoDictionary on Bundle
func bundle(forBundleID: String) -> Bundle? {
guard let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: forBundleID)
else { return nil }
return Bundle(url: url)
}
}
func AppIcon(for bundleID: String) -> Image {
let workspace = NSWorkspace.shared
if let appURL = workspace.urlForApplication(withBundleIdentifier: bundleID) {
let appIcon = workspace.icon(forFile: appURL.path)
return Image(nsImage: appIcon)
}
return Image(nsImage: workspace.icon(for: .applicationBundle))
}
func AppIconAsNSImage(for bundleID: String) -> NSImage? {
let workspace = NSWorkspace.shared
if let appURL = workspace.urlForApplication(withBundleIdentifier: bundleID) {
let appIcon = workspace.icon(forFile: appURL.path)
return appIcon
}
return nil
}

View file

@ -0,0 +1,31 @@
//
// AppleScriptHelper.swift
// boringNotch
//
// Created by Alexander Greco on 2025-03-29.
//
import Foundation
class AppleScriptHelper {
@discardableResult
class func execute(_ scriptText: String) async throws -> NSAppleEventDescriptor? {
try await withCheckedThrowingContinuation { continuation in
Task.detached(priority: .userInitiated) {
let script = NSAppleScript(source: scriptText)
var error: NSDictionary?
if let descriptor = script?.executeAndReturnError(&error) {
continuation.resume(returning: descriptor)
} else if let error = error {
continuation.resume(throwing: NSError(domain: "AppleScriptError", code: 1, userInfo: error as? [String: Any]))
} else {
continuation.resume(throwing: NSError(domain: "AppleScriptError", code: 1, userInfo: [NSLocalizedDescriptionKey: "Unknown error"]))
}
}
}
}
class func executeVoid(_ scriptText: String) async throws {
_ = try await execute(scriptText)
}
}

View file

@ -0,0 +1,15 @@
//
// AudioPlayer.swift
// boringNotch
//
// Created by Harsh Vardhan Goswami on 09/08/24.
//
import Foundation
import AppKit
class AudioPlayer {
func play(fileName: String, fileExtension: String) {
NSSound(contentsOf:Bundle.main.url(forResource: fileName, withExtension: fileExtension)!, byReference: false)?.play()
}
}

View file

@ -0,0 +1,25 @@
import AppKit
func getAttributedString(content: Any, type: NSPasteboard.PasteboardType) -> NSAttributedString? {
if let stringContent = content as? String {
return NSAttributedString(string: stringContent)
}
if type == .rtf, let data = content as? Data {
return NSAttributedString(rtf: data, documentAttributes: nil)
} else if type == .html, let data = content as? Data {
return try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
} else if type.rawValue == "public.utf8-plain-text", let data = content as? Data {
return try? NSAttributedString(data: data, documentAttributes: nil)
} else if type == .string {
return NSAttributedString(string: content as? String ?? "")
} else if type == .fileURL {
return NSAttributedString(string: content as? String ?? "")
} else if type == NSPasteboard.PasteboardType("com.apple.webarchive"), let data = content as? Data {
return try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.webArchive], documentAttributes: nil)
}
return nil
}
func isText(type: NSPasteboard.PasteboardType) -> Bool {
return type == .string || type == .html || type == .rtf || type == .html || type == .string || type.rawValue == "public.utf8-plain-text" || type.rawValue == "public.utf16-external-plain-text" || type.rawValue == "com.apple.webarchive"
}