Skip to content

Commit

Permalink
添加 electronjs 相关配置
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Aug 23, 2024
1 parent d7eae32 commit 9f7abda
Show file tree
Hide file tree
Showing 6 changed files with 609 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/_build*
/node_modules
*-dev*.wasm
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "0.2.0",
"compounds": [
{
"name": "Main + renderer",
"configurations": ["Main", "Renderer"],
"stopAll": true
}
],
"configurations": [
{
"name": "Renderer",
"port": 9222,
"request": "attach",
"type": "chrome",
"webRoot": "${workspaceFolder}"
},
{
"name": "Main",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"args": [".", "--remote-debugging-port=9222"],
"outputCapture": "std",
"console": "integratedTerminal"
}
]
}
32 changes: 32 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 版权 @2024 凹语言 作者。保留所有权利。

const { app, BrowserWindow } = require('electron/main')
const path = require('node:path')

const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})

win.loadFile('index.html')
}

app.whenReady().then(() => {
createWindow()

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "wa-playground-app",
"version": "1.0.0",
"description": "凹语言 Playground!",
"main": "main.js",
"scripts": {
"start": "electron . --disable-gpu",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "凹语言开发组",
"license": "AGPL-3.0-only",
"devDependencies": {
"electron": "^32.0.1"
}
}
11 changes: 11 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 版权 @2024 凹语言 作者。保留所有权利。

const { contextBridge } = require('electron')

contextBridge.exposeInMainWorld('versions', {
node: () => process.versions.node,
chrome: () => process.versions.chrome,
electron: () => process.versions.electron,
waWasmZipUrl: () => 'https://wa-lang.org/wa/wa-js/wa.wasm.zip'
// we can also expose variables, not just functions
})
Loading

0 comments on commit 9f7abda

Please sign in to comment.