Fix responsive scaling feedback loop
This commit is contained in:
@@ -39,6 +39,7 @@ const BASE_WINDOW_WIDTH = 1400
|
|||||||
const BASE_WINDOW_HEIGHT = 860
|
const BASE_WINDOW_HEIGHT = 860
|
||||||
|
|
||||||
let responsiveLayoutFrame = null
|
let responsiveLayoutFrame = null
|
||||||
|
let lastAppliedZoomFactor = null
|
||||||
|
|
||||||
function clamp(value, min, max){
|
function clamp(value, min, max){
|
||||||
return Math.min(Math.max(value, min), max)
|
return Math.min(Math.max(value, min), max)
|
||||||
@@ -70,13 +71,18 @@ function syncLaunchDetailWidths(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function applyResponsiveLayout(){
|
function applyResponsiveLayout(){
|
||||||
|
const currentWindow = remote.getCurrentWindow()
|
||||||
|
const contentBounds = currentWindow.getContentBounds()
|
||||||
const scale = clamp(
|
const scale = clamp(
|
||||||
Math.min(window.innerWidth / BASE_WINDOW_WIDTH, window.innerHeight / BASE_WINDOW_HEIGHT),
|
Math.min(contentBounds.width / BASE_WINDOW_WIDTH, contentBounds.height / BASE_WINDOW_HEIGHT),
|
||||||
0.72,
|
0.72,
|
||||||
1.45
|
1.45
|
||||||
)
|
)
|
||||||
|
|
||||||
webFrame.setZoomFactor(scale)
|
if(lastAppliedZoomFactor == null || Math.abs(lastAppliedZoomFactor - scale) > 0.001){
|
||||||
|
lastAppliedZoomFactor = scale
|
||||||
|
webFrame.setZoomFactor(scale)
|
||||||
|
}
|
||||||
document.documentElement.style.setProperty('--launcher-scale', scale.toFixed(3))
|
document.documentElement.style.setProperty('--launcher-scale', scale.toFixed(3))
|
||||||
|
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
@@ -94,9 +100,10 @@ function queueResponsiveLayout(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
const responsiveWindow = remote.getCurrentWindow()
|
||||||
queueResponsiveLayout()
|
responsiveWindow.on('resize', queueResponsiveLayout)
|
||||||
})
|
responsiveWindow.on('maximize', queueResponsiveLayout)
|
||||||
|
responsiveWindow.on('unmaximize', queueResponsiveLayout)
|
||||||
|
|
||||||
// Initialize auto updates in production environments.
|
// Initialize auto updates in production environments.
|
||||||
let updateCheckListener
|
let updateCheckListener
|
||||||
|
|||||||
Reference in New Issue
Block a user