Initial commit

This commit is contained in:
Zakary Timson 2022-08-06 14:17:27 -04:00
commit d8ebc770be
7 changed files with 106 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# IDEs
.idea
.vscode
# Artifacts
node_modules
dist

18
index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>TS Electron Template</title>
</head>
<body>
<!-- Placeholder -->
<h1>Versions:</h1>
<p>Node.js - <span id="node-version"></span></p>
<p>Chromium - <span id="chrome-version"></span></p>
<p>Electron - <span id="electron-version"></span></p>
<!-- Put your code inside src/renderer.ts -->
<script src="./dist/renderer.js"></script>
</body>
</html>

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "desktop-daemon",
"version": "0.0.0",
"description": "Programming Game",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"start": "npm run build && electron ./dist/main.js"
},
"devDependencies": {
"electron": "^20.0.1",
"typescript": "^4.7.4"
},
"dependencies": {}
}

34
src/main.ts Normal file
View File

@ -0,0 +1,34 @@
import {app, BrowserWindow} from "electron";
import * as path from "path";
// Window factory
function createWindow() {
const window = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
preload: path.join(__dirname, "preload.js")
}
});
window.loadFile(path.join(__dirname, "../index.html"));
window.webContents.openDevTools();
}
// Start
app.on("ready", () => {
createWindow();
// OSX convention - (resume the session)
app.on("activate", function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
// Stop
app.on("window-all-closed", () => {
// OSX convention (stay running in dock)
if (process.platform !== "darwin") app.quit();
});
// You can put anything else you want in the main thread here

12
src/preload.ts Normal file
View File

@ -0,0 +1,12 @@
// All of the Node.js APIs are available in the preload process (sandboxed).
window.addEventListener("DOMContentLoaded", () => {
const replaceText = (selector: string, text: string) => {
const element = document.getElementById(selector);
if(element) element.innerText = text;
};
replaceText('chrome-version', process.versions['chrome']);
replaceText('electron-version', process.versions['electron']);
replaceText('node-version', process.versions['node']);
});

4
src/renderer.ts Normal file
View File

@ -0,0 +1,4 @@
/*
This file is imported by index.html, you can put any code you want to run afer
page load, here.
*/

16
tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
},
"lib": ["dom", "es2015"]
},
"include": [
"src/**/*"
]
}