Skip to content

Commit

Permalink
Merge pull request #23 from bunny-mod/feat-safari-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
castdrian authored Nov 16, 2024
2 parents 9b645f8 + 072bfff commit 834a8db
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 266 deletions.
14 changes: 14 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BasedOnStyle: LLVM
IndentWidth: 4
ObjCBlockIndentWidth: 4
UseTab: Never
ColumnLimit: 100
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
AlignConsecutiveAssignments: Consecutive
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Build Validation

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build-check:
name: Build Check
uses: ./.github/workflows/deploy.yml
with:
caller_workflow: ci
secrets: inherit
100 changes: 66 additions & 34 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
name: Deploy
name: Deploy Build
run-name: ${{ github.event.inputs.release == 'true' && 'Release' || 'Build' }} for ${{ github.event.inputs.ipa_url }}

on:
workflow_dispatch:
workflow_dispatch:
inputs:
ipa_url:
description: "Direct link to the decrypted IPA"
default: ""
required: true
type: string
release:
description: 'Release the build'
required: true
type: boolean
ipa_url:
description: "Direct link to the decrypted IPA"
default: ""
required: true
type: string
release:
description: "Release the build"
required: true
type: boolean
workflow_call:
inputs:
caller_workflow:
required: false
type: string

env:
GH_TOKEN: ${{ github.token }}


jobs:
build-tweak:
runs-on: macos-14
runs-on: macos-15

env:
DEB_DOWNLOADED: false

steps:
- name: Checkout code
Expand All @@ -29,6 +36,7 @@ jobs:
submodules: true

- name: Download Tweak
if: inputs.caller_workflow != 'ci'
run: |
set +e
Expand All @@ -45,7 +53,7 @@ jobs:
release_version=$(echo "$release_info" | jq -r '.assets[] | select(.name | contains("iphoneos-arm.deb")) | .name' | grep -o '_[0-9.]\+_' | tr -d '_')
control_version=$(grep '^Version:' control | cut -d ' ' -f 2)
if [ "$release_version" = "$control_version" ]; then
echo "Versions match. Downloading DEB files..."
echo "$release_info" | jq -r '.assets[] | select(.name | endswith(".deb")) | .browser_download_url' | xargs -I {} curl -L -O {}
Expand All @@ -55,7 +63,7 @@ jobs:
echo "DEB_DOWNLOADED=false" >> $GITHUB_ENV
exit 0
fi
- name: Check cache
if: env.DEB_DOWNLOADED == 'false'
run: echo upstream_heads=`git ls-remote https://github.com/theos/theos | head -n 1 | cut -f 1`-`git ls-remote https://github.com/theos/sdks | head -n 1 | cut -f 1` >> $GITHUB_ENV
Expand Down Expand Up @@ -83,11 +91,11 @@ jobs:
- name: Set DEB path
run: |
if [ "${{ env.DEB_DOWNLOADED }}" == "true" ]; then
echo "DEB_PATH=${{ github.workspace }}/*-arm.deb" >> $GITHUB_ENV
echo "ROOTLESS_DEB_PATH=${{ github.workspace }}/*-arm64.deb" >> $GITHUB_ENV
echo "DEB_PATH=*-arm.deb" >> $GITHUB_ENV
echo "ROOTLESS_DEB_PATH=*-arm64.deb" >> $GITHUB_ENV
else
echo "DEB_PATH=${{ github.workspace }}/packages/*-arm.deb" >> $GITHUB_ENV
echo "ROOTLESS_DEB_PATH=${{ github.workspace }}/packages/*-arm64.deb" >> $GITHUB_ENV
echo "DEB_PATH=packages/*-arm.deb" >> $GITHUB_ENV
echo "ROOTLESS_DEB_PATH=packages/*-arm64.deb" >> $GITHUB_ENV
fi
- name: Upload package
Expand All @@ -103,13 +111,14 @@ jobs:
path: ${{ env.ROOTLESS_DEB_PATH }}

build-ipa:
runs-on: macos-14
if: inputs.caller_workflow != 'ci'
runs-on: macos-15
needs: build-tweak

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -123,6 +132,30 @@ jobs:
run: |
curl -L -o ipa-icons.zip https://raw.githubusercontent.com/pyoncord/assets/main/ipa-icons.zip
- name: Clone OpenInDiscord
uses: actions/checkout@v4
with:
repository: castdrian/OpenInDiscord
path: OpenInDiscord

- name: Build Safari Extension
run: |
cd OpenInDiscord
xcodebuild build \
-target "OpenInDiscord Extension" \
-configuration Release \
-sdk iphoneos \
CONFIGURATION_BUILD_DIR="build" \
PRODUCT_NAME="OpenInDiscord" \
PRODUCT_BUNDLE_IDENTIFIER="com.hammerandchisel.discord.OpenInDiscord" \
PRODUCT_MODULE_NAME="OpenInDiscordExt" \
SKIP_INSTALL=NO \
DEVELOPMENT_TEAM="" \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
ONLY_ACTIVE_ARCH=NO | xcbeautify
- name: Extract Values
run: |
NAME=$(grep '^Name:' control | cut -d ' ' -f 2)
Expand All @@ -133,37 +166,37 @@ jobs:
ROOTLESS_DEB_FILE_NAME="${PACKAGE}_${VERSION}_iphoneos-arm64.deb"
echo "ROOTLESS_DEB_FILE_NAME=$ROOTLESS_DEB_FILE_NAME" >> $GITHUB_ENV
echo "APP_NAME=$NAME" >> $GITHUB_ENV
- name: Run patcher
run: |
curl -L -o patcher https://github.com/amsyarasyiq/bunny-ipa-patcher/releases/download/release-pyon/patcher.mac-amd64
chmod +x patcher
./patcher -d discord.ipa -o discord.ipa -i ./ipa-icons.zip
- name: Install cyan
run: pip install --force-reinstall https://github.com/asdfzxcvbn/pyzule-rw/archive/main.zip Pillow

- name: Inject tweak
- name: Inject tweak and extension
run: |
cyan -duws -i discord.ipa -o ${{ github.workspace }}/${{ env.APP_NAME }}.ipa -f ${{ github.workspace }}/${{ env.DEB_FILE_NAME }}
cyan -duws -i discord.ipa -o ${{ env.APP_NAME }}.ipa -f ${{ env.DEB_FILE_NAME }} OpenInDiscord/build/OpenInDiscord.appex
- name: Upload ipa as artifact
uses: actions/upload-artifact@v4
with:
name: ipa
path: ${{ github.workspace }}/${{ env.APP_NAME }}.ipa
name: ipa
path: ${{ env.APP_NAME }}.ipa

release-app:
if: ${{ github.event.inputs.release == 'true' }}
runs-on: macos-14
if: inputs.caller_workflow != 'ci' && github.event.inputs.release == 'true'
runs-on: macos-15
needs: build-ipa
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract Values
run: |
NAME=$(grep '^Name:' control | cut -d ' ' -f 2)
Expand Down Expand Up @@ -201,9 +234,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

app-repo:
if: ${{ github.event.inputs.release == 'true' }}
if: inputs.caller_workflow != 'ci' && github.event.inputs.release == 'true'
continue-on-error: true
runs-on: macos-14
runs-on: macos-15
needs: release-app
steps:
- name: Checkout code
Expand All @@ -227,10 +260,9 @@ jobs:
DOWNLOAD_URL=https://github.com/${{ github.repository }}/releases/download/v$VERSION/${{ env.APP_NAME }}.ipa
NEW_ENTRY=$(jq -n --arg version "$VERSION" --arg date "$DATE" --arg size "$IPA_SIZE" --arg downloadURL "$DOWNLOAD_URL" '{version: $version, date: $date, size: ($size | tonumber), downloadURL: $downloadURL}')
jq --argjson newEntry "$NEW_ENTRY" '.apps[0].versions |= [$newEntry] + .' app-repo.json > temp.json && mv temp.json app-repo.json
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "chore: update app-repo.json"
add: app-repo.json

9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"tale.logos-vscode",
"spencerwmiles.vscode-task-buttons",
"redhat.vscode-yaml",
"davidanson.vscode-markdownlint",
"SteefH.external-formatters"
]
}
64 changes: 64 additions & 0 deletions .vscode/logos-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
import re
from subprocess import Popen, PIPE, STDOUT

# block level
# hook -> replace with @logosformathook with ; at the end
# end -> replace with @logosformatend with ; at the end
# property -> replace with @logosformatproperty with NO ; at the end. Special case for block level
# new -> replce with @logosformatnew with ; at the end
# group -> replace with @logosformatgroup with ; at the end
# subclass -> replace with @logosformatsubclass with ; at the end
# top level
# config -> replace with @logosformatconfig
# hookf -> replace with @logosformathookf
# ctor -> replace with @logosformatctor
# dtor -> replace with @logosformatdtor

# function level
# init -> replace with @logosformatinit
# c -> replace with @logosformatc
# orig -> replace with @logosformatorig
# log -> replace with @logosformatlog

specialFilterList = ["%hook", "%end", "%new", "%group", "%subclass"]
filterList = [
"%property",
"%config",
"%hookf",
"%ctor",
"%dtor",
"%init",
"%c",
"%orig",
"%log",
]


fileContentsList = sys.stdin.read().splitlines()
newList = []

for line in fileContentsList:
for token in filterList:
if token in line:
line = re.sub(rf"%({token[1:]})\b", r"@logosformat\1", line)
for token in specialFilterList:
if token in line:
line = re.sub(rf"%({token[1:]})\b", r"@logosformat\1", line) + ";"
newList.append(line)

command = ["clang-format"] + sys.argv[1:]
process = Popen(command, stdout=PIPE, stderr=None, stdin=PIPE)
stdoutData = process.communicate(input="\n".join(newList).encode())[0]
refinedList = stdoutData.decode().splitlines()


for line in refinedList:
if "@logosformat" in line:
fix = line.replace("@logosformat", "%")
if any(token in fix for token in specialFilterList):
print(fix.replace(";",""))
else:
print(fix)
else:
print(line)
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,25 @@
"tooltip": "Make and copy Tweak"
}
],
}
"externalFormatters.languages": {
"logos": {
"command": "python3",
"arguments": [
"../.vscode/logos-format.py",
"--assume-filename",
"objc"
]
}
},
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": [
"*.github/workflows/*.yaml",
"*.github/workflows/*.yml",
],
"https://json.schemastore.org/github-action.json": [
"action.yaml",
"action.yml",
]
},
"editor.formatOnSave": true
}
2 changes: 1 addition & 1 deletion Headers/Fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#import <UIKit/UIKit.h>

extern NSMutableDictionary<NSString *, NSString *> *fontMap;
void patchFonts(NSDictionary<NSString *, NSString *> *mainFonts, NSString *fontDefName);
void patchFonts(NSDictionary<NSString *, NSString *> *mainFonts, NSString *fontDefName);
6 changes: 3 additions & 3 deletions Headers/LoaderConfig.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#import <Foundation/Foundation.h>

@interface LoaderConfig : NSObject
@property (nonatomic, assign) BOOL customLoadUrlEnabled;
@property (nonatomic, strong) NSURL *customLoadUrl;
@property(nonatomic, assign) BOOL customLoadUrlEnabled;
@property(nonatomic, strong) NSURL *customLoadUrl;
+ (instancetype)defaultConfig;
+ (instancetype)getLoaderConfig;
- (instancetype)init;
- (BOOL)loadConfig;
@end
@end
2 changes: 1 addition & 1 deletion Headers/RCTCxxBridge.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@interface RCTCxxBridge : NSObject
- (void)executeApplicationScript:(NSData *)script url:(NSURL *)url async:(BOOL)async;
@end
@end
2 changes: 1 addition & 1 deletion Headers/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#import <UIKit/UIKit.h>

void swizzleDCDThemeColor(NSDictionary<NSString *, NSArray<NSString *> *> *semanticColors);
void swizzleUIColor(NSDictionary<NSString *, NSString *> *rawColors);
void swizzleUIColor(NSDictionary<NSString *, NSString *> *rawColors);
Loading

0 comments on commit 834a8db

Please sign in to comment.