Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
node_modules
dist
pnpm-lock.yaml
pnpm-workspace.yaml
pnpm-workspace.yaml
electron
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ dist-ssr
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?

ssl
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
node_modules
dist
pnpm-lock.yaml
pnpm-workspace.yaml
pnpm-workspace.yaml
electron
4 changes: 2 additions & 2 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ app.use(
resave: false,
saveUninitialized: false,
cookie: {
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
secure: process.env.NODE_ENV === "production",
sameSite: process.env.SECURE === "true" ? "none" : "lax",
secure: process.env.SECURE === "true",
maxAge: 8 * 60 * 60 * 1000,
httpOnly: true,
},
Expand Down
22 changes: 19 additions & 3 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import mongoose from "mongoose";
import dotenv from "dotenv";
import https from "https";
import fs from "fs";

import app from "./app";

Expand All @@ -15,6 +17,20 @@ mongo.once("open", () => {
console.log("Database connected!");
});

app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});
if (process.env.SECURE === "true") {
const httpsServer = https.createServer(
{
key: fs.readFileSync("ssl/seitz.key"),
cert: fs.readFileSync("ssl/seitz.crt"),
},
app
);

httpsServer.listen(port, () => {
console.log(`⚡️[server]: Server is running at https://localhost:${port}`);
});
} else {
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});
}
3 changes: 2 additions & 1 deletion packages/ui/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_API_URL: http://localhost:4000
VITE_API_URL: localhost:4000
VITE_SECURE: false
2 changes: 2 additions & 0 deletions packages/ui/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_API_URL: localhost:4000
VITE_SECURE: true
12 changes: 12 additions & 0 deletions packages/ui/capacitor.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CapacitorConfig } from "@capacitor/cli";

const config: CapacitorConfig = {
appId: "com.sandboxnu.bgc",
appName: "Brain Game Center",
webDir: "dist",
server: {
androidScheme: "https",
},
};

export default config;
8 changes: 8 additions & 0 deletions packages/ui/electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# NPM renames .gitignore to .npmignore
# In order to prevent that, we remove the initial "."
# And the CLI then renames it
app
node_modules
build
dist
logs
Binary file added packages/ui/electron/assets/appIcon.ico
Binary file not shown.
Binary file added packages/ui/electron/assets/appIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/ui/electron/assets/splash.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/ui/electron/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/ui/electron/capacitor.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CapacitorConfig } from "@capacitor/cli";

const config: CapacitorConfig = {
appId: "com.sandboxnu.bgc",
appName: "Brain Game Center",
webDir: "dist",
server: {
androidScheme: "https",
},
};

export default config;
28 changes: 28 additions & 0 deletions packages/ui/electron/electron-builder.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"appId": "com.yourdoamnin.yourapp",
"directories": {
"buildResources": "resources"
},
"files": [
"assets/**/*",
"build/**/*",
"capacitor.config.*",
"app/**/*"
],
"publish": {
"provider": "github"
},
"nsis": {
"allowElevation": true,
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"win": {
"target": "nsis",
"icon": "assets/appIcon.ico"
},
"mac": {
"category": "your.app.category.type",
"target": "dmg"
}
}
75 changes: 75 additions & 0 deletions packages/ui/electron/live-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const cp = require('child_process');
const chokidar = require('chokidar');
const electron = require('electron');

let child = null;
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const reloadWatcher = {
debouncer: null,
ready: false,
watcher: null,
restarting: false,
};

///*
function runBuild() {
return new Promise((resolve, _reject) => {
let tempChild = cp.spawn(npmCmd, ['run', 'build']);
tempChild.once('exit', () => {
resolve();
});
tempChild.stdout.pipe(process.stdout);
});
}
//*/

async function spawnElectron() {
if (child !== null) {
child.stdin.pause();
child.kill();
child = null;
await runBuild();
}
child = cp.spawn(electron, ['--inspect=5858', './']);
child.on('exit', () => {
if (!reloadWatcher.restarting) {
process.exit(0);
}
});
child.stdout.pipe(process.stdout);
}

function setupReloadWatcher() {
reloadWatcher.watcher = chokidar
.watch('./src/**/*', {
ignored: /[/\\]\./,
persistent: true,
})
.on('ready', () => {
reloadWatcher.ready = true;
})
.on('all', (_event, _path) => {
if (reloadWatcher.ready) {
clearTimeout(reloadWatcher.debouncer);
reloadWatcher.debouncer = setTimeout(async () => {
console.log('Restarting');
reloadWatcher.restarting = true;
await spawnElectron();
reloadWatcher.restarting = false;
reloadWatcher.ready = false;
clearTimeout(reloadWatcher.debouncer);
reloadWatcher.debouncer = null;
reloadWatcher.watcher = null;
setupReloadWatcher();
}, 500);
}
});
}

(async () => {
await runBuild();
await spawnElectron();
setupReloadWatcher();
})();
Loading