-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from flegald/features/controller-style-gzdoom-p…
…athing controller support, styling, backend path helpers
- Loading branch information
Showing
24 changed files
with
4,427 additions
and
603 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 |
---|---|---|
@@ -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); |
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 |
---|---|---|
@@ -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(); | ||
} | ||
}) | ||
}); |
Oops, something went wrong.