Skip to content

Commit

Permalink
Allow overriding game log location. Re: #62
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Feb 2, 2023
1 parent 9394d66 commit 26bfb33
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
24 changes: 21 additions & 3 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function createMainWindow () {
windows.main = null
if ( tray ) { tray.destroy() }
windows.load.destroy()
gameLogFileWatch.close()
if ( gameLogFileWatch ) { gameLogFileWatch.close() }
app.quit()
})

Expand Down Expand Up @@ -537,7 +537,7 @@ function createNamedWindow(winName, windowArgs) {
}
}

const subWindowDev = new Set(['import', 'save', 'find', 'detail', 'notes', 'version', 'resolve'])
const subWindowDev = new Set(['import', 'save', 'find', 'detail', 'notes', 'version', 'resolve', 'gamelog'])
const subWindows = {
confirmFav : {
winName : 'confirm',
Expand Down Expand Up @@ -1125,6 +1125,23 @@ ipcMain.on('toMain_notesContextMenu', async (event) => {
ipcMain.on('toMain_openGameLog', () => { createNamedWindow('gamelog') })
ipcMain.on('toMain_openGameLogFolder', () => { shell.showItemInFolder(path.join(path.dirname(gameSettings), 'log.txt')) })
ipcMain.on('toMain_getGameLog', () => { readGameLog() })
ipcMain.on('toMain_changeGameLog', () => {
dialog.showOpenDialog(windows.prefs, {
properties : ['openFile'],
defaultPath : path.join(pathBestGuess, 'log.txt'),
filters : [
{ name : 'Log Files', extensions : ['txt'] },
{ name : 'All', extensions : ['*'] },
],
}).then((result) => {
if ( ! result.canceled ) {
loadGameLog(result.filePaths[0])
readGameLog()
}
}).catch((unknownError) => {
log.log.danger(`Could not read specified log : ${unknownError}`, 'game-log')
})
})

function readGameLog() {
if ( windows.gamelog === null ) { return }
Expand All @@ -1136,7 +1153,7 @@ function readGameLog() {
try {
const gameLogContents = fs.readFileSync(thisGameLog, {encoding : 'utf8', flag : 'r'})

windows.gamelog.webContents.send('fromMain_gameLog', gameLogContents)
windows.gamelog.webContents.send('fromMain_gameLog', gameLogContents, thisGameLog)
} catch (e) {
log.log.warning(`Could not read game log file: ${e}`, 'game-log')
}
Expand Down Expand Up @@ -1644,6 +1661,7 @@ function loadGameLog(newPath = false) {
})
} else {
log.log.warning(`Game Log not found at: ${thisGameLog}`, 'game-log')
mcStore.set('game_log_file', null)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions renderer/gamelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
<div class="sticky-top border-bottom bg-body ">
<div class="row w-100 pt-2 bg-body border-bottom">
<div class="col-8">
<h2 class="ps-2 mastHead"><l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n></h2>
<h2 class="ps-2 mastHead mb-0"><l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n></h2>
<span class="ps-4 small fst-italic" id="gameLogPath"></span>
</div>
<div class="col-4 text-end">
<div class="btn-group w-100 ms-auto me-1">
<button data-bs-toggle="tooltip" title="Open log in Explorer" type="button" onclick="window.gamelog.openGameLogFolder()" class="btn btn-success btn-sm"><i class="bi bi-save"></i></button>
<button data-bs-toggle="tooltip" title="Open new log" type="button" onclick="window.gamelog.changeGameLogFile()" class="btn btn-dark btn-sm"><i class="bi bi-folder2-open"></i></button>
<button data-bs-toggle="tooltip" title="Open log in Explorer" type="button" onclick="window.gamelog.openGameLogFolder()" class="btn btn-dark btn-sm"><i class="bi bi-save"></i></button>
<button data-bs-toggle="tooltip" title="Refresh Log" type="button" onclick="window.gamelog.getGameLogContents()" class="btn btn-dark btn-sm"><i class="bi bi-arrow-clockwise"></i></button>
<input type="checkbox" class="btn-check" id="auto_scroll" autocomplete="off">
<label data-bs-toggle="tooltip" title="Auto-Scroll to Bottom on change" class="btn btn-outline-success btn-sm border" for="auto_scroll"><i class="bi bi-align-bottom"></i></label>
Expand Down
1 change: 1 addition & 0 deletions renderer/preload/preload-gamelogWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contextBridge.exposeInMainWorld(
contextBridge.exposeInMainWorld(
'gamelog',
{
changeGameLogFile : () => { ipcRenderer.send('toMain_changeGameLog') },
getGameLogContents : () => { ipcRenderer.send('toMain_getGameLog') },
openGameLogFolder : () => { ipcRenderer.send('toMain_openGameLogFolder') },
receive : ( channel, func ) => {
Expand Down
3 changes: 2 additions & 1 deletion renderer/renderJS/gamelog_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ window.l10n.receive('fromMain_getText_return', (data) => {
window.l10n.receive('fromMain_l10n_refresh', () => { processL10N() })


window.gamelog.receive('fromMain_gameLog', (data) => {
window.gamelog.receive('fromMain_gameLog', (data, fileName) => {
fsgUtil.byId('gameLogPath').innerHTML = fileName
const autoScroll = fsgUtil.byId('auto_scroll').checked || false
const showThese = new Set()
const showData = []
Expand Down

0 comments on commit 26bfb33

Please sign in to comment.