From 04a39e20a38aa6f422d52e3711ec5f67f167de7a Mon Sep 17 00:00:00 2001 From: Richard Pryce Date: Thu, 31 Aug 2023 12:45:47 +0100 Subject: [PATCH] Versions fix (#24) * Only compare major version of Premiere * Open latest version of PP with matching major version * Use latest MacOs runner image * Use github run number * Don't offset build number * Include project configfuration --- .github/workflows/objective-c-xcode.yml | 11 ++----- PlutoHelperAgent.xcodeproj/project.pbxproj | 7 ++-- PlutoHelperAgent/AppDelegate.m | 38 ++++++++++++++++++++-- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.github/workflows/objective-c-xcode.yml b/.github/workflows/objective-c-xcode.yml index 563dfb1..7eeb3eb 100644 --- a/.github/workflows/objective-c-xcode.yml +++ b/.github/workflows/objective-c-xcode.yml @@ -9,19 +9,14 @@ on: jobs: build: name: Build and export default scheme using xcodebuild command - runs-on: macos-10.15 + runs-on: macos-latest steps: - name: Checkout uses: actions/checkout@v2 - - name: Generate Build Number - id: buildnumber - uses: einaregilsson/build-number@v3 - with: - token: ${{secrets.github_token}} - name: Set Build Number run: | - /usr/libexec/PlistBuddy -c "Set :CFBundleVersion Build ${BUILD_NUMBER}" "PlutoHelperAgent/Info.plist" + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion Build $GITHUB_RUN_NUMBER" "PlutoHelperAgent/Info.plist" - name: Test run: | xcodebuild test -project PlutoHelperAgent.xcodeproj -scheme PlutoHelperAgent -destination 'platform=OS X,arch=x86_64' @@ -43,7 +38,7 @@ jobs: uses: actions/upload-artifact@v2.3.1 with: # Artifact name - name: PlutoHelperAgent-${{ env.BUILD_NUMBER }} + name: PlutoHelperAgent-${{ github.run_number }} # A file, directory or wildcard pattern that describes what to upload path: ./package/ # The desired behavior if no files are found using the provided path. diff --git a/PlutoHelperAgent.xcodeproj/project.pbxproj b/PlutoHelperAgent.xcodeproj/project.pbxproj index 20b6564..445253d 100644 --- a/PlutoHelperAgent.xcodeproj/project.pbxproj +++ b/PlutoHelperAgent.xcodeproj/project.pbxproj @@ -340,7 +340,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.12; MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; + ONLY_ACTIVE_ARCH = NO; SDKROOT = macosx; }; name = Debug; @@ -376,6 +376,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.12; MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = NO; SDKROOT = macosx; }; name = Release; @@ -389,7 +390,7 @@ INFOPLIST_FILE = PlutoHelperAgent/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 3.1; + MARKETING_VERSION = 3.2.2; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -403,7 +404,7 @@ INFOPLIST_FILE = PlutoHelperAgent/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 3.1; + MARKETING_VERSION = 3.2.2; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/PlutoHelperAgent/AppDelegate.m b/PlutoHelperAgent/AppDelegate.m index f92d442..fc77b38 100644 --- a/PlutoHelperAgent/AppDelegate.m +++ b/PlutoHelperAgent/AppDelegate.m @@ -130,17 +130,49 @@ - (void)showError:(NSString *)showError informativeText:(NSString *)informativeT } - (void) processVersion:(NSString *)premiereVersion filePath:(NSString *)filePath { + NSLog(@"Starting processVersion with premiereVersion: %@ and filePath: %@", premiereVersion, filePath); + NSDictionary * premiereVersions = [[NSUserDefaults standardUserDefaults] objectForKey:@"Premiere_versions"]; - if (premiereVersions[premiereVersion]) { + if (!premiereVersions) { + NSLog(@"Warning: premiereVersions dictionary not found in UserDefaults."); + return; + } + NSLog(@"Fetched premiereVersions from UserDefaults: %@", premiereVersions); + + NSArray *allKeys = [premiereVersions allKeys]; + NSLog(@"All available versions: %@", allKeys); + + NSArray *versionComponents = [premiereVersion componentsSeparatedByString:@"."]; + if ([versionComponents count] < 1) { + NSLog(@"Error: Invalid premiereVersion format"); + return; + } + + NSString *majorVersion = versionComponents[0]; + NSLog(@"Extracted major version: %@", majorVersion); + + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH %@", majorVersion]; + NSArray *filteredKeys = [allKeys filteredArrayUsingPredicate:predicate]; + NSLog(@"Filtered versions with the same major version: %@", filteredKeys); + + if ([filteredKeys count] > 0) { + NSString *latestVersion = [HelperFunctions getLatestVersion:filteredKeys]; + NSLog(@"Latest available version with the same major version: %@", latestVersion); + + NSLog(@"Launched app with version: %@", premiereVersions[latestVersion]); NSTask *openTask = [[NSTask alloc] init]; [openTask setLaunchPath:@"/usr/bin/open"]; [openTask setCurrentDirectoryPath:@"/"]; - [openTask setArguments:@[ @"-a", premiereVersions[premiereVersion], filePath ]]; + [openTask setArguments:@[ @"-a", premiereVersions[latestVersion], filePath ]]; [openTask launch]; } else { - NSString *requiredVersion = [HelperFunctions getLatestVersion:[premiereVersions allKeys]]; + NSString *requiredVersion = [HelperFunctions getLatestVersion:allKeys]; + NSLog(@"No matching versions found. Falling back to latest version: %@", requiredVersion); + NSString *plutoURL = [NSString stringWithFormat:@"%@pluto-core/file/changePremiereVersion?project=%@&requiredVersion=%@", [[NSUserDefaults standardUserDefaults] stringForKey:@"pluto_url"], filePath, requiredVersion]; [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:plutoURL]]; + + NSLog(@"Opened URL for version change: %@", plutoURL); } }