mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
Co-authored-by: lostb1t <coding-mosses0z@icloud.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com> Co-authored-by: Gauvino <uruknarb20@gmail.com> Co-authored-by: storm1er <le.storm1er@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com> Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com> Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
const { withAppDelegate, withXcodeProject } = require("@expo/config-plugins");
|
||
const fs = require("node:fs");
|
||
const path = require("node:path");
|
||
|
||
/** @param {import("@expo/config-plugins").ExpoConfig} config */
|
||
function withRNBackgroundDownloader(config) {
|
||
/* 1️⃣ Add handleEventsForBackgroundURLSession to AppDelegate.swift */
|
||
config = withAppDelegate(config, (mod) => {
|
||
const tag = "handleEventsForBackgroundURLSession";
|
||
if (!mod.modResults.contents.includes(tag)) {
|
||
mod.modResults.contents = mod.modResults.contents.replace(
|
||
/\}\s*$/, // insert before final }
|
||
`
|
||
func application(
|
||
_ application: UIApplication,
|
||
handleEventsForBackgroundURLSession identifier: String,
|
||
completionHandler: @escaping () -> Void
|
||
) {
|
||
RNBackgroundDownloader.setCompletionHandlerWithIdentifier(identifier, completionHandler: completionHandler)
|
||
}
|
||
}`,
|
||
);
|
||
}
|
||
return mod;
|
||
});
|
||
|
||
/* 2️⃣ Ensure bridging header exists & is attached to *every* app target */
|
||
config = withXcodeProject(config, (mod) => {
|
||
const project = mod.modResults;
|
||
const projectName = config.name || "App";
|
||
// Fix: Go up one more directory to get to ios/, not ios/ProjectName.xcodeproj/
|
||
const iosDir = path.dirname(path.dirname(project.filepath));
|
||
const headerRel = `${projectName}/${projectName}-Bridging-Header.h`;
|
||
const headerAbs = path.join(iosDir, headerRel);
|
||
|
||
// create / append import if missing
|
||
let headerText = "";
|
||
try {
|
||
headerText = fs.readFileSync(headerAbs, "utf8");
|
||
} catch (error) {
|
||
if (error.code !== "ENOENT") {
|
||
throw error;
|
||
}
|
||
}
|
||
if (!headerText.includes("RNBackgroundDownloader.h")) {
|
||
fs.mkdirSync(path.dirname(headerAbs), { recursive: true });
|
||
fs.appendFileSync(headerAbs, '#import "RNBackgroundDownloader.h"\n');
|
||
}
|
||
|
||
// Expo 53's xcode‑js doesn't expose pbxTargets().
|
||
// Setting the property once at the project level is sufficient.
|
||
["Debug", "Release"].forEach((cfg) => {
|
||
project.updateBuildProperty(
|
||
"SWIFT_OBJC_BRIDGING_HEADER",
|
||
"Streamyfin/Streamyfin-Bridging-Header.h",
|
||
cfg,
|
||
);
|
||
});
|
||
|
||
return mod;
|
||
});
|
||
|
||
return config;
|
||
}
|
||
|
||
module.exports = withRNBackgroundDownloader;
|