Skip to content

Commit

Permalink
Merge pull request #383 from Sequel-Ace/323-fix-Custom-Bundle-Keyboar…
Browse files Browse the repository at this point in the history
…d-Shortcuts-require-reactivation-after-Update

Issue 323 - Potentially fix Custom Bundle Keyboard Shortcuts require (re)activation after update
  • Loading branch information
Jason-Morcos committed Oct 5, 2020
2 parents 156fbe2 + 56ac956 commit 19286bc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
2 changes: 2 additions & 0 deletions SharedSupport/Default Bundles/CopyIDs.spBundle/command.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ UPDATE ... WHERE id IN (1,2,3,4)</string>
<string>showastexttooltip</string>
<key>scope</key>
<string>datatable</string>
<key>tooltip</key>
<string>Copy IDs</string>
<key>uuid</key>
<string>3C9F6E07-DF65-44D3-B0F2-8220E9BE009C</string>
<key>isDefaultBundle</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ proc.communicate(input=out_value)
<string>Copy as Markdown</string>
<key>scope</key>
<string>datatable</string>
<key>tooltip</key>
<string>Copy as Markdown</string>
<key>uuid</key>
<string>0314E554-3CDB-49D2-93FC-A28231AC9BB9</string>
<key>isDefaultBundle</key>
Expand Down
33 changes: 13 additions & 20 deletions Source/Controllers/Preferences/SPPreferencesUpgrade.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,25 @@ void SPApplyRevisionChanges(void)
currentVersionNumber = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] integerValue];

// Get the current revision
if ([prefs objectForKey:SPLastUsedVersion]) recordedVersionNumber = [[prefs objectForKey:SPLastUsedVersion] integerValue];

//Set version number back down if we're somehow too far ahead
if (currentVersionNumber < recordedVersionNumber) {
[prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion];
[importantUpdateNotes release];
return;
if ([prefs objectForKey:SPLastUsedVersion]) {
recordedVersionNumber = [[prefs objectForKey:SPLastUsedVersion] integerValue];
}

// Skip processing if the current version matches or is less than recorded version
if (currentVersionNumber <= recordedVersionNumber) {
[importantUpdateNotes release];
return;
// Check if version changed at all
if (currentVersionNumber != recordedVersionNumber) {
// Update the prefs revision
[prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion];

// Inform SPAppController to check installed default Bundles for available updates
[prefs setObject:@YES forKey:@"doBundleUpdate"];
}
// If no recorded version, update to current revision and skip processing

// If no recorded version, or current version matches or is less than recorded version, don't show release notes or do version-specific processing
if (!recordedVersionNumber) {
[prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion];
[importantUpdateNotes release];
return;
}

// Inform SPAppController to check installed default Bundles for available updates
[prefs setObject:@YES forKey:@"doBundleUpdate"];


// This is how you add release notes and run specific migration steps
if (recordedVersionNumber < 2061) {
Expand All @@ -85,10 +79,9 @@ void SPApplyRevisionChanges(void)
// Display any important release notes, if any. Call this after a slight delay to prevent double help
// menus - see http://www.cocoabuilder.com/archive/cocoa/6200-two-help-menus-why.html .
[SPPreferencesUpgrade performSelector:@selector(showPostMigrationReleaseNotes:) withObject:importantUpdateNotes afterDelay:0.1];
[importantUpdateNotes release];

// Update the prefs revision
[prefs setObject:[NSNumber numberWithInteger:currentVersionNumber] forKey:SPLastUsedVersion];
//Release the release notes object
[importantUpdateNotes release];
}

/**
Expand Down
55 changes: 36 additions & 19 deletions Source/Controllers/SPAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ - (IBAction)reloadBundles:(id)sender
NSError *appPathError = nil;
NSArray *bundlePaths = [NSArray arrayWithObjects:
[fileManager applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:YES error:&appPathError],
[NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Bundles", [[NSBundle mainBundle] bundlePath]],
[NSString stringWithFormat:@"%@/Default Bundles", [[NSBundle mainBundle] sharedSupportPath]],
nil];

// If ~/Library/Application Path/Sequel Ace/Bundles couldn't be created bail
Expand Down Expand Up @@ -1670,14 +1670,18 @@ - (IBAction)reloadBundles:(id)sender
// If default Bundle is already installed check for possible update,
// if so duplicate the modified one by appending (user) and updated it
if(doBundleUpdate || [installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] == nil) {
NSString *oldBundlePath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName];
if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] != nil && ![([[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"] ?: @"") isEqualToString: @""]) {
oldBundlePath = [[installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"];
}

if([installedBundleUUIDs objectForKey:[cmdData objectForKey:SPBundleFileUUIDKey]]) {
NSDictionary *cmdDataOld = nil;
{
NSError *readError = nil;

NSString *oldPath = [NSString stringWithFormat:@"%@/%@/%@", [bundlePaths objectAtIndex:0], bundle, SPBundleFileName];
NSData *pDataOld = [NSData dataWithContentsOfFile:oldPath options:NSUncachedRead error:&readError];

NSData *pDataOld = [NSData dataWithContentsOfFile:oldBundlePath options:NSUncachedRead error:&readError];

if(pDataOld && !readError) {
cmdDataOld = [NSPropertyListSerialization propertyListWithData:pDataOld
Expand All @@ -1687,15 +1691,15 @@ - (IBAction)reloadBundles:(id)sender
}

if(!cmdDataOld || readError) {
NSLog(@"“%@” file couldn't be read. (error=%@)", oldPath, readError);
NSBeep();
continue;
NSLog(@"“%@” file couldn't be read. (error=%@)", oldBundlePath, readError);
// NSBeep();
// continue;
}
}

NSString *oldBundle = [NSString stringWithFormat:@"%@/%@", [bundlePaths objectAtIndex:0], bundle];
// Check for modifications
if([cmdDataOld objectForKey:SPBundleFileDefaultBundleWasModifiedKey]) {
if(cmdDataOld != nil && [cmdDataOld objectForKey:SPBundleFileDefaultBundleWasModifiedKey]) {

SPLog(@"default bundle WAS modified, duplicate, change UUID and rename menu item");

Expand Down Expand Up @@ -1737,7 +1741,9 @@ - (IBAction)reloadBundles:(id)sender
[dupData writeToFile:duplicatedBundleCommand atomically:YES];

error = nil;
[fileManager removeItemAtPath:oldBundle error:&error];
if(![fileManager removeItemAtPath:oldBundle error:&error]) {
[fileManager removeItemAtPath:oldBundlePath error:&error];
}

if(error != nil) {
[NSAlert createWarningAlertWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"error while moving “%@” to trash"), [[installedBundleUUIDs objectForKey:[cmdDataOld objectForKey:SPBundleFileUUIDKey]] objectForKey:@"path"]] message:[error localizedDescription] callback:nil];
Expand All @@ -1747,7 +1753,7 @@ - (IBAction)reloadBundles:(id)sender
} else {
SPLog(@"default bundle not modified, delete and ....");
// If no modifications are done simply remove the old one
if(![fileManager removeItemAtPath:oldBundle error:nil]) {
if(![fileManager removeItemAtPath:oldBundle error:nil] && ![fileManager removeItemAtPath:oldBundlePath error:nil]) {
NSLog(@"Couldn't remove “%@” to update it", bundle);
NSBeep();
continue;
Expand Down Expand Up @@ -1820,7 +1826,7 @@ - (IBAction)reloadBundles:(id)sender
}

// Register key equivalent
if([cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [(NSString *)[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) {
if(cmdData != nil && [cmdData objectForKey:SPBundleFileKeyEquivalentKey] && [(NSString *)[cmdData objectForKey:SPBundleFileKeyEquivalentKey] length]) {

NSString *theKey = [cmdData objectForKey:SPBundleFileKeyEquivalentKey];
NSString *theChar = [theKey substringFromIndex:[theKey length]-1];
Expand All @@ -1831,16 +1837,27 @@ - (IBAction)reloadBundles:(id)sender
if([theMods rangeOfString:@"~"].length) mask = mask | NSEventModifierFlagOption;
if([theMods rangeOfString:@"$"].length) mask = mask | NSEventModifierFlagShift;

if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]])
[[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]];
NSString *theUUID = [cmdData objectForKey:SPBundleFileUUIDKey] ?: @"";
NSString *theTooltip = [cmdData objectForKey:SPBundleFileTooltipKey] ?: @"";
NSString *theFilename = [cmdData objectForKey:SPBundleFileNameKey] ?: @"";

if(!doBundleUpdate || (doBundleUpdate && (![[cmdData objectForKey:SPBundleFileIsDefaultBundleKey] boolValue] || processDefaultBundles)))
[[[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] addObject:
[NSDictionary dictionaryWithObjectsAndKeys:
infoPath, @"path",
[cmdData objectForKey:SPBundleFileNameKey], @"title",
([cmdData objectForKey:SPBundleFileTooltipKey]) ?: @"", @"tooltip",
nil]];
if(![[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]]) {
[[bundleKeyEquivalents objectForKey:scope] setObject:[NSMutableArray array] forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]];
}
NSMutableArray *bundleKeysForKey = [[bundleKeyEquivalents objectForKey:scope] objectForKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]] ?: [NSMutableArray array];
for (NSDictionary *keyInfo in bundleKeysForKey) {
if([keyInfo objectForKey:@"uuid"] == [cmdData objectForKey:SPBundleFileUUIDKey]) {
[bundleKeysForKey removeObject:keyInfo];
}
}
NSDictionary *newBundleKey = [NSDictionary dictionaryWithObjectsAndKeys:
infoPath ?: @"", @"path",
theFilename, @"title",
theTooltip, @"tooltip",
theUUID, @"uuid",
nil];
[bundleKeysForKey addObject: newBundleKey];
[[bundleKeyEquivalents objectForKey:scope] setObject:bundleKeysForKey forKey:[cmdData objectForKey:SPBundleFileKeyEquivalentKey]];

[aDict setObject:[NSArray arrayWithObjects:theChar, [NSNumber numberWithInteger:mask], nil] forKey:SPBundleInternKeyEquivalentKey];
}
Expand Down

0 comments on commit 19286bc

Please sign in to comment.