mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 23:24:32 +00:00
72 lines
2.3 KiB
Swift
72 lines
2.3 KiB
Swift
/*
|
|
* Atoll (DynamicIsland)
|
|
* Copyright (C) 2024-2026 Atoll Contributors
|
|
*
|
|
* Originally from boring.notch project
|
|
* Modified and adapted for Atoll (DynamicIsland)
|
|
* See NOTICE for details.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import SwiftUI
|
|
|
|
extension Bundle {
|
|
var releaseVersionNumber: String? {
|
|
return infoDictionary?["CFBundleShortVersionString"] as? String
|
|
}
|
|
var buildVersionNumber: String? {
|
|
return infoDictionary?["CFBundleVersion"] as? String
|
|
}
|
|
var releaseVersionNumberPretty: String {
|
|
return "v\(releaseVersionNumber ?? "1.0.0")"
|
|
}
|
|
|
|
var iconFileName: String? {
|
|
guard let icons = infoDictionary?["CFBundleIcons"] as? [String: Any],
|
|
let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any],
|
|
let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String],
|
|
let iconFileName = iconFiles.last
|
|
else { return nil }
|
|
return iconFileName
|
|
}
|
|
}
|
|
|
|
struct BundleAppIcon: View {
|
|
var body: some View {
|
|
Bundle.main.iconFileName
|
|
.flatMap { NSImage(named: $0) }
|
|
.map { Image(nsImage: $0) }
|
|
}
|
|
}
|
|
|
|
func isNewVersion() -> Bool {
|
|
let defaults = UserDefaults.standard
|
|
let currentVersion = Bundle.main.releaseVersionNumber ?? "1.0"
|
|
let savedVersion = defaults.string(forKey: "LastVersionRun") ?? ""
|
|
|
|
if currentVersion != savedVersion {
|
|
defaults.set(currentVersion, forKey: "LastVersionRun")
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func isExtensionRunning(_ bundleID: String) -> Bool {
|
|
if let _ = NSWorkspace.shared.runningApplications.first(where: {$0.bundleIdentifier == bundleID}) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|