add ios patch
This commit is contained in:
364
ios/setup.zsh
364
ios/setup.zsh
@@ -1,232 +1,172 @@
|
||||
#!/bin/zsh
|
||||
d=${0:a:h}
|
||||
cd $d
|
||||
|
||||
source $d/config.zsh
|
||||
# iOS Social App Patch Setup Script
|
||||
# Usage: ./ios/setup.zsh [patch|reset]
|
||||
|
||||
# Sed compatibility wrapper
|
||||
function sediment() {
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
sed -i '' "$@"
|
||||
else
|
||||
sed -i "$@"
|
||||
fi
|
||||
# Arrays for patch management
|
||||
typeset -a FAILED_PATCHES
|
||||
|
||||
# Patch file lists for iOS
|
||||
typeset -a PATCH_FILES_IOS
|
||||
PATCH_FILES_IOS=(
|
||||
"001-social-app-ios-config.patch"
|
||||
"002-social-app-ios-lib.patch"
|
||||
"003-social-app-ios-view.patch"
|
||||
"004-social-app-ios-core.patch"
|
||||
"005-social-app-ios-screens.patch"
|
||||
"006-social-app-ios-shell.patch"
|
||||
"007-social-app-ios-misc.patch"
|
||||
"008-social-app-ios-policy-tos-error.patch"
|
||||
"009-social-app-ios-license.patch"
|
||||
"010-social-app-ios-remove-contact-support.patch"
|
||||
"011-social-app-ios-splash-license-footer.patch"
|
||||
"012-social-app-ios-settings-about-help.patch"
|
||||
"013-social-app-ios-settings-remove-help.patch"
|
||||
)
|
||||
|
||||
function ios-env() {
|
||||
d=${0:a:h:h}
|
||||
patching_dir=${0:a:h}/patching
|
||||
target_dir=$d/repos/social-app
|
||||
}
|
||||
|
||||
echo "Configuring $APP_NAME..."
|
||||
# Common patch function with status detection
|
||||
function apply-patch() {
|
||||
local patch_name=$1
|
||||
local target_dir=$2
|
||||
local patch_file=$3
|
||||
|
||||
# Check if repo exists
|
||||
#if [ ! -d "$REPO_DIR" ]; then
|
||||
# echo "Cloning social-app..."
|
||||
# git clone https://github.com/bluesky-social/social-app "$REPO_DIR"
|
||||
#else
|
||||
# echo "Updating social-app..."
|
||||
# pushd "$REPO_DIR"
|
||||
# git stash -u
|
||||
# if ! git pull; then
|
||||
# echo "Git pull failed. Resetting..."
|
||||
# git reset --hard HEAD
|
||||
# git pull
|
||||
# fi
|
||||
# popd
|
||||
#fi
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📝 Patch: ${patch_name}"
|
||||
echo " Target: ${target_dir}"
|
||||
echo " File: ${patch_file}"
|
||||
|
||||
# Backup config if not exists (or restore from backup to start fresh)
|
||||
if [ ! -f "$CONFIG_FILE.bak" ]; then
|
||||
cp "$CONFIG_FILE" "$CONFIG_FILE.bak"
|
||||
else
|
||||
cp "$CONFIG_FILE.bak" "$CONFIG_FILE"
|
||||
fi
|
||||
pushd ${target_dir} > /dev/null
|
||||
|
||||
# 1. app.config.js modifications
|
||||
echo "Updating app.config.js..."
|
||||
# Check if patch is already applied (reverse dry-run succeeds)
|
||||
if patch --dry-run -p1 -R < ${patch_file} > /dev/null 2>&1; then
|
||||
echo "✅ Already applied - skipping"
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Replace name
|
||||
sediment "s/name: 'Bluesky'/name: '$APP_NAME'/g" "$CONFIG_FILE"
|
||||
sediment "s/slug: 'bluesky'/slug: '$APP_SLUG'/g" "$CONFIG_FILE"
|
||||
sediment "s/scheme: 'bsky'/scheme: '$APP_SCHEME'/g" "$CONFIG_FILE"
|
||||
# Check if patch can be applied (forward dry-run succeeds)
|
||||
if patch --dry-run -p1 < ${patch_file} > /dev/null 2>&1; then
|
||||
echo "🔧 Applying patch..."
|
||||
if patch -p1 < ${patch_file}; then
|
||||
echo "✅ Applied successfully"
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 0
|
||||
else
|
||||
echo "❌ Failed to apply"
|
||||
FAILED_PATCHES+=("${patch_name} (${patch_file})")
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Cannot apply - file may have been modified"
|
||||
echo " Please check manually"
|
||||
FAILED_PATCHES+=("${patch_name} (${patch_file}) - file modified")
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Replace Bundle ID and App Group
|
||||
sediment "s/xyz.blueskyweb.app/$BUNDLE_ID/g" "$CONFIG_FILE"
|
||||
sediment "s/group.app.bsky/$APP_GROUP/g" "$CONFIG_FILE"
|
||||
function show-failed-patches() {
|
||||
if [ ${#FAILED_PATCHES[@]} -eq 0 ]; then
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "✅ All patches applied successfully!"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
return 0
|
||||
fi
|
||||
|
||||
# REMOVE App Clip Configuration (Critical for Personal Team Signing)
|
||||
# Use Python for safer multi-line removal than sed
|
||||
echo "Removing App Clip configuration..."
|
||||
python3 -c "
|
||||
import sys
|
||||
import re
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "⚠️ FAILED PATCHES SUMMARY"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "The following patches could not be applied:"
|
||||
echo ""
|
||||
for failed_patch in "${FAILED_PATCHES[@]}"; do
|
||||
echo " ❌ ${failed_patch}"
|
||||
done
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
}
|
||||
|
||||
try:
|
||||
with open('$CONFIG_FILE', 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
with open('$CONFIG_FILE', 'w') as f:
|
||||
skip = 0
|
||||
for i, line in enumerate(lines):
|
||||
if skip > 0:
|
||||
skip -= 1
|
||||
continue
|
||||
|
||||
# Remove the plugin import line
|
||||
if 'withStarterPackAppClip.js' in line:
|
||||
continue
|
||||
# Helper function for applying patches
|
||||
function patch-apply() {
|
||||
local name=$1
|
||||
local patch_file=$2
|
||||
apply-patch "${name}" "$target_dir" "$patching_dir/${patch_file}"
|
||||
}
|
||||
|
||||
# Check if this line defines the AppClip target
|
||||
# Structure we expect:
|
||||
# {
|
||||
# targetName: 'BlueskyClip',
|
||||
# ...
|
||||
# },
|
||||
# We look for the targetName, and if found, we attempt to remove the preceding '{' line if possible
|
||||
|
||||
if \"targetName: 'BlueskyClip'\" in line:
|
||||
# We found the target. We need to NOT write this line.
|
||||
# And we need to ensure the PREVIOUS line (which was '{') is not written?
|
||||
# Since we are writing sequentially, we can't pop easily unless we buffer.
|
||||
# Actually, simpler: Read file, modify list, write back.
|
||||
continue
|
||||
else:
|
||||
pass
|
||||
|
||||
# Retry with list manipulation approach
|
||||
out = []
|
||||
i = 0
|
||||
while i < len(lines):
|
||||
line = lines[i]
|
||||
|
||||
# Remove plugin import
|
||||
if 'withStarterPackAppClip.js' in line:
|
||||
i += 1
|
||||
continue
|
||||
|
||||
# Identify the block start
|
||||
# We look ahead. If lines[i] is '{' and lines[i+1] has 'BlueskyClip', we skip the block.
|
||||
if i + 1 < len(lines) and lines[i].strip() == '{' and \"targetName: 'BlueskyClip'\" in lines[i+1]:
|
||||
# Found the start of the block.
|
||||
# Skip until we find the closing '},'
|
||||
# Typical block is 4 lines.
|
||||
# {
|
||||
# targetName: 'BlueskyClip',
|
||||
# bundleIdentifier: ...,
|
||||
# },
|
||||
# We'll just skip 4 lines to be safe matching the observed file structure
|
||||
i += 4
|
||||
continue
|
||||
|
||||
out.append(line)
|
||||
i += 1
|
||||
|
||||
f.writelines(out)
|
||||
except Exception as e:
|
||||
print(f'Error processing file: {e}')
|
||||
sys.exit(1)
|
||||
"
|
||||
# Auto-apply patches from list
|
||||
function ios-patch-apply-all() {
|
||||
for filename in "${PATCH_FILES_IOS[@]}"; do
|
||||
local title="${filename%.*}"
|
||||
patch-apply "$title" "$filename"
|
||||
done
|
||||
}
|
||||
|
||||
# Inject NSAppTransportSecurity for development/preview (Allow Arbitrary Loads)
|
||||
if ! grep -q "NSAppTransportSecurity" "$CONFIG_FILE"; then
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
sed -i '' "/ios: {/a\\
|
||||
infoPlist: {\\
|
||||
NSAppTransportSecurity: {\\
|
||||
NSAllowsArbitraryLoads: true,\\
|
||||
},\\
|
||||
}," "$CONFIG_FILE"
|
||||
else
|
||||
sed -i "/ios: {/a\\
|
||||
infoPlist: {\\
|
||||
NSAppTransportSecurity: {\\
|
||||
NSAllowsArbitraryLoads: true,\\
|
||||
},\\
|
||||
}," "$CONFIG_FILE"
|
||||
fi
|
||||
fi
|
||||
# Copy new files that aren't in patches
|
||||
function ios-copy-new-files() {
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📁 Copying new files..."
|
||||
|
||||
# 2. constants.ts modifications
|
||||
echo "Updating constants.ts..."
|
||||
sediment "s|export const BSKY_SERVICE = 'https://bsky.social'|export const BSKY_SERVICE = '$SERVICE_URL'|g" "$CONSTANTS_FILE"
|
||||
sediment "s|export const BSKY_SERVICE_DID = 'did:web:bsky.social'|export const BSKY_SERVICE_DID = 'did:web:syu.is'|g" "$CONSTANTS_FILE"
|
||||
sediment "s|export const PUBLIC_BSKY_SERVICE = 'https://public.api.bsky.app'|export const PUBLIC_BSKY_SERVICE = 'https://bsky.syu.is'|g" "$CONSTANTS_FILE"
|
||||
sediment "s|const HELP_DESK_LANG = 'en-us'|const HELP_DESK_LANG = 'ja-jp'|g" "$CONSTANTS_FILE"
|
||||
sediment "s|export const HELP_DESK_URL = \`https://blueskyweb.zendesk.com/hc/\${HELP_DESK_LANG}\`|export const HELP_DESK_URL = '$HELP_URL'|g" "$CONSTANTS_FILE"
|
||||
# Copy License.tsx
|
||||
if [ -f "$patching_dir/License.tsx" ]; then
|
||||
mkdir -p "$target_dir/src/view/screens"
|
||||
cp "$patching_dir/License.tsx" "$target_dir/src/view/screens/License.tsx"
|
||||
echo "✅ Copied License.tsx"
|
||||
fi
|
||||
|
||||
# 3. Footer/Link replacements (Global text replacement for specific URLs)
|
||||
echo "Replacing links..."
|
||||
grep -r "https://bsky.social/about/blog" "$REPO_DIR/src" -l | xargs -I {} zsh -c "if [[ \"\$OSTYPE\" == \"darwin\"* ]]; then sed -i '' \"s|https://bsky.social/about/blog|$HELP_URL|g\" {}; else sed -i \"s|https://bsky.social/about/blog|$HELP_URL|g\" {}; fi"
|
||||
grep -r "https://bsky.social/about/blog/jobs" "$REPO_DIR/src" -l | xargs -I {} zsh -c "if [[ \"\$OSTYPE\" == \"darwin\"* ]]; then sed -i '' \"s|https://bsky.social/about/blog/jobs|$HELP_URL|g\" {}; else sed -i \"s|https://bsky.social/about/blog/jobs|$HELP_URL|g\" {}; fi"
|
||||
grep -r "/support/privacy" "$REPO_DIR/src" -l | xargs -I {} zsh -c "if [[ \"\$OSTYPE\" == \"darwin\"* ]]; then sed -i '' \"s|/support/privacy|$PRIVACY_URL|g\" {}; else sed -i \"s|/support/privacy|$PRIVACY_URL|g\" {}; fi"
|
||||
grep -r "/support/tos" "$REPO_DIR/src" -l | xargs -I {} zsh -c "if [[ \"\$OSTYPE\" == \"darwin\"* ]]; then sed -i '' \"s|/support/tos|$TERMS_URL|g\" {}; else sed -i \"s|/support/tos|$TERMS_URL|g\" {}; fi"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# 4. Icon replacement
|
||||
if [ -d "app-icons" ]; then
|
||||
echo "Updating icons from app-icons/ directory..."
|
||||
# Copy the entire contents of the user-provided app-icons directory to the repo's assets/app-icons
|
||||
# This covers all variants (Aurora, Bonfire, etc.) as the user has prepared them.
|
||||
cp -rf "app-icons/"* "$REPO_DIR/assets/app-icons/"
|
||||
|
||||
# Also update the main app icons referenced by default
|
||||
if [ -f "app-icons/ios_icon_default_next.png" ]; then
|
||||
cp "app-icons/ios_icon_default_next.png" "$REPO_DIR/assets/icon.png"
|
||||
cp "app-icons/ios_icon_default_next.png" "$REPO_DIR/assets/icon-android-notification.png"
|
||||
fi
|
||||
|
||||
# Force app.config.js to use the 'default_next' PNG instead of the complex .icon directory
|
||||
sediment "s|'./assets/app-icons/ios_icon_default.icon'|'./assets/app-icons/ios_icon_default_next.png'|g" "$CONFIG_FILE"
|
||||
function ios-setup-clone() {
|
||||
if [ ! -d $target_dir ]; then
|
||||
echo "Error: social-app repository not found at $target_dir"
|
||||
echo "Please run install.zsh first to clone repositories"
|
||||
return 1
|
||||
fi
|
||||
echo "Repository found: $target_dir"
|
||||
}
|
||||
|
||||
elif [ -f "icon.png" ]; then
|
||||
echo "Updating ALL icons from single icon.png..."
|
||||
# 1. Overwrite the files that app.config.js points to by default
|
||||
cp "icon.png" "$REPO_DIR/assets/icon.png"
|
||||
cp "icon.png" "$REPO_DIR/assets/icon-android-notification.png"
|
||||
|
||||
# 2. Overwrite ALL icons in app-icons/ since no specific set was provided
|
||||
echo "Overwriting all assets/app-icons/*.png..."
|
||||
find "$REPO_DIR/assets/app-icons" -name "*.png" -exec cp "icon.png" {} \;
|
||||
|
||||
# 3. Handle ios_icon_default.icon special case
|
||||
TARGET_ICON_DIR="$REPO_DIR/assets/app-icons/ios_icon_default.icon"
|
||||
if [ -d "$TARGET_ICON_DIR" ]; then
|
||||
cp "icon.png" "$TARGET_ICON_DIR/icon.png" 2>/dev/null || true
|
||||
fi
|
||||
function ios-setup-reset() {
|
||||
echo "Resetting social-app repository..."
|
||||
cd $target_dir
|
||||
git stash
|
||||
git checkout .
|
||||
echo "Reset complete"
|
||||
}
|
||||
|
||||
# 4. Force app.config.js to point to PNG
|
||||
sediment "s|'./assets/app-icons/ios_icon_default.icon'|'./assets/app-icons/ios_icon_default_next.png'|g" "$CONFIG_FILE"
|
||||
fi
|
||||
# Main execution
|
||||
ios-env
|
||||
|
||||
# 5. Build Fixes (Entitlements and NSE Sounds)
|
||||
echo "Applying build fixes..."
|
||||
|
||||
# Fix 1: Create Config Plugin to Allow Entitlements Modification
|
||||
cat <<EOF > "$REPO_DIR/plugins/withCodeSignEntitlements.js"
|
||||
const { withXcodeProject } = require('expo/config-plugins');
|
||||
|
||||
module.exports = function withCodeSignEntitlements(config) {
|
||||
return withXcodeProject(config, (config) => {
|
||||
const xcodeProject = config.modResults;
|
||||
const configurations = xcodeProject.pbxXCBuildConfigurationSection();
|
||||
for (const key in configurations) {
|
||||
const buildSettings = configurations[key].buildSettings;
|
||||
if (buildSettings) {
|
||||
buildSettings['CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION'] = 'YES';
|
||||
}
|
||||
}
|
||||
return config;
|
||||
});
|
||||
};
|
||||
EOF
|
||||
|
||||
# Register the plugin in app.config.js
|
||||
# We insert it into the plugins array. Finding a safe anchor.
|
||||
# 'expo-video' is in the plugins array.
|
||||
sediment "s/'expo-video',/'expo-video', '.\/plugins\/withCodeSignEntitlements.js',/g" "$CONFIG_FILE"
|
||||
|
||||
|
||||
# Fix 2: Disable soundFiles in Notification Extension to avoid 'no rule to process dm.aiff'
|
||||
# The main app handles sounds via expo-notifications. The extension adding it as a source fails.
|
||||
NOTIF_EXT_FILE="$REPO_DIR/plugins/notificationsExtension/withNotificationsExtension.js"
|
||||
if [ -f "$NOTIF_EXT_FILE" ]; then
|
||||
echo "Patching withNotificationsExtension.js..."
|
||||
sediment "s/const soundFiles = \['dm.aiff'\]/const soundFiles = []/g" "$NOTIF_EXT_FILE"
|
||||
fi
|
||||
|
||||
echo "Setup complete. App Clip configuration removed. Build fixes applied."
|
||||
case "$1" in
|
||||
patch)
|
||||
ios-setup-clone
|
||||
ios-patch-apply-all
|
||||
ios-copy-new-files
|
||||
show-failed-patches
|
||||
exit
|
||||
;;
|
||||
reset)
|
||||
ios-setup-reset
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
ios-setup-clone
|
||||
ios-patch-apply-all
|
||||
ios-copy-new-files
|
||||
show-failed-patches
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user