zoom persistenz
This commit is contained in:
15
main.ts
15
main.ts
@@ -709,6 +709,7 @@ if (
|
|||||||
|
|
||||||
// Native resize tracking using Deno 2.9 BrowserWindow events
|
// Native resize tracking using Deno 2.9 BrowserWindow events
|
||||||
let resizeTimer: ReturnType<typeof setTimeout> | undefined;
|
let resizeTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
let sizeSeenFromEvent = false;
|
||||||
try {
|
try {
|
||||||
win.addEventListener(
|
win.addEventListener(
|
||||||
"resize",
|
"resize",
|
||||||
@@ -720,6 +721,7 @@ try {
|
|||||||
if (w >= 1100 && h >= 700) {
|
if (w >= 1100 && h >= 700) {
|
||||||
settings.windowWidth = w;
|
settings.windowWidth = w;
|
||||||
settings.windowHeight = h;
|
settings.windowHeight = h;
|
||||||
|
sizeSeenFromEvent = true;
|
||||||
}
|
}
|
||||||
resizeTimer = setTimeout(() => {
|
resizeTimer = setTimeout(() => {
|
||||||
if (settings.windowWidth >= 1100 && settings.windowHeight >= 700) {
|
if (settings.windowWidth >= 1100 && settings.windowHeight >= 700) {
|
||||||
@@ -740,17 +742,28 @@ try {
|
|||||||
"close",
|
"close",
|
||||||
(() => {
|
(() => {
|
||||||
if (resizeTimer !== undefined) clearTimeout(resizeTimer);
|
if (resizeTimer !== undefined) clearTimeout(resizeTimer);
|
||||||
|
// Prefer the size reported by native resize events. getSize() has
|
||||||
|
// been observed to return a stale value (the last programmatically
|
||||||
|
// requested size) instead of the actual user-resized window size,
|
||||||
|
// which caused the same size to be saved on every close. Only fall
|
||||||
|
// back to getSize() if no resize event was ever received.
|
||||||
|
if (!sizeSeenFromEvent) {
|
||||||
|
try {
|
||||||
const [fw, fh] = win.getSize();
|
const [fw, fh] = win.getSize();
|
||||||
if (fw >= 1100 && fh >= 700) {
|
if (fw >= 1100 && fh >= 700) {
|
||||||
settings.windowWidth = fw;
|
settings.windowWidth = fw;
|
||||||
settings.windowHeight = fh;
|
settings.windowHeight = fh;
|
||||||
}
|
}
|
||||||
|
} catch { /* ok */ }
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const path = resolveSettingsPath();
|
const path = resolveSettingsPath();
|
||||||
Deno.mkdirSync(dirname(path), { recursive: true });
|
Deno.mkdirSync(dirname(path), { recursive: true });
|
||||||
Deno.writeTextFileSync(path, JSON.stringify(settings, null, 2));
|
Deno.writeTextFileSync(path, JSON.stringify(settings, null, 2));
|
||||||
console.log(
|
console.log(
|
||||||
`${PREFIX} Window size saved on close: ${settings.windowWidth}x${settings.windowHeight}`,
|
`${PREFIX} Window size saved on close: ${settings.windowWidth}x${settings.windowHeight} (source: ${
|
||||||
|
sizeSeenFromEvent ? "resize events" : "getSize()"
|
||||||
|
})`,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|||||||
@@ -126,10 +126,11 @@ async function loadPdf(index) {
|
|||||||
}
|
}
|
||||||
loadedIndex = index;
|
loadedIndex = index;
|
||||||
|
|
||||||
|
const previousZoom = pdfViewer ? pdfViewer.zoom : 1;
|
||||||
if (pdfViewer) {
|
if (pdfViewer) {
|
||||||
pdfViewer.destroy();
|
pdfViewer.destroy();
|
||||||
}
|
}
|
||||||
pdfViewer = new PdfViewer(pdfContainer);
|
pdfViewer = new PdfViewer(pdfContainer, { initialZoom: previousZoom });
|
||||||
viewer.classList.remove("loaded");
|
viewer.classList.remove("loaded");
|
||||||
pdfMessage.hidden = false;
|
pdfMessage.hidden = false;
|
||||||
pdfMessage.textContent = "Loading PDF\u2026";
|
pdfMessage.textContent = "Loading PDF\u2026";
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const ZOOM_MAX = 5;
|
|||||||
const ZOOM_STEP = 1.2; // multiplicative
|
const ZOOM_STEP = 1.2; // multiplicative
|
||||||
|
|
||||||
class PdfViewer {
|
class PdfViewer {
|
||||||
constructor(container) {
|
constructor(container, options = {}) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.generation = 0;
|
this.generation = 0;
|
||||||
this.loadingTask = null;
|
this.loadingTask = null;
|
||||||
@@ -15,12 +15,18 @@ class PdfViewer {
|
|||||||
this.renderTasks = new Set();
|
this.renderTasks = new Set();
|
||||||
this.lastUrl = null;
|
this.lastUrl = null;
|
||||||
this.lastSize = null;
|
this.lastSize = null;
|
||||||
this.zoom = 1; // multiplier on fit-to-width (1 = fit width)
|
// multiplier on fit-to-width (1 = fit width); can be seeded from the
|
||||||
|
// previous viewer instance so zoom survives switching documents
|
||||||
|
this.zoom = Math.min(
|
||||||
|
ZOOM_MAX,
|
||||||
|
Math.max(ZOOM_MIN, options.initialZoom ?? 1),
|
||||||
|
);
|
||||||
this._lastRenderWidth = 0;
|
this._lastRenderWidth = 0;
|
||||||
this._resizeTimer = null;
|
this._resizeTimer = null;
|
||||||
this._zoomTimer = null;
|
this._zoomTimer = null;
|
||||||
this.resizeObserver = null;
|
this.resizeObserver = null;
|
||||||
this._createDOM();
|
this._createDOM();
|
||||||
|
this._updateZoomLabel();
|
||||||
this._observeResize();
|
this._observeResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user