mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 18:13:25 +00:00
feat: background download plugin and dep
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { ExpoConfig } from "expo/config";
|
import type { ExpoConfig } from "expo/config";
|
||||||
|
|
||||||
import withRemoveiOSNotificationEntitlement from "./config-plugins/withRemoveiOSNotificationEntitlement";
|
import withRemoveiOSNotificationEntitlement from "./config-plugins/withRemoveiOSNotificationEntitlement";
|
||||||
|
import withRNBackgroundDownloader from "./config-plugins/withRNBackgroundDownloader";
|
||||||
import { version } from "./package.json";
|
import { version } from "./package.json";
|
||||||
|
|
||||||
const defineConfig = (): ExpoConfig => ({
|
const defineConfig = (): ExpoConfig => ({
|
||||||
@@ -49,6 +50,7 @@ const defineConfig = (): ExpoConfig => ({
|
|||||||
plugins: [
|
plugins: [
|
||||||
"expo-router",
|
"expo-router",
|
||||||
[withRemoveiOSNotificationEntitlement as unknown as string],
|
[withRemoveiOSNotificationEntitlement as unknown as string],
|
||||||
|
[withRNBackgroundDownloader as unknown as string],
|
||||||
[
|
[
|
||||||
"expo-screen-orientation",
|
"expo-screen-orientation",
|
||||||
{
|
{
|
||||||
|
48
apps/expo/config-plugins/withRNBackgroundDownloader.js
Normal file
48
apps/expo/config-plugins/withRNBackgroundDownloader.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
const { withAppDelegate } = require("@expo/config-plugins");
|
||||||
|
|
||||||
|
function withRNBackgroundDownloader(expoConfig) {
|
||||||
|
return withAppDelegate(expoConfig, async (appDelegateConfig) => {
|
||||||
|
const { modResults: appDelegate } = appDelegateConfig;
|
||||||
|
const appDelegateLines = appDelegate.contents.split("\n");
|
||||||
|
|
||||||
|
// Define the code to be added to AppDelegate.mm
|
||||||
|
const backgroundDownloaderImport =
|
||||||
|
"#import <RNBackgroundDownloader.h> // Required by react-native-background-downloader. Generated by expoPlugins/withRNBackgroundDownloader.js";
|
||||||
|
const backgroundDownloaderDelegate = `\n// Delegate method required by react-native-background-downloader. Generated by expoPlugins/withRNBackgroundDownloader.js
|
||||||
|
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
|
||||||
|
{
|
||||||
|
[RNBackgroundDownloader setCompletionHandlerWithIdentifier:identifier completionHandler:completionHandler];
|
||||||
|
}`;
|
||||||
|
|
||||||
|
// Find the index of the AppDelegate import statement
|
||||||
|
const importIndex = appDelegateLines.findIndex((line) =>
|
||||||
|
/^#import "AppDelegate.h"/.test(line),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Find the index of the last line before the @end statement
|
||||||
|
const endStatementIndex = appDelegateLines.findIndex((line) =>
|
||||||
|
/@end/.test(line),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Insert the import statement if it's not already present
|
||||||
|
if (!appDelegate.contents.includes(backgroundDownloaderImport)) {
|
||||||
|
appDelegateLines.splice(importIndex + 1, 0, backgroundDownloaderImport);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the delegate method above the @end statement
|
||||||
|
if (!appDelegate.contents.includes(backgroundDownloaderDelegate)) {
|
||||||
|
appDelegateLines.splice(
|
||||||
|
endStatementIndex,
|
||||||
|
0,
|
||||||
|
backgroundDownloaderDelegate,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the contents of the AppDelegate file
|
||||||
|
appDelegate.contents = appDelegateLines.join("\n");
|
||||||
|
|
||||||
|
return appDelegateConfig;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = withRNBackgroundDownloader;
|
@@ -19,6 +19,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/metro-config": "^0.17.3",
|
"@expo/metro-config": "^0.17.3",
|
||||||
|
"@kesha-antonov/react-native-background-downloader": "^3.1.2",
|
||||||
"@movie-web/api": "*",
|
"@movie-web/api": "*",
|
||||||
"@movie-web/colors": "*",
|
"@movie-web/colors": "*",
|
||||||
"@movie-web/provider-utils": "*",
|
"@movie-web/provider-utils": "*",
|
||||||
|
584
pnpm-lock.yaml
generated
584
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user