Skip to content

Commit

Permalink
Merge pull request #9 from barseghyanartur/dev
Browse files Browse the repository at this point in the history
Feature/chrome apps (#8)
  • Loading branch information
barseghyanartur authored Feb 3, 2024
2 parents c7185d8 + f9212f9 commit 6504190
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
68 changes: 60 additions & 8 deletions ApplicationMenu/ApplicationMenuApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ struct DirectoryAccessView: View {
}
}

struct ChromeAppsSettingsView: View {
@AppStorage("showChromeApps") private var showChromeApps: Bool = false

var body: some View {
Form {
Toggle("Show Chrome Apps", isOn: $showChromeApps)
}
.padding()
.frame(width: 300, height: 100)
}
}

struct SettingsView: View {
@State private var selectedOption: Int = UserDefaults.standard.integer(forKey: "menuBarOption")
@Environment(\.presentationMode) var presentationMode
Expand All @@ -148,6 +160,10 @@ struct SettingsView: View {
.tabItem {
Label("Directory Access", systemImage: "folder")
}
ChromeAppsSettingsView()
.tabItem {
Label("Chrome Apps", systemImage: "folder")
}
}
.padding()

Expand Down Expand Up @@ -195,8 +211,11 @@ struct AboutView: View {
struct CreditsView: View {
var body: some View {
ScrollView {
Text("The application icon has been taken from the amazing `tabler icons` (MIT licensed).")
.padding()
Text("""
The application icon has been taken from the amazing
[tabler icons](https://github.com/tabler/tabler-icons) (MIT licensed).
""")
.padding()
}
}
}
Expand All @@ -207,9 +226,7 @@ struct LicenseView: View {
Text("""
MIT License
Copyright (c) 2024 Artur Barseghyan
https://github.com/barseghyanartur/app-menu/
Copyright (c) 2024 [Artur Barseghyan](https://github.com/barseghyanartur/app-menu/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -328,16 +345,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let fileManager = FileManager.default
// let homeDirectory = FileManager.default.homeDirectoryForCurrentUser.path
// let userApplicationsDir = homeDirectory + "/Applications"
let userApplicationsDir = URL.userHome.path + "/Applications"
let chromeApplicationsDir = userApplicationsDir + "/Chrome Apps.localized"
let userAppsDir = URL.userHome.path + "/Applications"
let chromeAppsDir = userAppsDir + "/Chrome Apps.localized"

let appDirectories = ["/Applications", "/System/Applications", userApplicationsDir]
let appDirectories = ["/Applications", "/System/Applications", userAppsDir]

// TODO: If needed, add Chrome Apps here

print("appDirectories: \(appDirectories)") // Debug log
var appGroups = [String: [(String, NSImage?, String)]]() // Store the full path
var allApps = [(String, NSImage?, String)]() // Array to hold all apps
var chromeApps = [(String, NSImage?, String)]() // Array to hold chrome apps

for appDir in appDirectories {
do {
Expand All @@ -356,6 +374,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

do {
let appContents = try fileManager.contentsOfDirectory(atPath: chromeAppsDir)
for appName in appContents where appName.hasSuffix(".app") {
let appPath = chromeAppsDir + "/" + appName
print("Checking app at path: \(appPath)") // Debug log
let (category, appName, icon) = fetchAppDetails(atPath: appPath)
let humanReadableCategory = makeHumanReadable(category)
chromeApps.append((appName, icon, appPath)) // Store full path here
}
} catch {
print("Error reading applications directory (\(chromeAppsDir)): \(error)")
}

// Add 'All' category
// appGroups["All"] = allApps

Expand All @@ -375,6 +406,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
groupMenuItem.submenu = groupMenu
menu?.addItem(groupMenuItem)
}

// Chrome apps
let showChromeApps = UserDefaults.standard.bool(forKey: "showChromeApps")
if showChromeApps {
// Add a separator line
menu?.addItem(NSMenuItem.separator())

let chromeGroupMenu = NSMenu()
for (appName, icon, fullPath) in chromeApps.sorted(by: { $0.0 < $1.0 }) {
let menuItem = NSMenuItem(title: appName, action: #selector(openApp(_:)), keyEquivalent: "")
menuItem.target = self
if let iconImage = icon {
menuItem.image = resizeImage(image: iconImage, w: 20, h: 20)
}
menuItem.representedObject = fullPath // Use the stored full path
chromeGroupMenu.addItem(menuItem)
}
let chromeGroupMenuItem = NSMenuItem(title: "Chrome Apps", action: nil, keyEquivalent: "")
chromeGroupMenuItem.submenu = chromeGroupMenu
menu?.addItem(chromeGroupMenuItem)
}

// Add a separator line
menu?.addItem(NSMenuItem.separator())
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Release history and notes
=========================

`Sequence based identifiers
<http://en.wikipedia.org/wiki/Software_versioning#Sequence-based_identifiers>`_
are used for versioning (schema follows below):

.. code-block:: text
major.minor[.revision]
- It's always safe to upgrade within the same minor version (for example, from
0.3 to 0.3.4).
- Minor version changes might be backwards incompatible. Read the
release notes carefully before upgrading (for example, when upgrading from
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.1.1
-----
2024-02-03

- Add Chrome Apps.

0.1
---
2024-01-31

- Initial beta release.

0 comments on commit 6504190

Please sign in to comment.