diff --git a/ThrowBack/TBProphylaxis.h b/ThrowBack/TBProphylaxis.h new file mode 100644 index 0000000..3825ff8 --- /dev/null +++ b/ThrowBack/TBProphylaxis.h @@ -0,0 +1,13 @@ +// +// TBProphylaxis.h +// WWDC +// +// Created by Guilherme Rambo on 14/05/17. +// Copyright © 2017 Guilherme Rambo. All rights reserved. +// + +#import + +@interface TBProphylaxis : NSObject + +@end diff --git a/ThrowBack/TBProphylaxis.m b/ThrowBack/TBProphylaxis.m new file mode 100644 index 0000000..fe829ba --- /dev/null +++ b/ThrowBack/TBProphylaxis.m @@ -0,0 +1,43 @@ +// +// TBProphylaxis.m +// WWDC +// +// Created by Guilherme Rambo on 14/05/17. +// Copyright © 2017 Guilherme Rambo. All rights reserved. +// + +#import "TBProphylaxis.h" + +@import Cocoa; + +@implementation TBProphylaxis + ++ (void)load +{ + NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"br.com.guilhermerambo.WWDC"]; + + BOOL shouldQuit = NO; + + for (NSRunningApplication *app in apps) { + NSBundle *bundle = [NSBundle bundleWithURL:app.bundleURL]; + NSString *shortVersion = bundle.infoDictionary[@"CFBundleShortVersionString"]; + double shortVersionNumber = [shortVersion doubleValue]; + + if (shortVersionNumber < 5) { + if (![app forceTerminate]) { + shouldQuit = YES; + } + } + } + + if (shouldQuit) { + NSAlert *alert = [NSAlert new]; + alert.messageText = @"Older version running"; + alert.informativeText = @"There's an older version of WWDC for macOS running. Version 5 can't work with older versions. Please quit the other version and launch Version 5 again."; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + exit(1); + } +} + +@end diff --git a/WWDC.xcodeproj/project.pbxproj b/WWDC.xcodeproj/project.pbxproj index 92a8568..ae175c7 100644 --- a/WWDC.xcodeproj/project.pbxproj +++ b/WWDC.xcodeproj/project.pbxproj @@ -118,6 +118,8 @@ DDB3529C1EC8AB5D00254815 /* WWDCLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB3529B1EC8AB5D00254815 /* WWDCLayer.swift */; }; DDB3529E1EC8D8CD00254815 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DDB3529D1EC8D8CD00254815 /* main.m */; }; DDB352A01EC9088000254815 /* WWDCTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB3529F1EC9088000254815 /* WWDCTableView.swift */; }; + DDB352A51EC90ACA00254815 /* TBProphylaxis.h in Headers */ = {isa = PBXBuildFile; fileRef = DDB352A31EC90ACA00254815 /* TBProphylaxis.h */; }; + DDB352A61EC90ACA00254815 /* TBProphylaxis.m in Sources */ = {isa = PBXBuildFile; fileRef = DDB352A41EC90ACA00254815 /* TBProphylaxis.m */; }; DDCE7ECD1EA7A0F800C7A3CA /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE7ECC1EA7A0F800C7A3CA /* MainWindowController.swift */; }; DDCE7ED21EA7A1D300C7A3CA /* WWDCAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = DDCE7ED11EA7A1D300C7A3CA /* WWDCAppearance.m */; }; DDCE7ED91EA7A86600C7A3CA /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE7ED81EA7A86600C7A3CA /* AppCoordinator.swift */; }; @@ -353,6 +355,8 @@ DDB3529B1EC8AB5D00254815 /* WWDCLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WWDCLayer.swift; sourceTree = ""; }; DDB3529D1EC8D8CD00254815 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; DDB3529F1EC9088000254815 /* WWDCTableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WWDCTableView.swift; sourceTree = ""; }; + DDB352A31EC90ACA00254815 /* TBProphylaxis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TBProphylaxis.h; sourceTree = ""; }; + DDB352A41EC90ACA00254815 /* TBProphylaxis.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TBProphylaxis.m; sourceTree = ""; }; DDBFA16A1EB525F2004AE10F /* PlayerUI.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PlayerUI.xcodeproj; path = PlayerUI/PlayerUI.xcodeproj; sourceTree = ""; }; DDCE7ECC1EA7A0F800C7A3CA /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = ""; }; DDCE7ECF1EA7A1D300C7A3CA /* WWDC-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WWDC-Bridging-Header.h"; sourceTree = ""; }; @@ -853,6 +857,8 @@ children = ( DDDAA3F11EC7653300DF9D02 /* Info.plist */, DDDAA3F01EC7653300DF9D02 /* ThrowBack.h */, + DDB352A31EC90ACA00254815 /* TBProphylaxis.h */, + DDB352A41EC90ACA00254815 /* TBProphylaxis.m */, DDDAA4001EC768A900DF9D02 /* Migration */, ); path = ThrowBack; @@ -936,6 +942,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + DDB352A51EC90ACA00254815 /* TBProphylaxis.h in Headers */, DDDAA3F21EC7653300DF9D02 /* ThrowBack.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1285,6 +1292,7 @@ DDDAA4071EC76D9300DF9D02 /* TBPreferences.swift in Sources */, DDDAA40A1EC775B500DF9D02 /* TBSession.swift in Sources */, DDDAA4021EC768C500DF9D02 /* TBUserDataMigrator.swift in Sources */, + DDB352A61EC90ACA00254815 /* TBProphylaxis.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };