Skip to content

Commit

Permalink
Dont treat self as another running instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dyumin committed Mar 7, 2021
1 parent e597199 commit 53fc9e3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Draggy/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
int main(const int argc, const char *argv[]) {
@autoreleasepool {
__auto_type const mainBundleIdentifier = NSBundle.mainBundle.bundleIdentifier;
__auto_type const currentProcessIdentifier = NSRunningApplication.currentApplication.processIdentifier;
__block NSRunningApplication *anotherInstance;
// may be unreliable, but should do the job
const __auto_type index = [NSWorkspace.sharedWorkspace.runningApplications indexOfObjectPassingTest:^BOOL(NSRunningApplication *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
const bool isEqual = [obj.bundleIdentifier isEqualToString:mainBundleIdentifier];
if (isEqual) {
const bool anotherInstanceFound = [obj.bundleIdentifier isEqualToString:mainBundleIdentifier] && obj.processIdentifier != currentProcessIdentifier;
if (anotherInstanceFound) {
anotherInstance = obj;
}
return isEqual;
return anotherInstanceFound;
}];

if (index != NSNotFound) {
Expand Down

0 comments on commit 53fc9e3

Please sign in to comment.