use of org.rococoa.cocoa.foundation.NSArray in project HearthStats.net-Uploader by HearthStats.
the class ProgramHelperOsx method bringWindowToForeground.
@Override
public boolean bringWindowToForeground() {
final NSAutoreleasePool pool;
try {
pool = NSAutoreleasePool.new_();
} catch (Throwable ex) {
ex.printStackTrace(System.err);
throw new RuntimeException("Unable to find program " + _bundleIdentifier + " due to exception", ex);
}
try {
final NSArray nsArray = NSRunningApplication.CLASS.runningApplicationsWithBundleIdentifier(_bundleIdentifier);
final int size = nsArray.count();
for (int i = 0; i < size; i++) {
final NSRunningApplication nsRunningApplication = Rococoa.cast(nsArray.objectAtIndex(i), NSRunningApplication.class);
// This double-check of the bundle identifier is probably unnecessary...
if (_bundleIdentifier.equals(nsRunningApplication.bundleIdentifier())) {
boolean result = nsRunningApplication.activateWithOptions(0);
debugLog.debug("nsRunningApplication.activateWithOptions returned {}", result);
return result;
}
}
} catch (Exception ex) {
ex.printStackTrace(System.err);
throw new RuntimeException("Unable to find program " + _bundleIdentifier + " due to exception", ex);
} finally {
pool.drain();
}
return false;
}
use of org.rococoa.cocoa.foundation.NSArray in project HearthStats.net-Uploader by HearthStats.
the class ProgramHelperOsx method findProgramPid.
/**
* Looks for the program specified by {@link #_bundleIdentifier}, and if it finds it sets the {@link #_pid} to the process ID.
* Resets the {@link #_pid} if the program could not be found (ie it's not running).
*/
private int findProgramPid(String bundleIdentifier) {
final NSAutoreleasePool pool;
try {
pool = NSAutoreleasePool.new_();
} catch (Throwable ex) {
ex.printStackTrace(System.err);
throw new RuntimeException("Unable to find program " + bundleIdentifier + " due to exception", ex);
}
try {
final NSArray nsArray = NSRunningApplication.CLASS.runningApplicationsWithBundleIdentifier(bundleIdentifier);
final int size = nsArray.count();
for (int i = 0; i < size; i++) {
final NSRunningApplication nsRunningApplication = Rococoa.cast(nsArray.objectAtIndex(i), NSRunningApplication.class);
// This double-check of the bundle identifier is probably unnecessary...
if (bundleIdentifier.equals(nsRunningApplication.bundleIdentifier())) {
// We've found the application, so we can skip the rest of the loop
return nsRunningApplication.processIdentifier();
}
}
} catch (Exception ex) {
ex.printStackTrace(System.err);
throw new RuntimeException("Unable to find program " + bundleIdentifier + " due to exception", ex);
} finally {
pool.drain();
}
return 0;
}
Aggregations