Texts outside the web app
The web app has its texts in apps/frontend/src/locales. The Windows and Mac apps also show texts before the web
app runs, or without a browser: the tray menu and menu bar, notifications, message boxes, the question whether it is you, and the pages that say
that LibrePhotos is starting, could not start or is closed. So does the Windows installer. They are in apps/backend/app_texts/<language>.json,
one file for each language, en.json first.
Change or translate a text
-
en.jsonhas every text. A key is the path to it, such asmenu.quit. -
A translation has the same keys. A missing one is shown in English, so a half-finished file is fine.
-
{version}and other words in braces are filled in. Keep all of them, in any order. -
Plain words, short sentences, and no path, port or file name where the reader does not need one. German says "du".
-
owner_check.reason.*ends two sentences:owner_check.windows, and the one a Mac starts itself ("LibrePhotos Server is trying to ..."). So it has no capital letter and no full stop. -
A menu is narrow: keep
menu.*andstatus.*to a few words. -
installer.*is for the Windows installer.installer.page.*replaces a message of Inno Setup with the same name, and%1in it is the program's name.
To add a language, copy en.json to the language's code (fr.json, pt-BR.json, zh-Hans.json; pt_BR.json works too)
and translate the values. Nothing else needs to change for the app: librephotos/app_texts.py finds the file, and the
build takes the whole folder. The installer gets the language too if Inno Setup has its own texts in it
(INNO_LANGUAGES in scripts/build_installer.py).
api/tests/infra/test_app_texts.py fails on an unknown key, on a placeholder that differs from the English text, on
a key no code uses and on an incomplete German file.
These files are not on Weblate yet, so a translation comes as a pull request. They are plain nested JSON with English
as the source, which Weblate reads as a JSON file component with the mask apps/backend/app_texts/*.json and
en.json as the monolingual base file.
In the code
from librephotos.app_texts import Text
Text("status.database_update").format(done=3, total=7).shown
.shownis the text in the computer's language, for a menu, a notification or a page.str(text)is the English one, for the log, so a log in a question for help is always readable.- A text can be filled into another one; both come out in the same language.
follow_computer()asks the computer for its language once (GetUserDefaultUILanguageon Windows, the preferred languages on a Mac). Only the desktop program calls it. The start-up page of a Docker installation stays in English, because the computer it runs on is not the one that shows it.LIBREPHOTOS_LANGUAGE=deoverrides the language, to see a text without changing the computer.
Quit LibrePhotos
Quit LibrePhotos in the web app's account menu calls POST /api/desktop-app/quit/. GET /api/desktop-app/ says
whether the item is shown, and how the closed page tells its reader to open LibrePhotos again: the icon on the desktop
or the Start menu entry if it is there, the Dock or the Applications folder on a Mac
(librephotos/ways_to_open.py).
A page from somewhere else must not be able to close the program, so api/accounts/this_computer.py only accepts a
request
- from a loopback connection: the address of the connection, not a header,
- without a header a proxy adds (
X-Forwarded-For,Forwarded, ...), - whose
Hostnames this computer, so a name that points to127.0.0.1(DNS rebinding) does not count, - whose
Origin, if any, is that host, and whoseSec-Fetch-Site, if any, issame-origin, - with an admin's access token in the
Authorizationheader, which a form or an image of another page cannot send; the cookies alone are not enough.
A proxy that adds no header looks like this computer to the program. So the web app only asks for it when the address in
the browser is localhost, 127.x.x.x or [::1] (useDesktopAppQuery).
While the program closes, /api/healthz answers {"status": "ok", "closing": true} and /api/healthz/ready/
answers 503 closing. So the open page waits for the next LibrePhotos instead of going back to the one that ends, and
a second start waits for the data folder instead of opening a page that is about to disappear. Model:
verification/platform/QuitFromPage.tla.
Start with the computer
GET /api/desktop-app/ also says whether LibrePhotos opens with the computer (starts_with_computer, null where it
cannot) and whether the web app should ask for it (ask_to_start_with_computer). It asks an admin whose account is older
than this start, once there are photos, so not in the middle of the first setup. POST /api/desktop-app/start-with-computer/ takes {"on": true},
{"on": false} or {"on": null}, which means "asked, leave it as it is". It accepts the same requests as Quit LibrePhotos.
The computer's own entry is the only state: the Run value on Windows, the launch agent on a Mac. The database only
remembers that the question was answered (START_WITH_COMPUTER_ASKED), after the entry is written. No sends null,
so a second tab that still shows the question cannot undo the Yes of the first. Model:
verification/platform/StartWithComputer.tla.
The page for a closed LibrePhotos
A browser shows its own error page when nothing answers at an address. public/closed-page.js is a service worker that
shows "LibrePhotos is closed" there instead. It only handles opening a page, always asks LibrePhotos first, and keeps
nothing of LibrePhotos except that one page. components/desktopapp/closedPage.ts writes the page in the web app's
language, with the way to open LibrePhotos that is true on that computer, and registers the worker only in the desktop program and
only on that computer. Everywhere else, for example in a Docker installation, it removes the worker again.
The address can belong to another program later. After every page that was answered, the worker asks /api/healthz. If the
answer is not the {"status": "ok"} of LibrePhotos, it removes itself and its page, so it never speaks for that program. If
nothing answers, it stays. So one thing remains: after LibrePhotos was uninstalled and while nothing uses its address, this
browser still says "LibrePhotos is closed" there, until the site data of the address is deleted. Nothing can tell the worker
that LibrePhotos is gone for good.
Show in Finder / Show in File Explorer
Not released yet (comes after 1.7.0) POST /api/photos/<id>/show-in-folder/ opens the file manager of the computer LibrePhotos runs
on. It takes a photo, never a path, and follows the rules above, with one difference: any signed-in user may call it,
for the photos they own. GET /api/desktop-app/ is therefore for every signed-in user, and its platform decides the
label in the web app. Nothing counts as this computer on a demo site (DEMO_SITE). The file must be inside a library folder of the photo's
owner, or inside the folder their Nextcloud photos are downloaded to, otherwise the answer is 409 not_in_library.
api/photos/show_in_folder.py picks the files: the main file, then the photo's other files in the same folder, without
sidecars. It looks at the drive and calls the file manager in a thread of its own, because a sleeping or unplugged
drive can take a long time to answer. After ANSWER_SECONDS the request answers 202 and the folder opens when the
drive does; at most AT_ONCE requests wait like that (one more is answered with 429), and a folder that would open later than LATEST_SECONDS after
the click does not open any more. A file that is there only counts when its drive is the one LibrePhotos knows
(LibraryDrives.away): another stick can have the same letter and a file of the same name. That is answered with
404 another_drive and the text of api/photos/right_drive.py, an unplugged drive with 404 drive_not_connected.
librephotos/file_manager.py is the only place that talks to the system:
- Windows:
SHOpenFolderAndSelectItems, notexplorer /select,, which takes one file only and has its own rules for commas and quotes in names. Windows does not let a program in the background put a window in front, so the module first sends an emptySendInput, after whichAllowSetForegroundWindowis granted to Explorer. Now and then Explorer opens the new window and answers with an error instead of selecting the file; the module then asks again, and Explorer selects it in the open window. - macOS:
NSWorkspace.activateFileViewerSelectingURLson the main thread, where the run loop of the menu bar icon is. macOS asks no permission question for it.
No model in verification/: nothing is saved, and no request depends on another one.