Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/deploy-dmg.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/deploy-pyinstaller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Deploy PyInstaller Executables
on:
workflow_call:
workflow_dispatch:
pull_request:

jobs:
build:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ jobs:
needs: deploy-dockerhub
uses: ./.github/workflows/deploy-pyinstaller.yml

deploy-make-dmg:
needs: deploy-pyinstaller
uses: ./.github/workflows/deploy-dmg.yml

upload-release:
needs: [deploy-pypi, deploy-dockerhub, deploy-pyinstaller, deploy-make-dmg]
needs: [deploy-pypi, deploy-dockerhub, deploy-pyinstaller]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
Expand All @@ -67,6 +63,6 @@ jobs:
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/**/*.{zip,tar.gz,dmg}
artifacts/**/*.{zip,tar.gz,app}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions INSTALL/pyinstaller/make_pyinstaller_image.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pyinstaller `
--add-data "$env:USERPROFILE/.cache/clip${sep}clip_models" `
--add-data "photomap/frontend/static${sep}photomap/frontend/static" `
--add-data "photomap/frontend/templates${sep}photomap/frontend/templates" `
--add-data "THIRD_PARTY_LICENSES.txt${sep}.THIRD_PARTY_LICENSES" `
--paths . `
$pyinstallerMode `
--name photomap `
Expand Down
1 change: 1 addition & 0 deletions INSTALL/pyinstaller/make_pyinstaller_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ PYINSTALLER_ARGS=(
--add-data "$HOME/.cache/clip:clip_models"
--add-data "photomap/frontend/static:photomap/frontend/static"
--add-data "photomap/frontend/templates:photomap/frontend/templates"
--add-data "THIRD_PARTY_LICENSES.txt:THIRD_PARTY_LICENSES"
--paths .
$PYINSTALLER_MODE
--argv-emulation
Expand Down
20 changes: 20 additions & 0 deletions THIRD_PARTY_LICENSES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CLIP Model Weights
Copyright (c) 2021 OpenAI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion photomap/frontend/static/javascript/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ export async function toggleGridSwiperView(gridView = null) {
else state.gridViewActive = gridView;
saveSettingsToLocalStorage();


const swiperContainer = document.querySelector(".swiper");
const gridViewBtn = document.getElementById("gridViewBtn");
const gridViewIcon = gridViewBtn.querySelector("svg");
Expand Down
107 changes: 63 additions & 44 deletions photomap/frontend/static/javascript/grid-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let slidesPerBatch = 0; // Number of slides to load per batch
let slideHeight = 140; // Default slide height (reduced from 200)
let currentRows = 0; // Track current grid dimensions
let currentColumns = 0;
let suppressSlideChange = false;
let slideData = {}; // Store data for each slide

const GRID_MAX_SCREENS = 6; // Keep up to this many screens in memory (tweakable)
Expand Down Expand Up @@ -63,6 +64,7 @@ function calculateGridGeometry() {

// Initialization code
export async function initializeGridSwiper() {
console.log("Initializing grid swiper...");
gridInitialized = false;
showSpinner();
eventRegistry.removeAll("grid"); // Clear previous event handlers
Expand Down Expand Up @@ -120,11 +122,6 @@ export async function initializeGridSwiper() {
const swiperContainer = document.querySelector(".swiper");
swiperContainer.classList.add("grid-mode");

state.swiper.on("slideChange", () => {
// do nothing with this.
return;
});

addGridEventListeners();
setupContinuousNavigation();
setupGridResizeHandler();
Expand Down Expand Up @@ -206,6 +203,7 @@ function addGridEventListeners() {
// Load more when reaching the end
state.swiper.on("slideNextTransitionStart", async () => {
if (state.isTransitioning) return; // Don't load more during transitions
showSpinner();
state.isTransitioning = true;
await waitForBatchLoadingToFinish();
state.isTransitioning = false;
Expand All @@ -222,15 +220,25 @@ function addGridEventListeners() {
const index = slideState.isSearchMode
? slideState.globalToSearch(lastSlideIndex) + 1
: lastSlideIndex + 1;
await loadBatch(index, true); // Append a batch at the end
await waitForBatchLoadingToFinish();
setBatchLoading(true);
try {
await loadBatch(index, true); // Append a batch at the end
} catch (error) {
console.log(error);
} finally {
setBatchLoading(false);
}
}
hideSpinner();
});

// Load more when reaching the start
state.swiper.on("slidePrevTransitionStart", async () => {
if (state.isTransitioning) return; // Don't load more during transitions
state.isTransitioning = true;
await waitForBatchLoadingToFinish();
setBatchLoading(true);
state.isTransitioning = false;
const firstSlide = parseInt(
state.swiper.slides[0].dataset.globalIndex,
Expand All @@ -242,12 +250,19 @@ function addGridEventListeners() {
if (firstSlide > 0 && state.swiper.activeIndex === 0) {
await loadBatch(index - 1, false); // Prepend a batch at the start
}
setBatchLoading(false);
});

// transitionEnd event
state.swiper.on("transitionEnd", () => {
suppressSlideChange = false;
});

// onChange event
state.swiper.on("slideChange", async () => {
// If the currently highlighted slide s.seais not visible, move the highlight to the top-left slide
await state.swiper.update(); // Ensure Swiper state is current
if (suppressSlideChange) return;

// If the currently highlighted slide is not visible, move the highlight to the top-left slide
const currentSlide = slideState.getCurrentSlide();
const currentGlobal = currentSlide.globalIndex;
const slideEl = document.querySelector(
Expand Down Expand Up @@ -293,7 +308,7 @@ function addGridEventListeners() {
window.handleGridSlideDblClick = async function (globalIndex) {
// Prevent navigation if we're already transitioning
if (state.isTransitioning) return;

slideState.setCurrentIndex(globalIndex, false);
updateCurrentSlideHighlight(globalIndex);

Expand Down Expand Up @@ -323,15 +338,12 @@ function addDoubleTapHandler(slideEl, globalIndex) {
// @param {number|null} targetIndex - Optional index to include in first screen.
// If null, use current slide index.
async function resetAllSlides() {

if (!gridInitialized) return;
if (!state.swiper) return;
showSpinner();

await new Promise(requestAnimationFrame); // display spinner

await waitForBatchLoadingToFinish();
setBatchLoading(true);

const targetIndex = slideState.getCurrentIndex();

Expand All @@ -346,19 +358,15 @@ async function resetAllSlides() {
console.warn("removeAllSlides failed:", err);
}
try {
state.swiper.update(); // ensure internal state is correct
await waitForBatchLoadingToFinish();
setBatchLoading(true);
await loadBatch(targetIndex, true);
await loadBatch(targetIndex + slidesPerBatch, true); // Load two batches to start in order to enable forward navigation
if (targetIndex > 0) {
await loadBatch(targetIndex, false); // Prepend a screen if not at start
}
} catch (err) {
console.warn(
"swiper.update() failed:",
err,
"\ncontinuing anyway, slide length =",
state.swiper.slides.length
);
}
await loadBatch(targetIndex, true);
await loadBatch(targetIndex + slidesPerBatch, true); // Load two batches to start in order to enable forward navigation
if (targetIndex > 0) {
await loadBatch(targetIndex, false); // Prepend a screen if not at start
console.log(err);
}
updateCurrentSlide();
setBatchLoading(false);
Expand All @@ -370,8 +378,9 @@ async function resetAllSlides() {
// The startIndex will be adjusted to be an even multiple of the screen size.
// If startIndex is null, load the next batch after the last loaded slide.
async function loadBatch(startIndex = null, append = true) {

// Calculate the next batch to load
if (startIndex === null) {
// Load after the last loaded slide
if (!state.swiper.slides?.length) {
startIndex = 0;
} else {
Expand All @@ -396,14 +405,21 @@ async function loadBatch(startIndex = null, append = true) {
// --- NORMAL BATCH LOAD ---
if (append) {
for (let i = 0; i < slidesPerBatch; i++) {
if (i % 4 === 0) {
await new Promise(requestAnimationFrame); // yield to UI thread every 4 images
if (state.isTransitioning) {
throw new Error("Aborted loadBatch due to transition");
}
}

// Calculate offset from current slide position
const offset = startIndex + i;

// Use slideState.resolveOffset to get the correct indices for this position
const globalIndex = slideState.indexToGlobal(offset);
if (globalIndex === null) continue; // Out of bounds

// In the event that the slide is already loaded, skip it.
// I'm not sure this logic is necessary if load tracking is done correctly.
if (loadedImageIndices.has(globalIndex)) {
continue;
}
Expand All @@ -421,10 +437,6 @@ async function loadBatch(startIndex = null, append = true) {
console.error("Failed to load image:", error);
break;
}
if (i % 8 === 0) {
await new Promise(requestAnimationFrame);
if (state.isTransitioning) return;
}
}

if (slides.length > 0) state.swiper.appendSlide(slides);
Expand All @@ -446,8 +458,14 @@ async function loadBatch(startIndex = null, append = true) {
} else {
// --- PREPEND LOGIC: Add a full screen's worth of slides before startIndex ---
for (let i = 0; i < slidesPerBatch; i++) {
if (i % 4 === 0) {
await new Promise(requestAnimationFrame); // yield to UI thread every 4 images
if (state.isTransitioning) {
throw new Error("Aborted loadBatch due to transition");
}
}

const globalIndex = slideState.indexToGlobal(startIndex - i - 1); // reverse order
// not sure this is wanted here
if (loadedImageIndices.has(globalIndex)) continue;

try {
Expand All @@ -461,12 +479,10 @@ async function loadBatch(startIndex = null, append = true) {
console.error("Failed to load image (prepend):", error);
continue;
}
if (i % 8 === 0) {
await new Promise(requestAnimationFrame);
if (state.isTransitioning) return;
}
}
if (slides.length > 0) {
suppressSlideChange = true;

state.swiper.prependSlide(slides);

// After prepending slides, add double-tap handlers to all the new ones.
Expand All @@ -478,7 +494,6 @@ async function loadBatch(startIndex = null, append = true) {
}
}
state.swiper.slideTo(currentColumns, 0); // maintain current view
// enforce high water mark after prepending (trim the other side)
enforceHighWaterMark(true);
}
}
Expand Down Expand Up @@ -569,9 +584,6 @@ function enforceHighWaterMark(trimFromEnd = false) {
delete slideData[g];
}

// Update Swiper internals
state.swiper.update();

// Adjust active index once to avoid a jump:
if (!trimFromEnd) {
// We removed removeScreens full screens from the start.
Expand All @@ -585,8 +597,6 @@ function enforceHighWaterMark(trimFromEnd = false) {
const targetActive = Math.min(prevActive, maxActive);
state.swiper.slideTo(targetActive, 0);
}

state.swiper.update();
}

function setupContinuousNavigation() {
Expand Down Expand Up @@ -703,10 +713,17 @@ function setupGridResizeHandler() {
newGeometry.columns !== currentColumns ||
Math.abs(newGeometry.tileSize - slideHeight) > 10
) {
// Current global index
const currentGlobalIndex = slideState.getCurrentSlide().globalIndex;
// Reinitialize the grid completely
await initializeGridSwiper();
await loadBatch();
await loadBatch(); // Load two batches to start

// Do not allow concurrent execution!
await waitForBatchLoadingToFinish();
setBatchLoading(true);
await loadBatch(currentGlobalIndex);
await loadBatch(currentGlobalIndex + slidesPerBatch); // Load two batches to start
setBatchLoading(false);
}
}, 300); // 300ms debounce delay
}
Expand Down Expand Up @@ -760,13 +777,15 @@ function makeSlideHTML(data, globalIndex) {
data.searchIndex = slideState.globalToSearch(globalIndex);
slideData[globalIndex] = data; // Cache the data

// replace image_url with thumbnail_url
const thumbnail_url = `thumbnails/${state.album}/${globalIndex}?size=${slideHeight}`;
return `
<div class="swiper-slide" style="width:${slideHeight}px; height:${slideHeight}px;"
data-global-index="${globalIndex}"
data-filepath="${data.filepath || ""}"
onclick="handleGridSlideClick(${globalIndex})"
ondblclick="handleGridSlideDblClick(${globalIndex})">
<img src="${data.image_url}" alt="${data.filename}"
<img src="${thumbnail_url}" alt="${data.filename}"
style="width:100%; height:100%; object-fit:contain; background:#222; border-radius:4px; display:block;" />
</div>
`;
Expand Down
1 change: 0 additions & 1 deletion photomap/frontend/static/javascript/slide-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class SlideStateManager {
}

seekToSlideIndex() {
console.log("Sending seekToSlideIndex event")
const slideInfo = this.getCurrentSlide();
window.dispatchEvent(
new CustomEvent("seekToSlideIndex", {
Expand Down
Loading