Преглед изворни кода

Fix message css bug, add animations

Toby Chui пре 4 часа
родитељ
комит
ad70b5ac62

+ 3 - 2
src/web/Photo/README.md

@@ -43,11 +43,12 @@ thumbnail code is not involved.
 Where they are kept is a per user setting (Settings dialog, stored in
 `index_meta` of the index database, which survives an index rebuild):
 
-- **appdata** (default): `user:/.appdata/photo/previews/<hh>/<hash>.jpg`
+- **realtime** (default): drawn on every request and sent as a data URL;
+  nothing stored. The blurred square thumbnail stands in until it loads
+- **appdata**: `user:/.appdata/photo/previews/<hh>/<hash>.jpg`
 - **custom**: the same layout inside a folder the user picks; it must be
   writable and outside the Photo library roots, and only files named like
   previews are ever deleted from it
-- **realtime**: drawn on every request and sent as a data URL; nothing stored
 
 A preview is drawn again when the photo is newer than it. The front end asks
 `previews.js` for cached ones first (`generate: false`, up to 200 at a time),

+ 1 - 1
src/web/Photo/backend/photoSettings.js

@@ -74,7 +74,7 @@ function main() {
     var action = payload.action || "get";
     var reply;
     if (action === "set") {
-        var mode = "" + (payload.previewMode || "appdata");
+        var mode = "" + (payload.previewMode || "realtime");
         if (PREVIEW_MODES.indexOf(mode) < 0) {
             reply = { error: "unknown preview mode" };
         } else if (mode === "custom") {

+ 14 - 5
src/web/Photo/backend/previewlib.js

@@ -9,9 +9,9 @@
 
     Where previews go is the user's choice (Photo > Settings). It is kept in
     the index database's index_meta table, which survives an index rebuild:
-      preview_mode  "appdata"   cache in PREVIEW_DEFAULT_DIR (default)
+      preview_mode  "realtime"  draw on every request, store nothing (default)
+                    "appdata"   cache in PREVIEW_DEFAULT_DIR
                     "custom"    cache in the folder in preview_path
-                    "realtime"  draw on every request and store nothing
     A cached preview is <dir>/<hh>/<hash>.jpg, where hash is 14 hex digits of
     the photo's virtual path and hh its first two. It is drawn again when the
     photo is newer than it. Only files named like that are ever deleted from a
@@ -84,14 +84,14 @@ function previewCleanFolder(path) {
 // The preview settings of this user: { mode, path, dir }. dir is the cache
 // folder, or null for realtime previews.
 function previewSettings(db) {
-    var mode = "appdata";
+    var mode = "realtime";
     var path = "";
     if (db != null) {
-        mode = metaGet(db, "preview_mode", "appdata");
+        mode = metaGet(db, "preview_mode", "realtime");
         path = metaGet(db, "preview_path", "");
     }
     if (PREVIEW_MODES.indexOf(mode) < 0) {
-        mode = "appdata";
+        mode = "realtime";
     }
     var dir = PREVIEW_DEFAULT_DIR;
     if (mode === "realtime") {
@@ -136,9 +136,18 @@ function previewLookup(dir, filepath) {
     return { src: file, w: dim[0], h: dim[1], v: cacheTime };
 }
 
+// Whether this server can draw previews (imagelib.renderPreview came with a
+// newer ArozOS build)
+function previewAvailable() {
+    return typeof imagelib !== "undefined" && typeof imagelib.renderPreview === "function";
+}
+
 // Draw the preview of a photo into dir (or inline when dir is null)
 function previewRender(dir, filepath) {
     var r;
+    if (!previewAvailable()) {
+        return { error: "unavailable" };
+    }
     if (dir === null) {
         r = imagelib.renderPreview(filepath, "", PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT);
         if (!r || !r.dataURL) {

+ 5 - 0
src/web/Photo/backend/previews.js

@@ -57,6 +57,11 @@ function main() {
                 continue;
             }
         }
+        if (!previewAvailable()) {
+            // An older server build: show the thumbnails, ask for nothing
+            items[f] = { error: "unavailable" };
+            continue;
+        }
         if (!generate) {
             items[f] = { pending: true };
             continue;

+ 38 - 18
src/web/Photo/index.html

@@ -343,14 +343,25 @@
         .search-clear-link { color: #f76c5d; cursor: pointer; }
         .search-clear-link:hover { text-decoration: underline; }
         #index-chip {
-            margin-left: auto;
-            color: #888;
-            font-size: 0.95em;
+            position: absolute;
+            top: calc(100% + 8px);
+            right: 0.9em;
+            z-index: 20;
             display: flex;
             align-items: center;
-            gap: 0.35em;
+            gap: 0.4em;
+            padding: 0.3em 0.85em;
+            border-radius: 999px;
+            background: rgba(30, 30, 30, 0.9);
+            border: 1px solid #333;
+            box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
+            backdrop-filter: blur(6px);
+            color: #aaa;
+            font-size: 0.8em;
+            white-space: nowrap;
         }
-        #index-chip .reindex-link { color: #888; cursor: pointer; }
+        #index-chip i.icon { margin: 0; height: auto; }
+        #index-chip .reindex-link { color: #999; cursor: pointer; }
         #index-chip .reindex-link:hover { color: #f76c5d; }
 
         #fadeplate{
@@ -930,9 +941,15 @@
             height: 100%;
             object-fit: cover;
             object-position: center;
-            transition: transform 0.25s ease, filter 0.2s ease;
+            transition: transform 0.35s ease, filter 0.35s ease;
         }
         .imagecard:hover img { filter: brightness(1.08); }
+        /* Waterfall: the square thumbnail stands in, blurred, until the
+           photo's own preview has loaded */
+        .imagecard img.pv-pending {
+            filter: blur(14px) brightness(0.85);
+            transform: scale(1.12);
+        }
         .imagecard::after {
             content: "";
             position: absolute;
@@ -1648,17 +1665,19 @@
                     </div>
 
                     <!-- Result count / indexing status -->
-                    <div id="search-meta" x-show="searchMode || indexStatusText.length > 0">
-                        <span x-show="searchMode" x-text="searchSummary()"></span>
-                        <a class="search-clear-link" x-show="searchMode && scope === 'folder'" x-on:click="setScope('all')" locale="search/everywhere">Search all photos</a>
-                        <a class="search-clear-link" x-show="searchMode" x-on:click="clearSearch()" locale="search/clear">Clear search</a>
-                        <span id="index-chip" x-show="indexStatusText.length > 0">
-                            <i class="loading spinner icon" x-show="indexing"></i>
-                            <span x-text="indexStatusText"></span>
-                            <a class="reindex-link" x-show="!indexing" x-on:click="rebuildIndex()"
-                                title="Rebuild the search index" locale="search/rebuild">Rebuild</a>
-                        </span>
+                    <div id="search-meta" x-show="searchMode">
+                        <span x-text="searchSummary()"></span>
+                        <a class="search-clear-link" x-show="scope === 'folder'" x-on:click="setScope('all')" locale="search/everywhere">Search all photos</a>
+                        <a class="search-clear-link" x-on:click="clearSearch()" locale="search/clear">Clear search</a>
                     </div>
+
+                    <!-- Indexing status: floats over the gallery, so it never moves it -->
+                    <span id="index-chip" x-show="indexStatusText.length > 0" x-transition.opacity.duration.200ms>
+                        <i class="loading spinner icon" x-show="indexing"></i>
+                        <span x-text="indexStatusText"></span>
+                        <a class="reindex-link" x-show="!indexing" x-on:click="rebuildIndex()"
+                            title="Rebuild the search index" locale="search/rebuild">Rebuild</a>
+                    </span>
                 </div>
 
                 <div id="noimg" class="ui basic inverted segment" style="display:none;">
@@ -1696,6 +1715,7 @@
                                                     <div class="imagecard" x-on:click="showImage($el); ShowModal();"
                                                         :style="{ aspectRatio: cardRatio(image) }" :filedata="cardFiledata(image)">
                                                         <img :src="PhotoPreviews.url(image.filepath) || thumbUrl(image)" :data-thumb="thumbUrl(image)"
+                                                            :class="PhotoPreviews.url(image.filepath) ? '' : 'pv-pending'"
                                                             x-init="PhotoPreviews.observe($el, image.filepath)" alt="">
                                                     </div>
                                                 </template>
@@ -1733,7 +1753,7 @@
                             x-on:click="setPreviewMode('appdata')" x-on:keydown.enter.prevent="setPreviewMode('appdata')" x-on:keydown.space.prevent="setPreviewMode('appdata')">
                             <span class="pd-radio"></span>
                             <div class="pd-opt-main">
-                                <div class="pd-opt-title" locale="settings/modeAppdata">Keep them in my app data (recommended)</div>
+                                <div class="pd-opt-title" locale="settings/modeAppdata">Keep them in my app data</div>
                                 <div class="pd-opt-desc" x-text="settings.defaultDir"></div>
                             </div>
                         </div>
@@ -1750,7 +1770,7 @@
                             x-on:click="setPreviewMode('realtime')" x-on:keydown.enter.prevent="setPreviewMode('realtime')" x-on:keydown.space.prevent="setPreviewMode('realtime')">
                             <span class="pd-radio"></span>
                             <div class="pd-opt-main">
-                                <div class="pd-opt-title" locale="settings/modeRealtime">Draw them every time</div>
+                                <div class="pd-opt-title" locale="settings/modeRealtime">Draw them every time (default)</div>
                                 <div class="pd-opt-desc" locale="settings/modeRealtimeDesc">Uses no disk space, but every preview is drawn again each time it is shown.</div>
                             </div>
                         </div>

+ 57 - 29
src/web/Photo/layout.js

@@ -160,6 +160,7 @@ var PhotoPreviews = {
     batchSize: 3,
     mode: '',
     observer: null,
+    failures: 0,        // generate requests failed in a row
     generation: 0,      // bumps on reset, so late answers are dropped
     onSize: null,       // function(filepath, w, h) set by the component
 
@@ -194,13 +195,24 @@ var PhotoPreviews = {
         if (this.observer) this.observer.unobserve(el);
     },
 
+    // Show the preview of a card. The blurred thumbnail stays until the
+    // preview has really loaded; a photo without preview shows it sharp.
     apply: function (el, filepath) {
         var r = this.ready[filepath];
-        if (!r || !r.url || el.getAttribute('data-preview') !== filepath) return;
-        if (el.getAttribute('src') !== r.url) {
-            el.setAttribute('src', r.url);
+        if (!r || el.getAttribute('data-preview') !== filepath) return;
+        if (!r.url) {
+            el.classList.remove('pv-pending');
+            return;
         }
         el.classList.add('is-preview');
+        if (el.getAttribute('src') === r.url) {
+            if (el.complete) el.classList.remove('pv-pending');
+            return;
+        }
+        var done = function () { el.classList.remove('pv-pending'); };
+        el.addEventListener('load', done, { once: true });
+        el.addEventListener('error', done, { once: true });
+        el.setAttribute('src', r.url);
     },
 
     want: function (el, filepath) {
@@ -223,40 +235,54 @@ var PhotoPreviews = {
         var self = this;
         var gen = this.generation;
         while (this.lookupQueue.length) {
-            var batch = this.lookupQueue.splice(0, 200);
-            aoPhotoBackend('Photo/backend/previews.js', { files: batch, generate: false }).then(function (data) {
-                if (gen !== self.generation) return;
-                self.mode = (data && data.mode) || self.mode;
-                var items = (data && data.items) || {};
-                for (var f in items) {
-                    if (items[f].pending) {
-                        self.generateQueue.push(f);
-                    } else {
-                        self.store(f, items[f]);
+            (function (batch) {
+                aoPhotoBackend('Photo/backend/previews.js', { files: batch, generate: false }).then(function (data) {
+                    if (gen !== self.generation) return;
+                    self.mode = (data && data.mode) || self.mode;
+                    var items = (data && data.items) || {};
+                    for (var f in items) {
+                        if (items[f].pending) {
+                            self.generateQueue.push(f);
+                        } else {
+                            self.store(f, items[f]);
+                        }
                     }
-                }
-                self.pump();
-            }).catch(function () { /* keep the thumbnails */ });
+                    self.pump();
+                }).catch(function () {
+                    // Show these thumbnails sharp instead of blurred
+                    if (gen !== self.generation) return;
+                    for (var i = 0; i < batch.length; i++) self.store(batch[i], { error: 'failed' });
+                });
+            })(this.lookupQueue.splice(0, 200));
         }
     },
 
     pump: function () {
         var self = this;
         while (this.active < this.maxActive && this.generateQueue.length) {
-            var batch = this.generateQueue.splice(0, this.batchSize);
-            var gen = this.generation;
             this.active++;
-            aoPhotoBackend('Photo/backend/previews.js', { files: batch, generate: true }).then(function (data) {
-                if (gen !== self.generation) return;
-                var items = (data && data.items) || {};
-                for (var f in items) self.store(f, items[f]);
-            }).catch(function () {
-                /* leave the thumbnails */
-            }).then(function () {
-                if (gen !== self.generation) return;
-                self.active--;
-                self.pump();
-            });
+            (function (batch, gen) {
+                aoPhotoBackend('Photo/backend/previews.js', { files: batch, generate: true }).then(function (data) {
+                    if (gen !== self.generation) return;
+                    self.failures = 0;
+                    var items = (data && data.items) || {};
+                    for (var f in items) self.store(f, items[f]);
+                }).catch(function () {
+                    if (gen !== self.generation) return;
+                    // Keep the thumbnails of this batch; after a few failed
+                    // requests in a row stop asking (the server cannot draw)
+                    for (var i = 0; i < batch.length; i++) self.store(batch[i], { error: 'failed' });
+                    self.failures++;
+                    if (self.failures >= 3) {
+                        var rest = self.generateQueue.splice(0);
+                        for (var k = 0; k < rest.length; k++) self.store(rest[k], { error: 'failed' });
+                    }
+                }).then(function () {
+                    if (gen !== self.generation) return;
+                    self.active--;
+                    self.pump();
+                });
+            })(this.generateQueue.splice(0, this.batchSize), this.generation);
         }
     },
 
@@ -306,10 +332,12 @@ var PhotoPreviews = {
         this.generateQueue = [];
         this.queued = {};
         this.active = 0;
+        this.failures = 0;
         clearTimeout(this.lookupTimer);
         var imgs = document.querySelectorAll('#viewbox img[data-preview]');
         for (var i = 0; i < imgs.length; i++) {
             imgs[i].classList.remove('is-preview');
+            imgs[i].classList.add('pv-pending');
             var thumb = imgs[i].getAttribute('data-thumb');
             if (thumb) imgs[i].setAttribute('src', thumb);
             this.observe(imgs[i], imgs[i].getAttribute('data-preview'));

+ 12 - 12
src/web/Photo/locale/photo.json

@@ -284,11 +284,11 @@
                 "settings/title": "相片設定",
                 "settings/previews": "瀑布流預覽圖",
                 "settings/previewsDesc": "瀑布流版面會以原本的比例顯示每張相片。這些預覽圖由伺服器產生,可以保存起來,下次就能更快載入。",
-                "settings/modeAppdata": "保存在我的應用程式資料中(建議)",
+                "settings/modeAppdata": "保存在我的應用程式資料中",
                 "settings/modeCustom": "保存在我選擇的資料夾",
                 "settings/noFolder": "尚未選擇資料夾",
                 "settings/choose": "選擇…",
-                "settings/modeRealtime": "每次即時產生",
+                "settings/modeRealtime": "每次即時產生(預設)",
                 "settings/modeRealtimeDesc": "不佔用磁碟空間,但每次顯示時都要重新產生預覽圖。",
                 "settings/clearCache": "清除快取",
                 "settings/customNote": "預覽圖存放在名為 00 至 ff 的子資料夾中,清除快取只會刪除這些檔案。",
@@ -613,11 +613,11 @@
                 "settings/title": "相片設定",
                 "settings/previews": "瀑布流預覽圖",
                 "settings/previewsDesc": "瀑布流版面會以原本的比例顯示每張相片。這些預覽圖由伺服器產生,可以保存起來,下次就能更快載入。",
-                "settings/modeAppdata": "保存在我的應用程式資料中(建議)",
+                "settings/modeAppdata": "保存在我的應用程式資料中",
                 "settings/modeCustom": "保存在我選擇的資料夾",
                 "settings/noFolder": "尚未選擇資料夾",
                 "settings/choose": "選擇…",
-                "settings/modeRealtime": "每次即時產生",
+                "settings/modeRealtime": "每次即時產生(預設)",
                 "settings/modeRealtimeDesc": "不佔用磁碟空間,但每次顯示時都要重新產生預覽圖。",
                 "settings/clearCache": "清除快取",
                 "settings/customNote": "預覽圖存放在名為 00 至 ff 的子資料夾中,清除快取只會刪除這些檔案。",
@@ -942,11 +942,11 @@
                 "settings/title": "照片设置",
                 "settings/previews": "瀑布流预览图",
                 "settings/previewsDesc": "瀑布流布局会以原始比例显示每张照片。这些预览图由服务器生成,可以保存下来,下次加载更快。",
-                "settings/modeAppdata": "保存在我的应用数据中(推荐)",
+                "settings/modeAppdata": "保存在我的应用数据中",
                 "settings/modeCustom": "保存在我选择的文件夹",
                 "settings/noFolder": "尚未选择文件夹",
                 "settings/choose": "选择…",
-                "settings/modeRealtime": "每次实时生成",
+                "settings/modeRealtime": "每次实时生成(默认)",
                 "settings/modeRealtimeDesc": "不占用磁盘空间,但每次显示时都要重新生成预览图。",
                 "settings/clearCache": "清除缓存",
                 "settings/customNote": "预览图存放在名为 00 至 ff 的子文件夹中,清除缓存只会删除这些文件。",
@@ -1271,11 +1271,11 @@
                 "settings/title": "Photo settings",
                 "settings/previews": "Waterfall previews",
                 "settings/previewsDesc": "The waterfall layout shows every photo in its own shape. Those previews are drawn on the server and can be kept, so they load quickly next time.",
-                "settings/modeAppdata": "Keep them in my app data (recommended)",
+                "settings/modeAppdata": "Keep them in my app data",
                 "settings/modeCustom": "Keep them in a folder I choose",
                 "settings/noFolder": "No folder chosen yet",
                 "settings/choose": "Choose…",
-                "settings/modeRealtime": "Draw them every time",
+                "settings/modeRealtime": "Draw them every time (default)",
                 "settings/modeRealtimeDesc": "Uses no disk space, but every preview is drawn again each time it is shown.",
                 "settings/clearCache": "Clear cache",
                 "settings/customNote": "Previews are kept in sub folders named 00 to ff. Clearing the cache only removes those.",
@@ -1600,11 +1600,11 @@
                 "settings/title": "写真の設定",
                 "settings/previews": "ウォーターフォールのプレビュー",
                 "settings/previewsDesc": "ウォーターフォールでは各写真を元の縦横比で表示します。プレビューはサーバーで作成され、保存しておくと次回から速く表示されます。",
-                "settings/modeAppdata": "アプリデータに保存する(推奨)",
+                "settings/modeAppdata": "アプリデータに保存する",
                 "settings/modeCustom": "選んだフォルダーに保存する",
                 "settings/noFolder": "フォルダーが選ばれていません",
                 "settings/choose": "選択…",
-                "settings/modeRealtime": "毎回その場で作成する",
+                "settings/modeRealtime": "毎回その場で作成する(既定)",
                 "settings/modeRealtimeDesc": "ディスク容量を使いませんが、表示するたびにプレビューを作り直します。",
                 "settings/clearCache": "キャッシュを消去",
                 "settings/customNote": "プレビューは 00〜ff という名前のサブフォルダーに保存されます。キャッシュの消去で削除されるのはそれらだけです。",
@@ -1929,11 +1929,11 @@
                 "settings/title": "사진 설정",
                 "settings/previews": "워터폴 미리 보기",
                 "settings/previewsDesc": "워터폴 레이아웃은 사진을 원래 비율로 보여 줍니다. 미리 보기는 서버에서 만들어지며, 저장해 두면 다음에 더 빨리 열립니다.",
-                "settings/modeAppdata": "내 앱 데이터에 저장 (권장)",
+                "settings/modeAppdata": "내 앱 데이터에 저장",
                 "settings/modeCustom": "선택한 폴더에 저장",
                 "settings/noFolder": "선택한 폴더 없음",
                 "settings/choose": "선택…",
-                "settings/modeRealtime": "매번 새로 만들기",
+                "settings/modeRealtime": "매번 새로 만들기 (기본값)",
                 "settings/modeRealtimeDesc": "디스크 공간을 쓰지 않지만, 표시할 때마다 미리 보기를 다시 만듭니다.",
                 "settings/clearCache": "캐시 지우기",
                 "settings/customNote": "미리 보기는 00~ff 이름의 하위 폴더에 저장됩니다. 캐시를 지우면 그 파일만 삭제됩니다.",

+ 1 - 1
src/web/Photo/photo.js

@@ -161,7 +161,7 @@ function photoListObject() {
         // settings dialog (gear)
         settingsOpen: false,
         settings: {
-            loaded: false, mode: 'appdata', path: '', dir: '', defaultDir: '',
+            loaded: false, mode: 'realtime', path: '', dir: '', defaultDir: '',
             stats: null, statsLoading: false, error: '', busy: false,
             total: 0, lastIndexed: 0, exclude: [], excludeInput: ''
         },