Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift implementation (IOS Equalizer) #784

Open
wants to merge 19 commits into
base: minor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ pubspec.lock
*.iml

# VS Code
.vscode
.vscode

.DS_Store
6 changes: 6 additions & 0 deletions tools/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
24 changes: 24 additions & 0 deletions tools/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Development tools

### Swift development

**Problem**

Native `macos` and `ios` projects share most of the code. Sadly, CocoaPods does not allow to
reference files outside of the root project directory, or to symlink `.swift` files.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? The symlink solution does at least work for objective C. For swift, I have seen other solutions to code sharing, though, a type of include/import-based solution.


This would force us to duplicate the code between `macos` and `ios` implementations with cut &
paste.

**Solution**

A simple script that watches a source folder (say `darwin`) and copies the files to the correct
folder. Of course this means that most of future ios/macos developments will need to happen inside
the source folder.

**How to**
Launch the script inside `tools/cli/lib`. Say you are in the root of the repository it would be

```bash
dart run ./tools/cli/lib/sync_darwin_folder.dart
```
11 changes: 11 additions & 0 deletions tools/cli/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false

linter:
rules:
prefer_single_quotes: false
unawaited_futures: false
64 changes: 64 additions & 0 deletions tools/cli/lib/sync_darwin_folder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:core';
import 'dart:io';

import "package:path/path.dart" show dirname;
import 'package:watcher/watcher.dart';

void main(List<String> arguments) {
watch(
sourceFolder: "just_audio/darwin",
destinationFolders: [
"just_audio/macos",
"just_audio/ios",
],
);
}

/// Watches files changes (add, modify and remove) inside the [sourceFolder], and aligns accordingly
/// the [destinationFolders] files. Both [sourceFolder] and [destinationFolders] are supposed to be relative paths to the directory you want to operate with.
///
/// Throws a [FileSystemException] if [sourceFolder] does not exist.
void watch({
required String sourceFolder,
required List<String> destinationFolders,
}) {
final currentDir = dirname(Platform.script.path).dropLastSlash();
final baseDir = "$currentDir/../../..";
final destinationDirs = destinationFolders.map((it) {
return "$baseDir/${it.dropLastSlash()}";
});
final watcher = DirectoryWatcher("$baseDir/$sourceFolder");

watcher.events.listen((event) {
final partialPath = event.path.replaceAll("$baseDir/$sourceFolder", "");

print("Updating $partialPath");

switch (event.type) {
case ChangeType.ADD:
case ChangeType.MODIFY:
final file = File(event.path);
for (final destination in destinationDirs) {
file.copySync("$destination$partialPath");
}
break;
case ChangeType.REMOVE:
for (var element in destinationDirs) {
final file = File("$element$partialPath");
file.deleteSync(recursive: file is Directory);
}
}
});

print("🫣 Watching files 🫣");
}

extension StringPathClean on String {
String dropLastSlash() {
if (endsWith("/")) {
return substring(0, length - 1);
}

return this;
}
}
13 changes: 13 additions & 0 deletions tools/cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: cli
description: Just Audio development utilities
version: 0.1.0

environment:
sdk: '>=2.17.0 <3.0.0'

dependencies:
path: ^1.8.2
watcher: ^1.0.1

dev_dependencies:
lints: ^2.0.0