Skip to content

Commit

Permalink
Add a custom titlebar, re: #62
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Feb 2, 2023
1 parent f3edec4 commit 882d09e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 68 deletions.
125 changes: 76 additions & 49 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function handleUnhandled(type, err, origin) {
message : `Caught ${type}: ${err}\n\nOrigin: ${origin}\n\n${err.stack}\n\n\nCan't Continue, exiting now!\n\nTo send file, please see ${crashLog}`,
type : 'error',
})
if ( gameLogFile ) { gameLogFileWatch.close() }
if ( gameLogFileWatch ) { gameLogFileWatch.close() }
app.quit()
} else {
log.log.debug(`Network error: ${err}`, `net-error-${type}`)
Expand All @@ -71,6 +71,7 @@ myTranslator.iconOverrides = {
folder_down_button : 'chevron-down',
folder_bot_button : 'align-bottom',
button_gamelog : 'file-earmark-text',
min_tray_button : 'chevron-bar-down',
}

if ( process.platform === 'win32' && app.isPackaged && gotTheLock && !isPortable ) {
Expand All @@ -92,7 +93,7 @@ if ( process.platform === 'win32' && app.isPackaged && gotTheLock && !isPortable
dialog.showMessageBox(windows.main, dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
if ( tray ) { tray.destroy() }
if ( gameLogFile ) { gameLogFileWatch.close() }
if ( gameLogFileWatch ) { gameLogFileWatch.close() }
Object.keys(windows).forEach((thisWin) => {
if ( thisWin !== 'main' && windows[thisWin] !== null ) {
windows[thisWin].destroy()
Expand Down Expand Up @@ -125,7 +126,6 @@ let pathBestGuess = userHome
let foundPath = false
let foundGame = ''

let gameLogFile = null
let gameLogFileWatch = null
let gameLogFileBounce = false

Expand Down Expand Up @@ -181,6 +181,7 @@ const settingsSchema = {
force_lang : { type : 'string', default : '' },
game_settings : { type : 'string', default : path.join(pathBestGuess, 'gameSettings.xml') },
game_path : { type : 'string', default : foundGame },
game_log_file : { type : ['string', 'null'], default : null },
cache_version : { type : 'string', default : '0.0.0' },
rel_notes : { type : 'string', default : '0.0.0' },
game_args : { type : 'string', default : '' },
Expand Down Expand Up @@ -365,6 +366,12 @@ function createSubWindow(winName, { skipTaskbar = false, noSelect = true, show =
show : show,
skipTaskbar : skipTaskbar,
autoHideMenuBar : true,
titleBarStyle : winName === 'main' ? 'hidden' : 'default',
titleBarOverlay : {
color : '#1f2021',
symbolColor : '#ffffff',
height : 25,
},
webPreferences : {
spellcheck : false,
nodeIntegration : false,
Expand Down Expand Up @@ -415,28 +422,10 @@ function createMainWindow () {

windows.main = createSubWindow('main', { noSelect : false, show : devDebug, preload : 'mainWindow' })

windows.main.on('minimize', () => {
if ( tray ) {
if ( firstMin ) {
const bubbleOpts = {
icon : trayIcon,
title : myTranslator.syncStringLookup('minimize_message_title'),
content : myTranslator.syncStringLookup('minimize_message'),
}

tray.displayBalloon(bubbleOpts)

setTimeout(() => {
if ( tray && !tray.isDestroyed() ) {
tray.removeBalloon()
}
}, 5000)
}

firstMin = false
windows.main.hide()
}
windows.main.on('focus', () => {
windows.main.webContents.send('fromMain_clearTooltips')
})

windows.main.on('closed', () => {
windows.main = null
if ( tray ) { tray.destroy() }
Expand Down Expand Up @@ -723,6 +712,28 @@ function isNetworkError(errorObject) { return errorObject.message.startsWith('ne
_)(_ )___/( (__
(____)(__) \___) */

ipcMain.on('toMain_sendMainToTray', () => {
if ( tray ) {
if ( firstMin ) {
const bubbleOpts = {
icon : trayIcon,
title : myTranslator.syncStringLookup('minimize_message_title'),
content : myTranslator.syncStringLookup('minimize_message'),
}

tray.displayBalloon(bubbleOpts)

setTimeout(() => {
if ( tray && !tray.isDestroyed() ) {
tray.removeBalloon()
}
}, 5000)
}

firstMin = false
windows.main.hide()
}
})
ipcMain.on('toMain_populateClipboard', (event, text) => { clipboard.writeText(text, 'selection') })

/** File operation buttons */
Expand Down Expand Up @@ -1117,8 +1128,13 @@ ipcMain.on('toMain_getGameLog', () => { readGameLog() })

function readGameLog() {
if ( windows.gamelog === null ) { return }

const thisGameLog = mcStore.get('game_log_file', null)

if ( thisGameLog === null ) { return }

try {
const gameLogContents = fs.readFileSync(gameLogFile, {encoding : 'utf8', flag : 'r'})
const gameLogContents = fs.readFileSync(thisGameLog, {encoding : 'utf8', flag : 'r'})

windows.gamelog.webContents.send('fromMain_gameLog', gameLogContents)
} catch (e) {
Expand Down Expand Up @@ -1599,6 +1615,38 @@ function refreshClientModList(closeLoader = true) {
/** END: Utility & Convenience Functions */

/** Business Functions */
function loadGameLog(newPath = false) {
if ( newPath ) { mcStore.set('game_log_file', newPath) }

if ( newPath || gameLogFileWatch !== null ) {
gameLogFileWatch.close()
gameLogFileWatch = null
}

const thisGameLog = mcStore.get('game_log_file', null)

if ( thisGameLog !== null && gameLogFileWatch === null ) {
log.log.debug(`Trying to open game log: ${thisGameLog}`, 'game-log')

if ( fs.existsSync(thisGameLog) ) {
gameLogFileWatch = fs.watch(thisGameLog, (event, filename) => {
if ( filename ) {
if ( gameLogFileBounce ) return
gameLogFileBounce = setTimeout(() => {
gameLogFileBounce = false
readGameLog()
}, 1000)
}
})
gameLogFileWatch.on('error', (err) => {
log.log.warning(`Error with game log: ${err}`, 'game-log')
gameLogFileWatch = null
})
} else {
log.log.warning(`Game Log not found at: ${thisGameLog}`, 'game-log')
}
}
}
function parseGameXML(devMode = null) {
const gameXMLFile = gameSettings.replace('gameSettings.xml', 'game.xml')

Expand Down Expand Up @@ -1651,32 +1699,11 @@ function parseSettings({disable = null, newFolder = null, userName = null, serve
mcStore.set('game_settings', gameSettings)
}

if ( gameLogFileWatch !== null ) {
gameLogFileWatch.close()
gameLogFileWatch = null
if ( mcStore.get('game_log_file') === null ) {
mcStore.set('game_log_file', path.join(path.dirname(gameSettings), 'log.txt'))
}

if ( gameLogFileWatch === null ) {
gameLogFile = path.join(path.dirname(gameSettings), 'log.txt')
log.log.debug(`Log file probable path: ${gameLogFile}`, 'game-log')

if ( fs.existsSync(gameLogFile) ) {
gameLogFileWatch = fs.watch(gameLogFile, (event, filename) => {
if ( filename ) {
if ( gameLogFileBounce ) return
gameLogFileBounce = setTimeout(() => {
gameLogFileBounce = false
readGameLog()
}, 1000)
}
})
gameLogFileWatch.on('error', (err) => {
log.log.warning(`Error with game log: ${err}`, 'game-log')
})
} else {
log.log.warning(`Game Log not found at: ${gameLogFile}`, 'game-log')
}
}
if ( gameLogFileWatch === null ) { loadGameLog() }

let XMLString = ''
const XMLParser = new fxml.XMLParser({
Expand Down
32 changes: 21 additions & 11 deletions renderer/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@
height: 13.5%;
line-height: 1.1em
}
.btn-launch:focus-visible { box-shadow: none!important;}
.btn-win_ui {
color: #ffffff;
height: 25px;
padding-top: 0px;
padding-bottom: 0px;
font-size: 13px;
}
.btn-win_ui:hover {
background-color: #4b4d5a;
color: #ffffff;
}

#display_mod_container { margin-top: 135px; }
#moveButtons { height: calc(100vh - 188px); position: fixed; top: 150px; }
Expand Down Expand Up @@ -124,26 +136,24 @@
<div id="lang-style-div">
<main class="flex-shrink-0">
<div class="container-fluid px-0 user-select-none">
<div class="fixed-top pt-2 bg-body" id="main-header">
<div class="fixed-top pt-0 bg-body" id="main-header">
<div class="row w-100 mb-1">
<div class="col-6 border-bottom">
<div class="col border-bottom mt-2" style="-webkit-app-region: drag;">
<h2 class="ps-2 mastHead">
<l10n name="app_name"></l10n> <l10n class="ver" name="app_version"></l10n>
</h2>
</div>
<div class="col-1"></div>
<div class="col-3">
<button onclick="clientOpenFarmSim()" class="btn btn-info w-100" id="launch_fs22">
<div class="col-3 pt-2 pe-4">
<button onclick="clientOpenFarmSim()" class="btn btn-info w-100 btn-launch" id="launch_fs22">
<img src="img/fsicon.png" style="height: 24px" class="float-start img-fluid"/>
<l10n name="launch_fs22"></l10n>
</button>
</div>
<div class="col-2 text-end">
<div class="btn-group w-100">
<button class="btn btn-outline-light w-50" onclick="window.mods.openFindAll()"><l10n name="search_all"></l10n></button>
<button class="btn btn-outline-light w-50" onclick="window.mods.openGameLog()"><l10n name="button_gamelog"></l10n></button>
<button onclick="window.mods.openPreferences()" class="btn btn-outline-light w-50" id="open_prefs"><l10n name="preferences_button"></l10n></button>
</div>
<div class="m-0 p-0 rounded-bottom" style="background-color: #1f2021; height: 25px; width: 290px!important;">
<button class="btn-win_ui btn rounded-0" onclick="window.mods.openFindAll()"><l10n name="search_all"></l10n></button>
<button class="btn-win_ui btn rounded-0" onclick="window.mods.openGameLog()"><l10n name="button_gamelog"></l10n></button>
<button class="btn-win_ui btn rounded-0" onclick="window.mods.openPreferences()" id="open_prefs"><l10n name="preferences_button"></l10n></button>
<button class="btn-win_ui btn rounded-0" onclick="window.mods.sendToTray()"><l10n name="min_tray_button"></l10n></button>
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions renderer/preload/preload-mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contextBridge.exposeInMainWorld(

contextBridge.exposeInMainWorld(
'mods', {
sendToTray : () => { ipcRenderer.send('toMain_sendMainToTray') },
startFarmSim : () => { ipcRenderer.send('toMain_startFarmSim') },
openPreferences : () => { ipcRenderer.send('toMain_openPrefs') },
openFindAll : () => { ipcRenderer.send('toMain_openFind') },
Expand Down Expand Up @@ -83,6 +84,7 @@ contextBridge.exposeInMainWorld(
'fromMain_selectOnlyFilter',
'fromMain_debugLogDanger',
'fromMain_dirtyUpdate',
'fromMain_clearTooltips',
]

if ( validChannels.includes( channel ) ) {
Expand Down
16 changes: 8 additions & 8 deletions renderer/renderJS/assist_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,16 @@ window.addEventListener('DOMContentLoaded', () => {
mismatchDialog.hide()
const dragTarget = fsgUtil.byId('drag_target')

dragTarget.addEventListener('dragenter', (event) => { clientDragEnter(event) })
dragTarget.addEventListener('dragleave', (event) => { clientDragLeave(event) })
dragTarget.addEventListener('dragover', (event) => { clientDragOver(event) })
dragTarget.addEventListener('drop', (event) => { clientDragDrop(event) })
dragTarget.addEventListener('dragenter', clientDragEnter )
dragTarget.addEventListener('dragleave', clientDragLeave )
dragTarget.addEventListener('dragover', clientDragOver )
dragTarget.addEventListener('drop', clientDragDrop )
})

window.addEventListener('click', () => {
fsgUtil.query('.tooltip').forEach((tooltip) => { tooltip.remove() })
})
function clearTooltips() { fsgUtil.query('.tooltip').forEach((tooltip) => { tooltip.remove() }) }

window.mods.receive('fromMain_clearTooltips', clearTooltips)
window.addEventListener('click', clearTooltips )

function clientDragOut(e) {
e.preventDefault()
Expand Down Expand Up @@ -563,7 +564,6 @@ function clientDragOver(e) {
e.preventDefault()
e.stopPropagation()


e.dataTransfer.dropEffect = (dragDropInFolder ? 'link' : 'copy')
}

0 comments on commit 882d09e

Please sign in to comment.