Merge pull request #81 from vkedwardli/feat/macOS-multiple-instance
[macOS] Enable "New Instance" in File and Dock menu
This commit is contained in:
commit
a04b7f88fa
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue