Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions apps/mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"android": { "package": "app.openmuse.mobile" },
"web": { "bundler": "metro", "name": "OpenMuse — a little room for everything" },
"plugins": [
"./plugins/withIOSSceneLifecycle",
"expo-document-picker",
"@config-plugins/react-native-blob-util",
"@config-plugins/react-native-pdf"
Expand Down
62 changes: 62 additions & 0 deletions apps/mobile/plugins/withIOSSceneLifecycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const fs = require("node:fs");
const path = require("node:path");
const { withDangerousMod, withInfoPlist, withXcodeProject } = require("expo/config-plugins");

const sceneDelegate = `import UIKit

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] This UIWindowSceneDelegate only attaches the window and does not forward cold-start connectionOptions or subsequent scene URL events. After adopting scenes UIKit stops invoking application(_:open:options:), which the generated AppDelegate/Expo dev-launcher currently uses. Preserve cold/warm URL and user-activity delivery when migrating; see Expo's guide: https://github.com/expo/fyi/blob/main/ios-scene-lifecycle.md. Validate development-client launch links on the migrated project.

var window: UIWindow?

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = scene as? UIWindowScene else { return }
guard let appWindow = (UIApplication.shared.delegate as? AppDelegate)?.window else { return }
appWindow.windowScene = windowScene
window = appWindow
appWindow.makeKeyAndVisible()
}
}
`;

function withIOSSceneLifecycle(config) {
config = withInfoPlist(config, (mod) => {
mod.modResults.UIApplicationSceneManifest = {
UIApplicationSupportsMultipleScenes: false,
UISceneConfigurations: {
UIWindowSceneSessionRoleApplication: [
{
UISceneConfigurationName: "Default Configuration",
UISceneDelegateClassName: "$(PRODUCT_MODULE_NAME).SceneDelegate",
},
],
},
};
return mod;
});

config = withDangerousMod(config, [
"ios",
async (mod) => {
const filePath = path.join(
mod.modRequest.platformProjectRoot,
mod.modRequest.projectName,
"SceneDelegate.swift",
);
fs.writeFileSync(filePath, sceneDelegate);
return mod;
},
]);

return withXcodeProject(config, (mod) => {
const project = mod.modResults;
const target = project.getFirstTarget();
if (!project.hasFile("OpenMuse/SceneDelegate.swift"))
project.addSourceFile("OpenMuse/SceneDelegate.swift", { target: target.uuid }, "OpenMuse");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] node-xcode expects the PBX group UUID as addSourceFile's third argument, not the display name 'OpenMuse'. In a fresh Expo iOS prebuild this invokes getPBXVariantGroupByKey('OpenMuse') and throws Cannot read properties of undefined (reading 'OpenMuse'), blocking native project generation. The same clean prebuild passes when only this plugin is removed. Resolve the actual project group key and add clean-prebuild regression/validation.

return mod;
});
}

module.exports = withIOSSceneLifecycle;
Loading