From e1bd8a4ea77f82216e4c0f831367512c2729272d Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sun, 26 Apr 2020 12:23:54 +0800 Subject: [PATCH] [macOS] Enable "New Instance" in File and Dock menu --- .../emulator-osx/emulator-osx/AppDelegate.swift | 13 +++++++++++++ shell/apple/emulator-osx/emulator-osx/osx-main.mm | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift b/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift index ee497e805..ec374e2ae 100644 --- a/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift +++ b/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift @@ -18,6 +18,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { if let name = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String { window.title = name } + NSApplication.shared.mainMenu?.item(at: 1)?.submenu?.insertItem( + NSMenuItem(title: "New Instance", action: #selector(newInstance(_:)), keyEquivalent: "n"), at: 0 + ) } func applicationWillTerminate(_ aNotification: Notification) { @@ -27,5 +30,15 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + func applicationDockMenu(_ sender: NSApplication) -> NSMenu? { + let dockMenu = NSMenu() + dockMenu.addItem(withTitle: "New Instance", action: #selector(newInstance(_:)), keyEquivalent: "n") + return dockMenu + } + + @objc func newInstance(_ sender: NSMenuItem) { + Process.launchedProcess(launchPath: "/usr/bin/open", arguments: ["-n", Bundle.main.bundlePath]) + } } diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index 237ba6fc0..9a5376f36 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -133,6 +133,11 @@ extern "C" void emu_gles_init(int width, int height) { if (home != NULL) { std::string config_dir = std::string(home) + "/.reicast"; + int instanceNumber = (int)[[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.reicast.Flycast"] count]; + if (instanceNumber > 1){ + config_dir += "/" + std::to_string(instanceNumber); + [[NSApp dockTile] setBadgeLabel:@(instanceNumber).stringValue]; + } mkdir(config_dir.c_str(), 0755); // create the directory if missing set_user_config_dir(config_dir); set_user_data_dir(config_dir);