Skip to content

Commit

Permalink
Merge pull request #8 from flegald/features/controller-style-gzdoom-p…
Browse files Browse the repository at this point in the history
…athing

controller support, styling, backend path helpers
  • Loading branch information
flegald committed Jul 29, 2022
2 parents 8718158 + 278964f commit 1aef4d3
Show file tree
Hide file tree
Showing 24 changed files with 4,427 additions and 603 deletions.
61 changes: 37 additions & 24 deletions electron/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,75 @@
import { contextBridge, ipcRenderer } from 'electron'
import { contextBridge, ipcRenderer } from 'electron';
import {
FLATPAK_LIST_COMMAND,
FLATPAK_RUN_COMMAND,
GZDOOM_PATH,
MOD_PATH,
SETTINGS_CONTENTS,
SETTINGS_FILE,
SETTINGS_FILE_PATH
SETTINGS_FILE_PATH,
} from './constants';
import { SettingsInterface } from '../src/screens/Launch/types';
const fs = require('fs');
const os = require('os');
const path = require('path');
const exec = require('await-exec');

export const api = {

engineSearch: async () => {
const response = await exec(FLATPAK_LIST_COMMAND)
return !!response.stdout
engineSearch: async (): Promise<boolean> => {
const response = await exec(FLATPAK_LIST_COMMAND);
return !!response.stdout;
},

writeSettings: async (settings: object) => {
const settingsPath = path.join(os.homedir(), SETTINGS_FILE_PATH, SETTINGS_FILE);
initFileStructure: (): void => {
const shortPath = `${GZDOOM_PATH}/mods`;
const fullPackagePath = path.join(os.homedir(), shortPath);
if (!fs.existsSync(fullPackagePath)) {
fs.mkdirSync(fullPackagePath, { recursive: true });
}
},

writeSettings: async (settings: object): Promise<void> => {
const settingsPath = path.join(
os.homedir(),
SETTINGS_FILE_PATH,
SETTINGS_FILE
);
await fs.writeFileSync(settingsPath, JSON.stringify(settings));
},

initSettings: async () => {
initSettings: (): SettingsInterface => {
const settingsPath = path.join(os.homedir(), SETTINGS_FILE_PATH);
const withFileName = path.join(settingsPath, SETTINGS_FILE)
const withFileName = path.join(settingsPath, SETTINGS_FILE);
if (fs.existsSync(withFileName)) {
return JSON.parse(fs.readFileSync(withFileName));
}
try {
fs.mkdirSync(settingsPath);
} catch (e) {
console.log(e)
console.log(e);
}
await fs.writeFileSync(withFileName, JSON.stringify(SETTINGS_CONTENTS));
return SETTINGS_CONTENTS
fs.writeFileSync(withFileName, JSON.stringify(SETTINGS_CONTENTS));
return SETTINGS_CONTENTS;
},

fileSearch: async (extendedPath: string = ''): Promise<string[]> => {
const shortPath = `${GZDOOM_PATH}${extendedPath}`
const fullPackagePath = path.join(os.homedir(), shortPath)
const shortPath = `${GZDOOM_PATH}${extendedPath}`;
const fullPackagePath = path.join(os.homedir(), shortPath);
return await fs.promises.readdir(fullPackagePath);
},

startEngine: (modList: string[], iwad: string) => {
startEngine: async (modList: string[], iwad: string): Promise<void> => {
const iwadFull = `${GZDOOM_PATH}/${iwad}`;
const modPrefix = `${GZDOOM_PATH}${MOD_PATH}`
const command = [FLATPAK_RUN_COMMAND, `-iwad ${iwadFull}`]
modList.forEach((m => command.push(`-file ${path.join(modPrefix, m)}`)));
exec(command.join(' '))
const modPrefix = `${GZDOOM_PATH}${MOD_PATH}`;
const command = [FLATPAK_RUN_COMMAND, `-iwad ${iwadFull}`];
modList.forEach(m => command.push(`-file ${path.join(modPrefix, m)}`));
await exec(command.join(' '));
},

on: (channel: string, callback: Function) => {
ipcRenderer.on(channel, (_, data) => callback(data))
}
}
on: (channel: string, callback: Function): void => {
ipcRenderer.on(channel, (_, data) => callback(data));
},
};

contextBridge.exposeInMainWorld('Main', api)
contextBridge.exposeInMainWorld('Main', api);
52 changes: 23 additions & 29 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,52 @@
import { app, BrowserWindow, ipcMain } from 'electron'
import { app, BrowserWindow, ipcMain } from 'electron';

let mainWindow: BrowserWindow | null
let mainWindow: BrowserWindow | null;

declare const MAIN_WINDOW_WEBPACK_ENTRY: string
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string
declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;

// const assetsPath =
// process.env.NODE_ENV === 'production'
// ? process.resourcesPath
// : app.getAppPath()

function createWindow () {
function createWindow() {
mainWindow = new BrowserWindow({
// icon: path.join(assetsPath, 'assets', 'icon.png'),
width: 1200,
height: 800,
backgroundColor: '#191622',
autoHideMenuBar: true,
fullscreen: process.env.NODE_ENV === 'production',
autoHideMenuBar: process.env.NODE_ENV === 'production',
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
}
})
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
});

mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);

mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow = null;
});
}

async function registerListeners () {
/**
* This comes from bridge integration, check bridge.ts
*/
async function registerListeners() {
ipcMain.on('message', (_, message) => {
console.log(message)
})
console.log(message);
});
}

app.on('ready', createWindow)
app
.on('ready', createWindow)
.whenReady()
.then(registerListeners)
.catch(e => console.error(e))
.catch(e => console.error(e));

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
app.quit();
}
})
});

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

0 comments on commit 1aef4d3

Please sign in to comment.