modules/jdk.packager/src/main/native/library/common/MacPlatform.mm

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
  * All rights reserved. Use is subject to license terms.
  *
  * This file is available and licensed under the following license:
  *
  * Redistribution and use in source and binary forms, with or without

@@ -44,18 +44,21 @@
 #include <sys/sysctl.h>
 #include <pthread.h>
 #include <vector>
 
 #import <Foundation/Foundation.h>
+#import <AppKit/NSRunningApplication.h>
 
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreFoundation/CFString.h>
 
 #ifdef __OBJC__
 #import <Cocoa/Cocoa.h>
 #endif //__OBJC__
 
+#define MAC_PACKAGER_TMP_DIR "/Library/Application Support/Oracle/Java/Packager/tmp"
+
 //--------------------------------------------------------------------------------------------------
 
 NSString* StringToNSString(TString Value) {
     NSString* result = [NSString stringWithCString:Value.c_str()
                                           encoding:[NSString defaultCStringEncoding]];

@@ -85,10 +88,26 @@
     TString appname = GetModuleFileName();
     appname = FilePath::ExtractFileName(appname);
     ShowMessage(appname, Description);
 }
 
+const char* MacPlatform::getTmpDirString() {
+    return MAC_PACKAGER_TMP_DIR;
+}
+
+void MacPlatform::reactivateAnotherInstance() {
+    if (singleInstanceProcessId == 0) {
+        printf("Unable to reactivate another instance, PID is undefined");
+        return;
+    } 
+    NSRunningApplication* app = [NSRunningApplication runningApplicationWithProcessIdentifier: singleInstanceProcessId];
+    if (app != nil) {
+        [app activateWithOptions: NSApplicationActivateIgnoringOtherApps];
+    } else {
+        printf("Unable to reactivate another instance PID: %d", singleInstanceProcessId);
+    }
+}
 
 TCHAR* MacPlatform::ConvertStringToFileSystemString(TCHAR* Source, bool &release) {
     TCHAR* result = NULL;
     release = false;
     CFStringRef StringRef = CFStringCreateWithCString(kCFAllocatorDefault, Source, kCFStringEncodingUTF8);

@@ -337,10 +356,11 @@
         keys.insert(std::map<TString, TString>::value_type(PACKAGER_APP_DATA_DIR,     _T("CFBundleIdentifier")));
 
         keys.insert(std::map<TString, TString>::value_type(CONFIG_SPLASH_KEY,         _T("app.splash")));
         keys.insert(std::map<TString, TString>::value_type(CONFIG_APP_MEMORY,         _T("app.memory")));
         keys.insert(std::map<TString, TString>::value_type(CONFIG_APP_DEBUG,          _T("app.debug")));
+        keys.insert(std::map<TString, TString>::value_type(CONFIG_APPLICATION_INSTANCE,   _T("app.application.instance")));
 
         keys.insert(std::map<TString, TString>::value_type(CONFIG_SECTION_APPLICATION,    _T("Application")));
         keys.insert(std::map<TString, TString>::value_type(CONFIG_SECTION_JVMOPTIONS,     _T("JVMOptions")));
         keys.insert(std::map<TString, TString>::value_type(CONFIG_SECTION_JVMUSEROPTIONS, _T("JVMUserOptions")));
         keys.insert(std::map<TString, TString>::value_type(CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS, _T("JVMUserOverrideOptions")));