Skip to content

Commit

Permalink
electron fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
prosif committed Oct 10, 2023
1 parent 8e674cf commit aa86796
Show file tree
Hide file tree
Showing 10 changed files with 503 additions and 324 deletions.
764 changes: 468 additions & 296 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homegames-core",
"version": "1.0.20",
"version": "1.0.21",
"description": "Play games at home",
"directories": {
"lib": "lib"
Expand Down Expand Up @@ -28,12 +28,12 @@
"homepage": "https://github.com/homegamesio/homegames#readme",
"dependencies": {
"homegames-common": "1.0.4",
"squish-0756": "npm:squishjs@0.7.56",
"squish-0762": "npm:squishjs@0.7.62",
"squish-0765": "npm:squishjs@0.7.65",
"squish-0766": "npm:squishjs@0.7.66",
"squish-0767": "npm:squishjs@0.7.67",
"squish-1000": "npm:[email protected].0",
"squish-0756": "npm:squishjs@1.0.4",
"squish-0762": "npm:squishjs@1.0.4",
"squish-0765": "npm:squishjs@1.0.4",
"squish-0766": "npm:squishjs@1.0.4",
"squish-0767": "npm:squishjs@1.0.4",
"squish-1000": "npm:[email protected].4",
"squish-1004": "npm:[email protected]",
"squish-1005": "npm:[email protected]",
"unzipper": "^0.10.11",
Expand Down
2 changes: 1 addition & 1 deletion src/Homenames.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getLocalIP = () => {

class Homenames {
constructor(port, certPath) {
log.info('running homenames on port ', port);
log.info('running homenames on port ' + port);

this.certPath = certPath;
this.playerInfo = {};
Expand Down
4 changes: 3 additions & 1 deletion src/common/squish-map.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { log } = require('homegames-common');

let isMain = true;

try {
require.resolve('homegames-core');
isMain = false;
} catch (err) {
console.log('Running web as main module');
log.info('Running web as main module');
}

// versions before 1004 will fail when using electron because they use the wrong base data directory. when running in electron (not as main process), use 1004 instead of those older versions
Expand Down
6 changes: 4 additions & 2 deletions src/common/util/dictionary.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { log } = require('homegames-common');

const https = require('https');
const path = require('path');
const fs = require('fs');
Expand Down Expand Up @@ -160,11 +162,11 @@ for (let i = 0; i < options.length; i++) {
}

if (dictPath) {
console.log('Using dictionary file at ' + dictPath);
log.info('Using dictionary file at ' + dictPath);
const dictionaryBytes = fs.readFileSync(dictPath);
words = dictionaryBytes.toString().split('\n').filter(w => !!w);
} else {
console.log('Missing dictionary.txt file. Using default dictionary');
log.info('Missing dictionary.txt file. Using default dictionary');
words = defaultWords;
}

Expand Down
11 changes: 6 additions & 5 deletions src/dashboard/HomegamesDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ if (!fs.existsSync(DOWNLOADED_GAME_DIRECTORY)) {
try {
fs.mkdirSync(DOWNLOADED_GAME_DIRECTORY);
} catch (err) {
console.error('Unable to create downloaded game directory');
console.error(err);
log.error('Unable to create downloaded game directory');
log.error(err);
}
}

Expand Down Expand Up @@ -451,7 +451,8 @@ class HomegamesDashboard extends ViewableGame {
});

childSession.on('close', (err) => {
console.log(err);
log.error('Child session closed');
log.error(err);
this.sessions[sessionId] = {};
});

Expand Down Expand Up @@ -536,8 +537,8 @@ class HomegamesDashboard extends ViewableGame {
this.renderGamePlane();
this.startSession(playerId, gameId, gameVersion.versionId);
}).catch(err => {
console.log('eroeororor');
console.log(err);
log.error('Error downloading game');
log.error(err);
});
}
},
Expand Down
1 change: 0 additions & 1 deletion src/games/sponge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Sponge extends Game {
}

constructor() {
console.log("SDKJFHKDSJFHDSF");
super();

this.playerSides = {};
Expand Down
11 changes: 6 additions & 5 deletions src/homegames_root/HomegamesRoot.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { getConfigValue, getAppDataPath, log } = require('homegames-common');

const fs = require('fs');
const process = require('process');

if (!process.env.SQUISH_PATH) {
const defaultVersion = 'squish-0767';
console.log('No SQUISH_PATH found. Using default: ' + defaultVersion);
log.info('No SQUISH_PATH found. Using default: ' + defaultVersion);
process.env.SQUISH_PATH = defaultVersion;
}

Expand All @@ -21,18 +23,17 @@ if (baseDir.endsWith('src')) {
baseDir = baseDir.substring(0, baseDir.length - 3);
}

const { getConfigValue, getAppDataPath, log } = require('homegames-common');
const HomenamesHelper = require('../util/homenames-helper');

const settingsModal = require('./settings');
const COLORS = Colors.COLORS;

const GAME_DIRECTORY = path.join(getAppDataPath(), 'hg-games');
// const GAME_DIRECTORY = path.join(getAppDataPath(), 'hg-games');


const SOURCE_GAME_DIRECTORY = path.resolve(getConfigValue('SOURCE_GAME_DIRECTORIES', `${baseDir}/src/games`));
const DOWNLOADED_GAME_DIRECTORY = GAME_DIRECTORY;//path.resolve(getConfigValue('DOWNLOADED_GAME_DIRECTORY', `hg-games`));
const DOWNLOADED_GAME_DIRECTORY = GAME_DIRECTORY;

const HOME_PORT = getConfigValue('HOME_PORT', 7001);

if (!fs.existsSync(GAME_DIRECTORY)) {
Expand Down Expand Up @@ -401,7 +402,7 @@ class HomegamesRoot {
this.homenamesHelper.updatePlayerSetting(playerId, PLAYER_SETTINGS.SOUND, {
enabled: newVal
}).then(() => {
console.log('just updated setting??');
log.info('just updated setting??');
});
},
onExportSessionData: () => {
Expand Down
11 changes: 6 additions & 5 deletions src/util/link-helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { log } = require('homegames-common');

const WebSocket = require('ws');
const https = require('https');
const os = require('os');
Expand Down Expand Up @@ -63,8 +65,6 @@ const linkConnect = (msgHandler) => new Promise((resolve, reject) => {

client.on('open', () => {
getClientInfo().then(clientInfo => {
// clientInfo.username = username ? username.toString() : null;

client.send(JSON.stringify({
type: 'register',
data: clientInfo
Expand All @@ -73,10 +73,10 @@ const linkConnect = (msgHandler) => new Promise((resolve, reject) => {
interval = setInterval(() => {
client.readyState == 1 && client.send(JSON.stringify({type: 'heartbeat'}));
if (Date.now() > socketRefreshTime) {
console.log('refreshing link socket');
log.info('refreshing link socket');
client.close();
clearInterval(interval);
linkConnect(msgHandler);///, username);
linkConnect(msgHandler);
}

}, 1000 * 10);
Expand All @@ -88,7 +88,8 @@ const linkConnect = (msgHandler) => new Promise((resolve, reject) => {
client.on('message', msgHandler ? msgHandler : () => {});

client.on('error', (err) => {
console.log(err);
log.error('Link client error');
log.error(err);
reject(err);
});

Expand Down
3 changes: 2 additions & 1 deletion src/util/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ const socketServer = (gameSession, port, cb = null, certPath = null, username =
let server;

if (certPath) {
log.info('Starting secure server on port ' + port);

server = https.createServer({
key: fs.readFileSync(`${certPath}/homegames.key`).toString(),
cert: fs.readFileSync(`${certPath}/homegames.cert`).toString()
Expand All @@ -232,7 +234,6 @@ const socketServer = (gameSession, port, cb = null, certPath = null, username =
});

getPublicIP().then(publicIp => {

const broadcastEnabled = !!getConfigValue('PUBLIC_GAMES', false);
log.info('broadcastEnabled: ' + broadcastEnabled);

Expand Down

0 comments on commit aa86796

Please sign in to comment.