Skip to content

Instantly share code, notes, and snippets.

@dmjio
Last active August 30, 2025 13:52
Show Gist options
  • Save dmjio/f3092fcd7ad16b92f82e966e12b4fbcf to your computer and use it in GitHub Desktop.
Save dmjio/f3092fcd7ad16b92f82e966e12b4fbcf to your computer and use it in GitHub Desktop.
initBackground();
globalThis['renderPage'] = function () {
console.log('in main');
console.log('getting global emitter in main should fail', 'getJSModule' in lynx);
const context = lynx.getJSContext();
console.log('js context', context);
// dmj: this works
context.addEventListener("message", (event) => {
console.log('got event in js context', event);
});
context.postMessage({ main : 'main' });
lynx.requestAnimationFrame(step);
}
function initBackground () {
'background only'
console.log('in bg');
console.log('getting global emitter in bg should work', lynx.getJSModule('GlobalEventEmitter'));
const coreContext = lynx.getCoreContext();
coreContext.addEventListener("message", (event) => {
console.log('got event in core context, sending event back to main thread', event);
coreContext.postMessage({ bg: 'bg' });
});
lynx.requestAnimationFrame(step);
}
// dmj: looping
function step (frame) {
lynx.requestAnimationFrame(step);
}
// dmj: need this
globalThis['processData'] = function () {
}
// dmj: this might need to be configured differently
globalThis['runWorklet'] = (worklet, params) => {
return worklet(params);
}
import { defineConfig } from '@lynx-js/rspeedy'
import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin'
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
export default defineConfig({
plugins: [
pluginQRCode({
schema(url) {
// We use `?fullscreen=true` to open the page in LynxExplorer in full screen mode
return `${url}?fullscreen=true`
},
}),
pluginReactLynx(),
],
})
{
"name": "sphynx",
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "rspeedy build",
"dev": "rspeedy dev",
"preview": "rspeedy preview",
"test": "vitest run"
},
"dependencies": {
"@lynx-js/react": "^0.112.4"
},
"devDependencies": {
"@lynx-js/preact-devtools": "^5.0.1-6664329",
"@lynx-js/qrcode-rsbuild-plugin": "^0.4.1",
"@lynx-js/react-rsbuild-plugin": "^0.10.13",
"@lynx-js/rspeedy": "^0.10.8",
"@lynx-js/types": "3.3.0",
"@rsbuild/plugin-type-check": "1.2.4",
"@testing-library/jest-dom": "^6.8.0",
"@types/react": "^18.3.23",
"jsdom": "^26.1.0",
"typescript": "~5.9.2",
"vitest": "^3.2.4"
},
"engines": {
"node": ">=18"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment