mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Scale window correctly
This commit is contained in:
2
Makefile
2
Makefile
@@ -41,7 +41,7 @@ package:
|
|||||||
|
|
||||||
.PHONY: runx
|
.PHONY: runx
|
||||||
runx:
|
runx:
|
||||||
./src/main/shell/run-electron-app-in-xorg
|
IMGFLOAT_CHANNELS_URL=http://localhost:8080/channels ./src/main/shell/run-electron-app-in-xorg
|
||||||
|
|
||||||
.PHONY: ssl
|
.PHONY: ssl
|
||||||
ssl:
|
ssl:
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
const { app, BrowserWindow } = require("electron");
|
const { app, BrowserWindow } = require("electron");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
let broadcastRect = { width: 0, height: 0 };
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
const url = "https://imgfloat.kruhlmann.dev/channels";
|
const url = process.env["IMGFLOAT_CHANNELS_URL"] || "https://imgfloat.kruhlmann.dev/channels";
|
||||||
const initialWindowWidthPx = 960;
|
const initialWindowWidthPx = 960;
|
||||||
const initialWindowHeightPx = 640;
|
const initialWindowHeightPx = 640;
|
||||||
const applicationWindow = new BrowserWindow({
|
const applicationWindow = new BrowserWindow({
|
||||||
@@ -27,31 +28,30 @@ function createWindow() {
|
|||||||
|
|
||||||
const lockWindowToCanvas = async () => {
|
const lockWindowToCanvas = async () => {
|
||||||
if (applicationWindow.isDestroyed()) {
|
if (applicationWindow.isDestroyed()) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
const size = await applicationWindow.webContents.executeJavaScript(`(() => {
|
||||||
const size = await applicationWindow.webContents.executeJavaScript(`(() => {
|
const canvas = document.getElementById('broadcast-canvas');
|
||||||
const canvas = document.getElementById('broadcast-canvas');
|
if (!canvas) {
|
||||||
if (!canvas || !canvas.width || !canvas.height) {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
const rect = canvas.getBoundingClientRect();
|
||||||
return { width: Math.round(canvas.width), height: Math.round(canvas.height) };
|
return {
|
||||||
})();`);
|
width: Math.round(rect.width),
|
||||||
|
height: Math.round(rect.height),
|
||||||
if (size?.width && size?.height) {
|
};
|
||||||
const [currentWidth, currentHeight] = applicationWindow.getSize();
|
})();`);
|
||||||
if (currentWidth !== size.width || currentHeight !== size.height) {
|
|
||||||
applicationWindow.setSize(size.width, size.height, false);
|
if (size?.width && size?.height) {
|
||||||
}
|
if (broadcastRect.width !== size.width || broadcastRect.height !== size.height) {
|
||||||
applicationWindow.setMinimumSize(size.width, size.height);
|
console.log(
|
||||||
applicationWindow.setMaximumSize(size.width, size.height);
|
`Window size did not match canvas old: ${broadcastRect.width}x${broadcastRect.height} new: ${size.width}x${size.height}. Resizing.`,
|
||||||
applicationWindow.setResizable(false);
|
);
|
||||||
return true;
|
applicationWindow.setContentSize(size.width, size.height, false);
|
||||||
|
applicationWindow.setResizable(false);
|
||||||
|
broadcastRect = { ...size };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
// Best-effort sizing; ignore errors from early navigation states.
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNavigation = (navigationUrl) => {
|
const handleNavigation = (navigationUrl) => {
|
||||||
@@ -65,9 +65,6 @@ function createWindow() {
|
|||||||
lockWindowToCanvas();
|
lockWindowToCanvas();
|
||||||
} else {
|
} else {
|
||||||
clearCanvasSizeInterval();
|
clearCanvasSizeInterval();
|
||||||
applicationWindow.setResizable(true);
|
|
||||||
applicationWindow.setMinimumSize(320, 240);
|
|
||||||
applicationWindow.setMaximumSize(10000, 10000);
|
|
||||||
applicationWindow.setSize(initialWindowWidthPx, initialWindowHeightPx, false);
|
applicationWindow.setSize(initialWindowWidthPx, initialWindowHeightPx, false);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -1103,11 +1103,6 @@ button:disabled:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.broadcast-body canvas {
|
.broadcast-body canvas {
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,15 +154,6 @@ function fetchCanvasSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resizeCanvas() {
|
function resizeCanvas() {
|
||||||
const scale = Math.min(window.innerWidth / canvasSettings.width, window.innerHeight / canvasSettings.height);
|
|
||||||
const displayWidth = canvasSettings.width * scale;
|
|
||||||
const displayHeight = canvasSettings.height * scale;
|
|
||||||
canvas.width = canvasSettings.width;
|
|
||||||
canvas.height = canvasSettings.height;
|
|
||||||
canvas.style.width = `${displayWidth}px`;
|
|
||||||
canvas.style.height = `${displayHeight}px`;
|
|
||||||
canvas.style.left = `${(window.innerWidth - displayWidth) / 2}px`;
|
|
||||||
canvas.style.top = `${(window.innerHeight - displayHeight) / 2}px`;
|
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,8 +270,8 @@ function applyPatch(assetId, patch) {
|
|||||||
const targetLayer = Number.isFinite(patch.layer)
|
const targetLayer = Number.isFinite(patch.layer)
|
||||||
? patch.layer
|
? patch.layer
|
||||||
: Number.isFinite(patch.zIndex)
|
: Number.isFinite(patch.zIndex)
|
||||||
? patch.zIndex
|
? patch.zIndex
|
||||||
: null;
|
: null;
|
||||||
if (!isAudio && Number.isFinite(targetLayer)) {
|
if (!isAudio && Number.isFinite(targetLayer)) {
|
||||||
const currentOrder = getLayerOrder().filter((id) => id !== assetId);
|
const currentOrder = getLayerOrder().filter((id) => id !== assetId);
|
||||||
const insertIndex = Math.max(0, currentOrder.length - Math.round(targetLayer));
|
const insertIndex = Math.max(0, currentOrder.length - Math.round(targetLayer));
|
||||||
@@ -773,7 +764,7 @@ function setVideoSource(element, asset) {
|
|||||||
}
|
}
|
||||||
applyVideoSource(element, next.objectUrl, asset);
|
applyVideoSource(element, next.objectUrl, asset);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyVideoSource(element, objectUrl, asset) {
|
function applyVideoSource(element, objectUrl, asset) {
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ done
|
|||||||
|
|
||||||
echo "Using DISPLAY=:$DISP"
|
echo "Using DISPLAY=:$DISP"
|
||||||
|
|
||||||
Xephyr ":$DISP" -screen "$SCREEN" -resizeable -ac &
|
|
||||||
XEPHYR_PID=$!
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
kill "$ELECTRON_PID" "$OPENBOX_PID" "$XEPHYR_PID" 2>/dev/null || true
|
kill "$ELECTRON_PID" "$OPENBOX_PID" "$XEPHYR_PID" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
trap cleanup EXIT INT TERM
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
Xephyr ":$DISP" -screen "$SCREEN" -resizeable -ac &
|
||||||
|
XEPHYR_PID=$!
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
DISPLAY=":$DISP" openbox &
|
DISPLAY=":$DISP" openbox &
|
||||||
@@ -35,12 +35,23 @@ sleep 0.5
|
|||||||
|
|
||||||
DISPLAY=":$DISP" electron "$APP_ENTRY" &
|
DISPLAY=":$DISP" electron "$APP_ENTRY" &
|
||||||
ELECTRON_PID=$!
|
ELECTRON_PID=$!
|
||||||
|
DISPLAY=":$DISP" xsetroot -solid "#009999"
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
if ! kill -0 "$ELECTRON_PID" 2>/dev/null; then
|
||||||
|
echo "Electron exited — killing Xephyr"
|
||||||
|
kill "$XEPHYR_PID" 2>/dev/null || true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! kill -0 "$XEPHYR_PID" 2>/dev/null; then
|
||||||
|
echo "Xephyr exited — killing Electron"
|
||||||
|
kill "$ELECTRON_PID" 2>/dev/null || true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
# monitor X server — when it dies, kill Electron
|
|
||||||
while kill -0 "$XEPHYR_PID" 2>/dev/null; do
|
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Xephyr exited — killing Electron"
|
|
||||||
kill "$ELECTRON_PID" 2>/dev/null || true
|
|
||||||
wait "$ELECTRON_PID" 2>/dev/null || true
|
wait "$ELECTRON_PID" 2>/dev/null || true
|
||||||
|
wait "$XEPHYR_PID" 2>/dev/null || true
|
||||||
|
|||||||
Reference in New Issue
Block a user