-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,062 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "demo", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"elecrun": "elecrun", | ||
"dev": "elecrun --vite --preload preload.ts --esm", | ||
"build": "elecrun build", | ||
"clean": "elecrun clean" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.5.0", | ||
"vite": "^2.1.5" | ||
}, | ||
"dependencies": { | ||
"electron": "^32.0.1", | ||
"elecrun": "file:../../" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function add(lhs: number, rhs: number) { | ||
return lhs + rhs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { app, BrowserWindow } from 'electron'; | ||
import path from 'path'; | ||
import { add } from './add'; | ||
|
||
function createWindow() { | ||
const win = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
preload: path.join(import.meta.dirname, 'preload.js'), | ||
nodeIntegration: false, | ||
contextIsolation: true, | ||
}, | ||
}); | ||
|
||
console.log('1 + 1 =', add(1, 1)); | ||
win.loadURL('http://localhost:3000').then(); | ||
win.webContents.openDevTools({ mode: 'detach' }); | ||
} | ||
|
||
app.whenReady().then(() => { | ||
createWindow(); | ||
|
||
app.on('activate', () => { | ||
if (BrowserWindow.getAllWindows().length === 0) { | ||
createWindow(); | ||
} | ||
}); | ||
}); | ||
|
||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
contextBridge, | ||
ipcRenderer, | ||
IpcRendererEvent, | ||
} from "electron"; | ||
|
||
contextBridge.exposeInMainWorld("bridge", { | ||
sendIpc: ipcRenderer.send, | ||
listenIpc: ( | ||
channel: string, | ||
callBack: (event: IpcRendererEvent, arg: any) => void | ||
) => { | ||
ipcRenderer.on(channel, (event, arg) => { | ||
callBack(event, arg); | ||
}); | ||
}, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"module": "node16", | ||
"moduleResolution": "node16", | ||
"moduleDetection": "force", | ||
"target": "ESNext", | ||
"outDir": "../../app" | ||
}, | ||
"include": ["../main/**/*", "../common/**/*"], | ||
"exclude": ["../renderer/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
window.onload = () => { | ||
let count = 0; | ||
|
||
const counterLabel = document.querySelector(".label")!; | ||
const btn = document.querySelector(".add-btn")!; | ||
|
||
btn.addEventListener('click', () => { | ||
count += 1; | ||
counterLabel.textContent = `updated ${count}`; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='UTF-8'> | ||
<meta http-equiv='Content-Security-Policy' | ||
content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline';"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<div id='body'> | ||
<h1>Hello World</h1> | ||
<h5 class='label'>0</h5> | ||
<button class='add-btn'>+1</button> | ||
</div> | ||
<script src='./app.ts' type='module'></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"lib": [ | ||
"DOM", | ||
"DOM.Iterable", | ||
"ESNext" | ||
], | ||
"types": [ | ||
"vite/client" | ||
] | ||
}, | ||
"include": [ | ||
"../renderer/**/*", | ||
"../common/**/*" | ||
], | ||
"exclude": [ | ||
"../main/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "node16", | ||
"moduleResolution": "node16", | ||
"moduleDetection": "force", | ||
"target": "ESNext", | ||
"noImplicitAny": true, | ||
"removeComments": true, | ||
"preserveConstEnums": true, | ||
"allowJs": true, | ||
"checkJs": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"strictPropertyInitialization": true, | ||
"strictBindCallApply": true, | ||
"noImplicitThis": true, | ||
"noImplicitReturns": true, | ||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"importHelpers": true, | ||
"sourceMap": true, | ||
"baseUrl": "./src" | ||
}, | ||
"exclude": ["node_modules", "app", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
const rendererPath = "./src/renderer" | ||
const outDirRenderer = "./build" | ||
|
||
export default defineConfig({ | ||
base: "./", | ||
root: rendererPath, | ||
build: { | ||
outDir: outDirRenderer, | ||
emptyOutDir: true, | ||
}, | ||
}); |
Oops, something went wrong.