feat: add custom CEF V8 extensions support (#17)
* feat: Register extensions in render process - Add CefExtensions type to hold V8 extension code - Pass extensions through BrowserProcessAppBuilder - Register extensions in RenderProcessHandler on WebKit initialization - Decode JSON extensions from command line switch - Prefix extension names with "v8/" per CEF convention - Include actual JSON in error messages for debugging l * feat: refactor window.cef API and register as CEF extension * fix: remove debug print statements in render process handler * refactor: centralize EXTENSIONS_SWITCH constant in util.rs * fmt * refactor: implement Default trait for CefApiHandler * docs: add documentation for CefApiHandler and its JavaScript API functions --------- Co-authored-by: not-elm <elmgameinfo@gmail.com>
This commit is contained in:
39
assets/extensions.html
Normal file
39
assets/extensions.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CEF Extensions Example</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 20px; background: #1a1a2e; color: #eee; }
|
||||
button { padding: 10px 20px; margin: 5px; cursor: pointer; }
|
||||
#output { margin-top: 20px; padding: 10px; background: #16213e; border-radius: 5px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CEF Extensions Example</h1>
|
||||
<p>Testing custom JavaScript extensions registered via register_extension.</p>
|
||||
|
||||
<button onclick="testExtension()">Test myGame.sendScore()</button>
|
||||
<button onclick="checkVersion()">Check Version</button>
|
||||
|
||||
<div id="output">Output will appear here...</div>
|
||||
|
||||
<script>
|
||||
function testExtension() {
|
||||
if (typeof myGame !== 'undefined') {
|
||||
myGame.sendScore(Math.floor(Math.random() * 100));
|
||||
document.getElementById('output').innerHTML = 'Score sent! Check Bevy console.';
|
||||
} else {
|
||||
document.getElementById('output').innerHTML = 'Error: myGame extension not found';
|
||||
}
|
||||
}
|
||||
|
||||
function checkVersion() {
|
||||
if (typeof myGame !== 'undefined' && myGame.version) {
|
||||
document.getElementById('output').innerHTML = 'myGame version: ' + myGame.version;
|
||||
} else {
|
||||
document.getElementById('output').innerHTML = 'Error: myGame.version not found';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -15,7 +15,7 @@
|
||||
<h1 id="count" style="color: aqua">0</h1>
|
||||
<script>
|
||||
const count = document.getElementById("count");
|
||||
window.cef.listen("count", (payload) => {
|
||||
cef.listen("count", (payload) => {
|
||||
count.innerText = payload;
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
let count = 0;
|
||||
window.setInterval(() => {
|
||||
console.log("Emitting count:", count);
|
||||
window.cef.emit({
|
||||
cef.emit({
|
||||
count,
|
||||
});
|
||||
countElement.innerText = count;
|
||||
|
||||
Reference in New Issue
Block a user