diff --git a/public/js/renderer.js b/public/js/renderer.js index d1ead17..85eb1bd 100644 --- a/public/js/renderer.js +++ b/public/js/renderer.js @@ -3,8 +3,6 @@ import { getStreams, setStreams, getNewStreamId, getLastStream, getPrefs, setLas import locs from '../res/loc.json' with { type: 'json' } // Constants -const headerCollapsed = 12 -const headerExpanded = 31 const streams = getStreams() // Element references @@ -65,6 +63,8 @@ const $bookmarkSortHostBtn = document.querySelector('#bookmark-sort-host-btn') const $bookmarkNewLinkBtn = document.querySelector('#bookmark-newlink-btn') // Vars +let headerCollapsed = 0 +let headerExpanded = 0 let dragAnimationId let dragMouseX let dragMouseY @@ -74,6 +74,8 @@ let headerTimeOut let editMode = false // Functions +const headerDim = await window.electronAPI.getHeaderHeight() + const logOutput = log => { console.log(`${new Date().toLocaleString()}: ${log}\n`) } @@ -102,6 +104,9 @@ const loadStreams = () => { // apply settings on startup const applySettings = () => { + headerCollapsed = headerDim.base + headerExpanded = headerDim.height + loadStreams() getBookmarks() @@ -128,7 +133,7 @@ const applySettings = () => { window.electronAPI.defaultAgent(getDefaultAgent()) - window.electronAPI.headerHeight({ height: headerCollapsed, base: headerCollapsed }) + window.electronAPI.updateHeaderHeight(headerCollapsed) window.electronAPI.openUrl(getLastStream()) @@ -555,12 +560,12 @@ const togglePanel = (panelBtn, override) => { changeSettingsLayout() if (override || panelBtn.classList.contains('toggled')) { $panelToggle.forEach(b => b.classList.remove('toggled')) - window.electronAPI.headerHeight({ height: headerExpanded, base: headerCollapsed }) + window.electronAPI.updateHeaderHeight(headerExpanded) $headerPanels.forEach(p => p.style.display = '') } else { $panelToggle.forEach(b => b.classList.remove('toggled')) panelBtn.classList.add('toggled') - window.electronAPI.headerHeight({ height: null, base: headerCollapsed }) + window.electronAPI.updateHeaderHeight(null) $headerPanels.forEach(p => p.style.display = p.dataset.panel === panelBtn.dataset.panel ? 'flex' : '') } } @@ -607,7 +612,7 @@ const collaspeHeader = () => { $header.removeEventListener('mouseleave', waitHeader) $headerControls.style.cssText = '' $header.style.cssText = '' - window.electronAPI.headerHeight({ height: headerCollapsed, base: headerCollapsed }) + window.electronAPI.updateHeaderHeight(headerCollapsed) } // wait to collaspe header on mouseleave @@ -621,7 +626,7 @@ const expandHeader = () => { if ($header.offsetHeight > headerExpanded) return $header.addEventListener('mouseleave', waitHeader) $header.style.cssText = 'opacity: 1' - window.electronAPI.headerHeight({ height: headerExpanded, base: headerCollapsed }) + window.electronAPI.updateHeaderHeight(headerExpanded) window.electronAPI.winFocus() window.clearTimeout(headerTimeOut) } diff --git a/src/main.js b/src/main.js index b83c9f4..2499698 100644 --- a/src/main.js +++ b/src/main.js @@ -47,6 +47,8 @@ const isMac = process.platform === 'darwin' const isLinux = process.platform === 'linux' const isWindows = process.platform === 'win32' const windows = new Set() +const headerCollapsed = 31 +const headerBase = 12 const googleAuthHost = 'accounts.google.com' const appInfo = { name: productName, @@ -142,7 +144,7 @@ const createWindow = () => { const hb = headerView.getBounds() streamView.setBounds({ x: 0, y: 0, width: wb.width, height: wb.height }) facetView.setBounds({ x: 0, y: 0, width: facetView.getBounds().width, height: wb.height + 2 }) - headerView.setBounds({ x: 0, y: 0, width: wb.width, height: hb.height > 31 ? wb.height : hb.height }) + setHeaderViewBounds(hb.height > headerCollapsed ? wb.height : hb.height) }) // on steam view navigation check if url is valid and set userAgent @@ -191,7 +193,7 @@ const createWindow = () => { headerView.webContents.on('did-finish-load', () => { headerView.webContents.send('is-mac', isMac) }) - + // // on closing of main window, send window location to renderer and close all windows mainWin.on('close', () => { headerView.webContents.send('win-getloc', mainWin.getBounds()) @@ -603,10 +605,10 @@ ipcMain.on('open-devtools', () => { headerView.webContents.openDevTools({ mode: 'detach' }) }) -ipcMain.on('update-header-height', (e, { height, base }) => { +ipcMain.on('update-header-height', (e, height) => { if (!mainWin) return if (height) { - isMac ? height > base ? mainWin.setWindowButtonVisibility(true) : mainWin.setWindowButtonVisibility(mainWin.isFullScreen()) : null + isMac ? height > headerBase ? mainWin.setWindowButtonVisibility(true) : mainWin.setWindowButtonVisibility(mainWin.isFullScreen()) : null setHeaderViewBounds(height) } else { setHeaderViewBounds(mainWin.getBounds().height) @@ -616,3 +618,7 @@ ipcMain.on('update-header-height', (e, { height, base }) => { ipcMain.on('update-facets-width', (e, width) => { setFacetViewBounds(width) }) + +ipcMain.handle('set-header-height', async (e) => { + return { height: headerCollapsed, base: headerBase } +}) diff --git a/src/preload.js b/src/preload.js index 058491c..7ec7a9c 100644 --- a/src/preload.js +++ b/src/preload.js @@ -5,7 +5,7 @@ contextBridge.exposeInMainWorld('electronAPI', { logData: data => ipcRenderer.on('log-data', data), clearData: bool => ipcRenderer.send('clear-data', bool), defaultAgent: agent => ipcRenderer.send('default-agent', agent), - headerHeight: heightObj => ipcRenderer.send('update-header-height', heightObj), + updateHeaderHeight: height => ipcRenderer.send('update-header-height', height), facetWidth: width => ipcRenderer.send('update-facets-width', width), urlToBookmark: url => ipcRenderer.send('url-to-bookmark', url), openUrl: url => ipcRenderer.send('open-url', url), @@ -19,7 +19,7 @@ contextBridge.exposeInMainWorld('electronAPI', { winMin: () => ipcRenderer.send('win-min'), winHide: () => ipcRenderer.send('win-hide'), winClose: () => ipcRenderer.send('win-close'), - winFocus: () => ipcRenderer.send('win-focus'), + winFocus: () => ipcRenderer.send('win-focus'), winMove: mouseObj => ipcRenderer.send('win-move', mouseObj), winLock: bool => ipcRenderer.send('win-lock', bool), winRatio: bool => ipcRenderer.send('win-ratio', bool), @@ -34,6 +34,7 @@ contextBridge.exposeInMainWorld('electronAPI', { lastStream: url => ipcRenderer.on('last-stream', url), setIsNetflix: bool => ipcRenderer.on('is-netflix', bool), streamOpened: bool => ipcRenderer.on('stream-opened', bool), + getHeaderHeight: heightObj => ipcRenderer.invoke('set-header-height', heightObj), setIsMac: bool => ipcRenderer.once('is-mac', bool), getAppInfo: appInfo => ipcRenderer.once('app-info', appInfo) })