fix(composer): runtime migration
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
export const jsx = require('composer_core/src/JSX').jsx;
|
||||
export const assetCatalog = require("composer_core/src/AssetCatalog")
|
||||
export const style = require("composer_core/src/Style");
|
||||
import { runtimeName } from "./imports"
|
||||
|
||||
export const jsx = require(runtimeName + '_core/src/JSX').jsx;
|
||||
export const assetCatalog = require(runtimeName + "_core/src/AssetCatalog")
|
||||
export const style = require(runtimeName + "_core/src/Style");
|
||||
export const colors = require("coreui/src/styles/semanticColors");
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Config, FriendInfo } from "./types";
|
||||
|
||||
declare var _getImportsFunctionName: string;
|
||||
const remoteImports = require('composer_core/src/DeviceBridge')[_getImportsFunctionName]();
|
||||
declare var _runtimeName: boolean;
|
||||
export const runtimeName = _runtimeName;
|
||||
|
||||
const remoteImports = require(_runtimeName + '_core/src/DeviceBridge')[_getImportsFunctionName]();
|
||||
|
||||
function callRemoteFunction(method: string, ...args: any[]): any | null {
|
||||
return remoteImports[method](...args);
|
||||
|
||||
@@ -104,6 +104,8 @@ class ComposerHooks: Feature("ComposerHooks") {
|
||||
override fun init() {
|
||||
if (config.globalState != true) return
|
||||
|
||||
val nativeBridgeClass = runCatching { findClass("com.snapchat.client.valdi.NativeBridge") }.getOrNull() ?: findClass("com.snapchat.client.composer.NativeBridge")
|
||||
|
||||
val importedFunctions = mutableMapOf<String, Any?>()
|
||||
|
||||
fun composerFunction(name: String, block: ComposerMarshaller.() -> Unit) {
|
||||
@@ -172,7 +174,8 @@ class ComposerHooks: Feature("ComposerHooks") {
|
||||
context.native.setComposerLoader("""
|
||||
const i = setInterval(() => {
|
||||
try {
|
||||
require('composer_core/src/DeviceBridge').getDisplayWidth();
|
||||
const _runtimeName = "${if (nativeBridgeClass.name == "com.snapchat.client.valdi.NativeBridge") "valdi" else "composer"}";
|
||||
require(_runtimeName + '_core/src/DeviceBridge').getDisplayWidth();
|
||||
clearInterval(i);
|
||||
(() => { const _getImportsFunctionName = "$getImportsFunctionName"; $loaderScript })();
|
||||
} catch (e) {}
|
||||
@@ -195,16 +198,14 @@ class ComposerHooks: Feature("ComposerHooks") {
|
||||
}
|
||||
}
|
||||
|
||||
findClass("com.snapchat.client.composer.NativeBridge").apply {
|
||||
hook("registerNativeModuleFactory", HookStage.BEFORE) { param ->
|
||||
val moduleFactory = param.argNullable<Any>(1) ?: return@hook
|
||||
if (moduleFactory.javaClass.getMethod("getModulePath").invoke(moduleFactory)?.toString()?.contains("DeviceBridge") != true) return@hook
|
||||
Hooker.ephemeralHookObjectMethod(moduleFactory.javaClass, moduleFactory, "loadModule", HookStage.AFTER) { methodParam ->
|
||||
val result = methodParam.getResult() as? MutableMap<String, Any?> ?: return@ephemeralHookObjectMethod
|
||||
result[getImportsFunctionName] = newComposerFunction {
|
||||
pushUntyped(importedFunctions)
|
||||
true
|
||||
}
|
||||
nativeBridgeClass.hook("registerNativeModuleFactory", HookStage.BEFORE) { param ->
|
||||
val moduleFactory = param.argNullable<Any>(1) ?: return@hook
|
||||
if (moduleFactory.javaClass.getMethod("getModulePath").invoke(moduleFactory)?.toString()?.contains("DeviceBridge") != true) return@hook
|
||||
Hooker.ephemeralHookObjectMethod(moduleFactory.javaClass, moduleFactory, "loadModule", HookStage.AFTER) { methodParam ->
|
||||
val result = methodParam.getResult() as? MutableMap<String, Any?> ?: return@ephemeralHookObjectMethod
|
||||
result[getImportsFunctionName] = newComposerFunction {
|
||||
pushUntyped(importedFunctions)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user