Skip to content

Commit

Permalink
v1.0.2 Release
Browse files Browse the repository at this point in the history
Fixed a layout issue causing overlap that obstructed the timer and volume controls making them difficult to touch on the edges
Fixed a potential issue that could cause a settings pane crash if the user renamed an imported audio file in Filza/ssh to the same as a downloadable audio files localized name
Improved sounds sorting method to remain consistent in all cases
  • Loading branch information
CreatureSurvive committed Mar 29, 2022
1 parent 57816dd commit e569dae
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 57 deletions.
85 changes: 56 additions & 29 deletions Classes/Prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,6 @@ NS_INLINE __unused void OpenApplicationUrl(NSURL *url)
});
}

NS_INLINE __unused NSArray<NSDictionary *> *AudioMetadata(NSString *bundlePath)
{
NSString *bundledAudioPath = [bundlePath stringByAppendingPathComponent:@"Audio"];
NSArray *bundledAudioFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:bundledAudioPath error:nil];

NSString *userProvidedAudioPath = @"/var/mobile/Library/Application Support/Tranquil/Audio";
NSArray *userProvidedAudioFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:userProvidedAudioPath error:nil];

__block NSMutableArray *combinedMetadata = [NSMutableArray new];

void (^generateMetadata)(NSArray *, NSString *) = ^(NSArray *files, NSString *basePath)
{
NSArray *sortedFiles = [files sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

for (NSString *file in sortedFiles)
{
[combinedMetadata addObject:@{
@"path" : [basePath stringByAppendingPathComponent:file],
@"name" : [file stringByDeletingPathExtension]
}];
}
};

generateMetadata(bundledAudioFiles, bundledAudioPath);
generateMetadata(userProvidedAudioFiles, userProvidedAudioPath);

return combinedMetadata;
}

NS_INLINE __unused NSArray<NSString *> *DownloadableAudioFileNames(void)
{
static NSArray *downloadableAudioFileNames;
Expand All @@ -180,6 +151,7 @@ NS_INLINE __unused NSArray<NSDictionary *> *DownloadableAudioMetadata(void)

if (!downloadableAudioMetadata) {

// TODO migrate downloadable content to separate directory for improved organization
downloadableAudioMetadata = @[
@{
@"name" : @"INFRA_NOISE",
Expand Down Expand Up @@ -219,6 +191,61 @@ NS_INLINE __unused BOOL DownloadableContentAvailable(void)
return downloadsAvailable;
}

NS_INLINE __unused NSArray<NSDictionary *> *AudioMetadataIncludingDLC(BOOL includeDownloadable)
{
NSString *bundledAudioPath = [ModuleBundle(NO).bundlePath stringByAppendingPathComponent:@"Audio"];
NSArray *bundledAudioFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:bundledAudioPath error:nil];

NSString *userProvidedAudioPath = @"/var/mobile/Library/Application Support/Tranquil/Audio";
NSArray *userProvidedAudioFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:userProvidedAudioPath error:nil];

__block NSMutableSet *uniquePaths = [NSMutableSet new];
__block NSMutableArray *combinedMetadata = [NSMutableArray new];

void (^generateMetadata)(NSArray *, NSString *) = ^(NSArray *files, NSString *basePath)
{
for (NSString *file in files)
{
NSString *fullPath = [basePath stringByAppendingPathComponent:file];

if ([uniquePaths containsObject:fullPath]) continue;
[uniquePaths addObject:fullPath];
[combinedMetadata addObject:@{
@"path" : fullPath,
@"name" : [file stringByDeletingPathExtension]
}];
}
};

generateMetadata(bundledAudioFiles, bundledAudioPath);
generateMetadata(userProvidedAudioFiles, userProvidedAudioPath);

if (includeDownloadable) {

generateMetadata(DownloadableAudioFileNames(), userProvidedAudioPath);
}

NSArray *downloadableNames = DownloadableAudioFileNames();
// sort metadata alphabetically, then by asset type (1:bundled 2:imported 3:downloadable)
NSSortDescriptor *name = [NSSortDescriptor sortDescriptorWithKey:@"path" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *path = [NSSortDescriptor sortDescriptorWithKey:@"path" ascending:YES comparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
BOOL isDownloadable1 = [downloadableNames containsObject:obj1.lastPathComponent];
BOOL isDownloadable2 = [downloadableNames containsObject:obj2.lastPathComponent];
return isDownloadable2 && !isDownloadable1 ? NSOrderedAscending :
isDownloadable1 && !isDownloadable2 ? NSOrderedDescending :
NSOrderedSame;
}];

[combinedMetadata sortUsingDescriptors:@[path, name]];

return combinedMetadata;
}

NS_INLINE __unused NSArray<NSDictionary *> *AudioMetadata(void)
{
return AudioMetadataIncludingDLC(NO);
}

NS_INLINE __unused UIAlertController *GenericErrorAlert(NSError *error, UIViewController *controller)
{
UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:Localize(@"GENERIC_ERROR_TITLE") message:error.localizedFailureReason preferredStyle:UIAlertControllerStyleAlert];
Expand Down
2 changes: 1 addition & 1 deletion Classes/TranquilModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (NSBundle *)moduleBundle

- (NSArray <NSDictionary *> *)audioMetadata
{
return AudioMetadata([self moduleBundle].bundlePath);
return AudioMetadata();
}

- (void)refreshState
Expand Down
24 changes: 16 additions & 8 deletions Classes/TranquilModuleBackgroundViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ @interface TranquilModuleBackgroundViewController () {

UITapGestureRecognizer *_controlDismissRecognizer;

NSLayoutConstraint *_timerButtonWidthAnchor;
NSLayoutConstraint *_volumeButtonWidthAnchor;
NSLayoutConstraint *_timerControlTrailingAnchor;
NSLayoutConstraint *_volumeControlLeadingAnchor;
NSLayoutConstraint *_timerControlContainerLeadingAnchor;
Expand Down Expand Up @@ -375,11 +377,13 @@ - (void)_updateControlType:(TMControlType)type animated:(BOOL)animated opening:(
CGFloat controlWidth = (UIEdgeInsetsInsetRect(self.view.bounds, self.view.layoutMargins).size.width - 76);
(isVolume ? _volumeControlContainerTrailingAnchor : _timerControlContainerLeadingAnchor).constant = opening ? 0 : NEGATE_IF(controlWidth, isVolume);
(isVolume ? _volumeControlLeadingAnchor : _timerControlTrailingAnchor).constant = opening ? NEGATE_IF(65, !isVolume) : NEGATE_IF(3, !isVolume);
(isVolume ? _volumeButtonWidthAnchor : _timerButtonWidthAnchor).constant = opening ? 54 : 108;
} break;
case TMLayoutDirectionHorizontal: {
CGFloat controlHeight = (UIEdgeInsetsInsetRect(self.view.bounds, self.view.layoutMargins).size.height - 76);
(isVolume ? _volumeControlContainerBottomAnchor : _timerControlContainerTopAnchor).constant = opening ? 0 : NEGATE_IF(controlHeight, isVolume);
(isVolume ? _volumeControlTopAnchor : _timerControlBottomAnchor).constant = opening ? NEGATE_IF(65, !isVolume) : NEGATE_IF(3, !isVolume);
(isVolume ? _volumeButtonWidthAnchor : _timerButtonWidthAnchor).constant = 108;
} break;
}

Expand Down Expand Up @@ -458,12 +462,16 @@ - (void)updateConstraintsForLayoutDirection:(TMLayoutDirection)direction

- (void)_configureConstraints
{
CGFloat buttonViewWidth = 108;
CGFloat bottomMargin = -88;
CGFloat fixedHeight = 54;
CGFloat openHeight = 46;
CGFloat margin = 38;
UILayoutGuide *marginsGuide = self.view.layoutMarginsGuide;

_timerButtonWidthAnchor = [_timerButtonViewController.view.widthAnchor constraintEqualToConstant:buttonViewWidth];
_volumeButtonWidthAnchor = [_volumeButtonViewController.view.widthAnchor constraintEqualToConstant:buttonViewWidth];

_timerControlTrailingAnchor = [_timerStepper.trailingAnchor constraintEqualToAnchor:_timerControlContainer.trailingAnchor constant:-65];
_volumeControlLeadingAnchor = [_volumeSlider.leadingAnchor constraintEqualToAnchor:_volumeControlContainer.leadingAnchor constant:65];
_timerControlContainerLeadingAnchor = [_timerControlContainer.leadingAnchor constraintEqualToAnchor:_controlContainer.leadingAnchor];
Expand All @@ -472,6 +480,8 @@ - (void)_configureConstraints
_verticalConstraints = @[
_timerControlTrailingAnchor,
_volumeControlLeadingAnchor,
_timerButtonWidthAnchor,
_volumeButtonWidthAnchor,
_timerControlContainerLeadingAnchor,
_volumeControlContainerTrailingAnchor,
[_controlContainer.heightAnchor constraintEqualToConstant:fixedHeight],
Expand All @@ -491,16 +501,14 @@ - (void)_configureConstraints
[_timerStepper.topAnchor constraintEqualToAnchor:_timerControlContainer.topAnchor constant:4],
[_timerStepper.bottomAnchor constraintEqualToAnchor:_timerControlContainer.bottomAnchor constant:-4],
[_volumeButtonViewController.view.heightAnchor constraintEqualToConstant:fixedHeight],
[_volumeButtonViewController.view.widthAnchor constraintEqualToConstant:108],
[_volumeButtonViewController.view.leadingAnchor constraintEqualToAnchor:_controlContainer.leadingAnchor constant:-27],
[_volumeButtonViewController.view.centerXAnchor constraintEqualToAnchor:_controlContainer.leadingAnchor constant:(fixedHeight * 0.5f)],
[_volumeButtonViewController.view.topAnchor constraintEqualToAnchor:_controlContainer.topAnchor],
[_playbackButtonViewController.view.heightAnchor constraintEqualToConstant:fixedHeight],
[_playbackButtonViewController.view.widthAnchor constraintEqualToConstant:108],
[_playbackButtonViewController.view.widthAnchor constraintEqualToConstant:buttonViewWidth],
[_playbackButtonViewController.view.centerXAnchor constraintEqualToAnchor:_controlContainer.centerXAnchor],
[_playbackButtonViewController.view.topAnchor constraintEqualToAnchor:_controlContainer.topAnchor],
[_timerButtonViewController.view.heightAnchor constraintEqualToConstant:fixedHeight],
[_timerButtonViewController.view.widthAnchor constraintEqualToConstant:108],
[_timerButtonViewController.view.trailingAnchor constraintEqualToAnchor:_controlContainer.trailingAnchor constant:27],
[_timerButtonViewController.view.centerXAnchor constraintEqualToAnchor:_controlContainer.trailingAnchor constant:-(fixedHeight * 0.5f)],
[_timerButtonViewController.view.topAnchor constraintEqualToAnchor:_controlContainer.topAnchor],
];

Expand All @@ -512,6 +520,8 @@ - (void)_configureConstraints
_horizontalConstraints = @[
_timerControlBottomAnchor,
_volumeControlTopAnchor,
_timerButtonWidthAnchor,
_volumeButtonWidthAnchor,
_timerControlContainerTopAnchor,
_volumeControlContainerBottomAnchor,
[_controlContainer.widthAnchor constraintEqualToConstant:fixedHeight],
Expand All @@ -530,15 +540,13 @@ - (void)_configureConstraints
[_timerStepper.topAnchor constraintEqualToAnchor:_timerControlContainer.topAnchor constant:4],
[_timerStepper.leadingAnchor constraintEqualToAnchor:_timerControlContainer.leadingAnchor constant:4],
[_timerStepper.trailingAnchor constraintEqualToAnchor:_timerControlContainer.trailingAnchor constant:-4],
[_volumeButtonViewController.view.widthAnchor constraintEqualToConstant:108],
[_volumeButtonViewController.view.heightAnchor constraintEqualToConstant:fixedHeight],
[_volumeButtonViewController.view.topAnchor constraintEqualToAnchor:_controlContainer.topAnchor],
[_volumeButtonViewController.view.centerXAnchor constraintEqualToAnchor:_controlContainer.centerXAnchor],
[_playbackButtonViewController.view.widthAnchor constraintEqualToConstant:108],
[_playbackButtonViewController.view.widthAnchor constraintEqualToConstant:buttonViewWidth],
[_playbackButtonViewController.view.heightAnchor constraintEqualToConstant:fixedHeight],
[_playbackButtonViewController.view.centerXAnchor constraintEqualToAnchor:_controlContainer.centerXAnchor],
[_playbackButtonViewController.view.centerYAnchor constraintEqualToAnchor:_controlContainer.centerYAnchor],
[_timerButtonViewController.view.widthAnchor constraintEqualToConstant:108],
[_timerButtonViewController.view.heightAnchor constraintEqualToConstant:fixedHeight],
[_timerButtonViewController.view.bottomAnchor constraintEqualToAnchor:_controlContainer.bottomAnchor],
[_timerButtonViewController.view.centerXAnchor constraintEqualToAnchor:_controlContainer.centerXAnchor]
Expand Down
21 changes: 3 additions & 18 deletions Classes/TranquilPreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ - (NSURL *)userImportedSoundsDirectoryURL

- (NSArray *)audioMetadata
{
return AudioMetadata([NSBundle bundleForClass:self.class].bundlePath);
return AudioMetadata();
}

- (NSArray *)downloadableMetadata
Expand All @@ -110,42 +110,27 @@ - (NSArray *)downloadableMetadata

- (NSArray *)activeSoundTitles
{
NSArray *metadata = [self audioMetadata];
NSArray *downloadableMetadata = [self downloadableMetadata];
NSArray *metadata = AudioMetadataIncludingDLC(YES);
NSMutableArray *titles = [NSMutableArray new];

for (NSDictionary *entry in metadata)
{
[titles addObject:Localize(entry[@"name"])];
}

for (NSDictionary *entry in downloadableMetadata)
{
NSString *name = Localize(entry[@"name"]);
if ([titles containsObject:name]) continue;
[titles addObject:name];
}

return titles;
}

- (NSArray *)activeSoundValues
{
NSArray *metadata = [self audioMetadata];
NSArray *downloadableMetadata = [self downloadableMetadata];
NSArray *metadata = AudioMetadataIncludingDLC(YES);
NSMutableArray *values = [NSMutableArray new];

for (NSDictionary *entry in metadata)
{
[values addObject:entry[@"path"]];
}

for (NSDictionary *entry in downloadableMetadata)
{
if ([values containsObject:entry[@"path"]]) continue;
[values addObject:entry[@"path"]];
}

return values;
}

Expand Down
Binary file not shown.
Binary file modified Resources/Assets.car
Binary file not shown.
2 changes: 1 addition & 1 deletion layout/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.creaturecoding.tranquil
Name: Tranquil
Depends: mobilesubstrate, com.opa334.ccsupport
Version: 1.0.1
Version: 1.0.2
Architecture: iphoneos-arm
Description: Background sounds feature from iOS 15 on iOS 11+
Maintainer: CreatureSurvive <[email protected]>
Expand Down

0 comments on commit e569dae

Please sign in to comment.