TheAcharya / MarkerData

The avant-garde Marker extraction application crafted for Final Cut Pro
https://markerdata.theacharya.co
MIT License
22 stars 1 forks source link

When `minimise` the app menu items are not working #98

Closed IAmVigneswaran closed 1 month ago

IAmVigneswaran commented 1 month ago

@milanvarady

Thanks for fixing #97!

Now, when I trying to minimise (Yellow Button) the app, CMD+M, most of the app menu items are not working.

Especially, those under Marker Data,File, Configurations .

Technically, when a macOS app is minimise the app menu should be functional.

milanvarady commented 1 month ago

I don't exactly understand. While the app is minimized, I can still set the configuration, check for updates, open the cache folder, etc. Can you explain the problem in more detail?

IAmVigneswaran commented 1 month ago

@milanvarady

Can you explain the problem in more detail?

https://github.com/TheAcharya/MarkerData/assets/118706051/8b08543b-e1aa-437b-b7ee-492d664dfbff

  1. In this video, you can see that when minimise, when I click on the app menu items, it does not invoke the Marker Data back.
  2. As an example, with Keka App, even after minimise, when I click on the About Keka, the window pops back up.
milanvarady commented 1 month ago

I see what you mean. Those don't do anything because they open things inside the app, which is not visible when minimized. The About panel is a separate window in most apps (such as Keka) but we have it included as a sidebar view. Maybe I can make those buttons bring the window back?

IAmVigneswaran commented 1 month ago

The About panel is a separate window in most apps (such as Keka) but we have it included as a sidebar view.

Noted!

Is it possible for us, to pop Marker Data (after minimise) back up, when the appropriate menu items are clicked?


From ChatGPT -

To achieve the desired behavior in your SwiftUI app, where the app's menu items remain active and can bring the app back to the foreground with the appropriate side panel option selected when minimized, you can use the following approach:

Define Menu Actions: Define the actions for your menu items in a way that they can bring the app to the foreground and update the UI accordingly.

Handle App Activation: Use the NSApplication methods to bring the app to the foreground.

Manage Side Panel Selection: Use a shared state to manage the selected side panel so that the correct panel is displayed when the app is activated.

Here is an example to illustrate this:

Step 1: Define a Shared State for Side Panel Selection First, define a shared state (e.g., an ObservableObject) that will keep track of the selected side panel.

import SwiftUI

class AppState: ObservableObject {
    @Published var selectedPanel: SidePanel = .home

    enum SidePanel {
        case home
        case settings
        case profile
        // Add other panels as needed
    }
}

@main
struct MyApp: App {
    @StateObject private var appState = AppState()

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(appState)
        }
        .commands {
            CommandMenu("My Menu") {
                Button("Show Home") {
                    handleMenuAction(panel: .home)
                }
                Button("Show Settings") {
                    handleMenuAction(panel: .settings)
                }
                Button("Show Profile") {
                    handleMenuAction(panel: .profile)
                }
            }
        }
    }

    private func handleMenuAction(panel: AppState.SidePanel) {
        appState.selectedPanel = panel
        NSApp.activate(ignoringOtherApps: true)
    }
}

Step 2: Update the ContentView to Reflect the Selected Panel Update your ContentView to reflect changes in the selectedPanel state.

struct ContentView: View {
    @EnvironmentObject var appState: AppState

    var body: some View {
        VStack {
            switch appState.selectedPanel {
            case .home:
                HomeView()
            case .settings:
                SettingsView()
            case .profile:
                ProfileView()
            }
        }
    }
}

struct HomeView: View {
    var body: some View {
        Text("Home")
    }
}

struct SettingsView: View {
    var body: some View {
        Text("Settings")
    }
}

struct ProfileView: View {
    var body: some View {
        Text("Profile")
    }
}

Step 3: Activate the App when Menu Item is Clicked In the handleMenuAction function within your App struct, use NSApp.activate(ignoringOtherApps:) to bring the app to the foreground when a menu item is clicked.

Step 4: Add the Necessary Imports Ensure you have the necessary imports at the top of your Swift files:

import SwiftUI
import AppKit

This approach ensures that when a menu item is clicked, the app is brought to the foreground and the appropriate side panel is selected based on the shared state. The handleMenuAction function updates the selectedPanel state and activates the app. The ContentView then reacts to changes in the selectedPanel state to display the correct view.

milanvarady commented 1 month ago

When clicking on the About or the Open Configurations Panel option, the main window is now deminiaturized (unminimized).

IAmVigneswaran commented 1 month ago

When clicking on the About or the Open Configurations Panel option, the main window is now deminiaturized (unminimized).

Just tested! Working as expected. Thanks for fixing this.