Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove menu bar on clients in local testing server #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
79 changes: 78 additions & 1 deletion extensions/THNK_Local.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,83 @@
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": "// Load THNK Local Adapter (https://github.com/arthuro555/THNK)\n\"use strict\";\n(() => {\n // code/adapters/local.ts\n if(!window.THNK)window.THNK={};let THNK=window.THNK;\n ((THNK2) => {\n const logger = new gdjs.Logger(\"THNK - Local Testing Adapter\");\n if (!globalThis.BroadcastChannel)\n logger.error(\n \"This browser does not support the local adapter - please try using another adapter! (Prepare for an error)\"\n );\n const bc = new BroadcastChannel(\"thnk-local-server\");\n bc.addEventListener(\n \"messageerror\",\n (e) => logger.error(\"An error occured while sending a message!\", e)\n );\n const ownID = \"\" + Date.now() + Math.random() * 1e3;\n class LocalClientAdapter extends THNK2.ClientAdapter {\n onBCMessage({ data }) {\n if (data.message === \"msg-for-client\" && data.for === ownID)\n this.onMessage(data.data);\n }\n boundOnBCMessage = this.onBCMessage.bind(this);\n async prepare(runtimeScene) {\n bc.addEventListener(\"message\", this.boundOnBCMessage);\n bc.postMessage({ message: \"connect\", from: ownID });\n window.addEventListener(\"beforeunload\", () => this.close());\n }\n close() {\n bc.postMessage({ message: \"disconnect\", from: ownID });\n bc.removeEventListener(\"message\", this.boundOnBCMessage);\n }\n doSendMessage(message) {\n bc.postMessage({\n message: \"msg-for-server\",\n data: message,\n from: ownID\n });\n }\n }\n THNK2.LocalClientAdapter = LocalClientAdapter;\n class LocalServerAdapter extends THNK2.ServerAdapter {\n onBCMessage({ data }) {\n if (data.message === \"msg-for-server\")\n this.onMessage(data.from, data.data);\n else if (data.message === \"connect\")\n this.onConnection(data.from);\n else if (data.message === \"disconnect\")\n this.onDisconnection(data.from);\n }\n boundOnBCMessage = this.onBCMessage.bind(this);\n async prepare() {\n bc.addEventListener(\"message\", this.boundOnBCMessage);\n window.addEventListener(\"beforeunload\", () => this.close());\n }\n close() {\n bc.removeEventListener(\"message\", this.boundOnBCMessage);\n }\n doSendMessageTo(userID, message) {\n bc.postMessage({\n message: \"msg-for-client\",\n data: message.buffer.slice(\n message.buffer.byteLength - message.byteLength\n ),\n for: userID\n });\n }\n getServerID() {\n return ownID;\n }\n }\n THNK2.LocalServerAdapter = LocalServerAdapter;\n })(THNK || (THNK = {}));\n})();\nif (new URL(location).searchParams.get(\"client\")) THNK.client.startClient(runtimeScene, new THNK.LocalClientAdapter());",
"inlineCode": [
"// Load THNK Local Adapter (https://github.com/arthuro555/THNK)",
"\"use strict\";",
"(() => {",
" // code/adapters/local.ts",
" if(!window.THNK)window.THNK={};let THNK=window.THNK;",
" ((THNK2) => {",
" const logger = new gdjs.Logger(\"THNK - Local Testing Adapter\");",
" if (!globalThis.BroadcastChannel)",
" logger.error(",
" \"This browser does not support the local adapter - please try using another adapter! (Prepare for an error)\"",
" );",
" const bc = new BroadcastChannel(\"thnk-local-server\");",
" bc.addEventListener(",
" \"messageerror\",",
" (e) => logger.error(\"An error occured while sending a message!\", e)",
" );",
" const ownID = \"\" + Date.now() + Math.random() * 1e3;",
" class LocalClientAdapter extends THNK2.ClientAdapter {",
" onBCMessage({ data }) {",
" if (data.message === \"msg-for-client\" && data.for === ownID)",
" this.onMessage(data.data);",
" }",
" boundOnBCMessage = this.onBCMessage.bind(this);",
" async prepare(runtimeScene) {",
" bc.addEventListener(\"message\", this.boundOnBCMessage);",
" bc.postMessage({ message: \"connect\", from: ownID });",
" window.addEventListener(\"beforeunload\", () => this.close());",
" }",
" close() {",
" bc.postMessage({ message: \"disconnect\", from: ownID });",
" bc.removeEventListener(\"message\", this.boundOnBCMessage);",
" }",
" doSendMessage(message) {",
" bc.postMessage({",
" message: \"msg-for-server\",",
" data: message,",
" from: ownID",
" });",
" }",
" }",
" THNK2.LocalClientAdapter = LocalClientAdapter;",
" class LocalServerAdapter extends THNK2.ServerAdapter {",
" onBCMessage({ data }) {",
" if (data.message === \"msg-for-server\")",
" this.onMessage(data.from, data.data);",
" else if (data.message === \"connect\")",
" this.onConnection(data.from);",
" else if (data.message === \"disconnect\")",
" this.onDisconnection(data.from);",
" }",
" boundOnBCMessage = this.onBCMessage.bind(this);",
" async prepare() {",
" bc.addEventListener(\"message\", this.boundOnBCMessage);",
" window.addEventListener(\"beforeunload\", () => this.close());",
" }",
" close() {",
" bc.removeEventListener(\"message\", this.boundOnBCMessage);",
" }",
" doSendMessageTo(userID, message) {",
" bc.postMessage({",
" message: \"msg-for-client\",",
" data: message.buffer.slice(",
" message.buffer.byteLength - message.byteLength",
" ),",
" for: userID",
" });",
" }",
" getServerID() {",
" return ownID;",
" }",
" }",
" THNK2.LocalServerAdapter = LocalServerAdapter;",
" })(THNK || (THNK = {}));",
"})();",
"if (new URL(location).searchParams.get(\"client\")) THNK.client.startClient(runtimeScene, new THNK.LocalClientAdapter());"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
Expand Down Expand Up @@ -76,6 +152,7 @@
" height: windowHeight,\r",
" useContentSize: true,\r",
" backgroundColor: '#000000',\r",
" autoHideMenuBar: true,\r",
" parent: remote.getCurrentWindow(),\r",
" webPreferences: {\r",
" nodeIntegration: true,\r",
Expand Down