Skip to content

Commit

Permalink
view resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
jtvberg committed Sep 1, 2024
1 parent f74dc42 commit 40d6b5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
19 changes: 12 additions & 7 deletions public/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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`)
}
Expand Down Expand Up @@ -102,6 +104,9 @@ const loadStreams = () => {

// apply settings on startup
const applySettings = () => {
headerCollapsed = headerDim.base
headerExpanded = headerDim.height

loadStreams()

getBookmarks()
Expand All @@ -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())

Expand Down Expand Up @@ -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' : '')
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
14 changes: 10 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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 }
})
5 changes: 3 additions & 2 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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)
})

0 comments on commit 40d6b5d

Please sign in to comment.