Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos: what is added with an album open goes into that album too

Yashwanth Kamireddi00548c715376
diff --git a/.uiverify/photos-albums.mjs b/.uiverify/photos-albums.mjs
index 05c2d72..055c3e5 100644
--- a/.uiverify/photos-albums.mjs
+++ b/.uiverify/photos-albums.mjs
@@ -62,6 +62,18 @@ await page.locator(".row-menu").getByText("Delete Album").click();
await page.waitForTimeout(250);
ok(!(await albumNames()).includes("Sea") && (await page.locator(".px-bar h1").innerText()) === "Library", "Delete Album, once agreed, removes it and goes back to the library");
+// With an album open, what is added goes into it too, and a drop says so.
+await page.locator(".px-albums .px-source", { hasText: "Trips" }).click();
+await page.waitForTimeout(200);
+await page.evaluate(() => { window.__pick = ["/home/test/Pictures/ferry.jpg"]; });
+await page.getByRole("button", { name: "Add Photos" }).click();
+await page.waitForTimeout(300);
+ok((await page.evaluate(() => window.__photoUploadAlbums?.at(-1))) === "AL1", "Add Photos with an album open puts them in it too");
+ok((await page.locator(".px").getAttribute("data-drop-label")) === "Add to Trips", "and a drop there reads Add to Trips");
+await page.locator(".px-source", { hasText: "Library" }).click();
+await page.waitForTimeout(200);
+ok((await page.locator(".px").getAttribute("data-drop-label")) === "Add to Library", "in the library, Add to Library");
+await page.evaluate(() => window.__emit?.("quince://photo-upload", { id: "B1:0", batch: "B1", name: "ferry.jpg", within: "", folder: false, error: null, state: "cancelled", sent: 0, total: 1 }));
await page.evaluate(() => { window.__albumFail = true; });
await page.getByRole("button", { name: "New Album" }).click();
await page.getByLabel("Album name").fill("Nope");
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 0b675e9..ca63d53 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -373,6 +373,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
// Each file is answered at once with where it stands; a test plays the rest in with __emit.
case "photos_upload": {
(window.__photoUploads ??= []).push(args.paths);
+ (window.__photoUploadAlbums ??= []).push(args.album ?? null);
const batch = `B${window.__photoUploads.length}`;
const say = (e) => window.__emit?.("quince://photo-upload", { batch, within: "", sent: 0, total: 1000, folder: false, error: null, ...e });
window.__photoLive = args.paths.map((path, i) => ({ id: `${batch}:${i}`, name: path.split("/").pop() }));
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index 75a039f..68da02a 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -99,6 +99,9 @@ pub struct Upload {
pub error: Option<String>,
pub asset: Option<String>,
pub added_at: i64,
+ /// The album open when it was added: the photo goes into it too, as in Photos.
+ #[serde(default)]
+ pub album: Option<String>,
}
/// Which photos a view shows.
@@ -280,9 +283,9 @@ impl Library {
let tx = self.conn.transaction()?;
for u in uploads {
tx.execute(
- "INSERT OR IGNORE INTO photo_uploads (id, batch, path, name, state, error, asset, added_at)
- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
- params![u.id, u.batch, u.path, u.name, u.state, u.error, u.asset, u.added_at],
+ "INSERT OR IGNORE INTO photo_uploads (id, batch, path, name, state, error, asset, added_at, album)
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
+ params![u.id, u.batch, u.path, u.name, u.state, u.error, u.asset, u.added_at, u.album],
)?;
}
tx.commit()?;
@@ -307,7 +310,7 @@ impl Library {
/// Uploads not yet finished, oldest first: what a launch resumes.
pub fn unfinished_uploads(&self) -> Result<Vec<Upload>> {
let mut stmt = self.conn.prepare(
- "SELECT id, batch, path, name, state, error, asset, added_at FROM photo_uploads
+ "SELECT id, batch, path, name, state, error, asset, added_at, album FROM photo_uploads
WHERE state IN ('waiting', 'sending', 'verifying') ORDER BY added_at, id",
)?;
let rows = stmt.query_map([], |r| {
@@ -320,6 +323,7 @@ impl Library {
error: r.get(5)?,
asset: r.get(6)?,
added_at: r.get(7)?,
+ album: r.get(8)?,
})
})?;
Ok(rows.collect::<std::result::Result<_, _>>()?)
diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rs
index 488e668..79642f0 100644
--- a/crates/quince-core/src/schema.rs
+++ b/crates/quince-core/src/schema.rs
@@ -451,4 +451,8 @@ pub const MIGRATIONS: &[&str] = &[
ALTER TABLE photos ADD COLUMN caption TEXT;
UPDATE sync_state SET token = NULL WHERE service = 'photos';
"#,
+ // The album open when a photo was added to Photos, which it goes into once Apple has it.
+ r#"
+ ALTER TABLE photo_uploads ADD COLUMN album TEXT;
+ "#,
];
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index 830976a..730769c 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -639,6 +639,7 @@ fn cancelled(u: &quince_core::photos::Upload) -> bool {
#[tauri::command]
pub async fn photos_upload(
paths: Vec<String>,
+ album: Option<String>,
app: AppHandle,
data: State<'_, Data>,
) -> UiResult<String> {
@@ -686,6 +687,7 @@ pub async fn photos_upload(
error: None,
asset: None,
added_at: now,
+ album: album.clone(),
};
if let Some(r) = quince_icloud::photos_upload::refusal(&name, size) {
u.state = "failed".into();
@@ -835,6 +837,7 @@ async fn one(app: &AppHandle, u: quince_core::photos::Upload) -> bool {
Ok(Some(_))
) {
set("done", None, Some(asset)).await;
+ into_album(app, &http, &ck, &params, &u, asset).await;
say(app, &u, "done", 1, 1, None);
refresh_photos(app).await;
return true;
@@ -955,6 +958,7 @@ async fn one(app: &AppHandle, u: quince_core::photos::Upload) -> bool {
match result {
Ok(Outcome::Uploaded(made)) => {
set("done", None, Some(&made.asset)).await;
+ into_album(app, &http, &ck, &params, &u, &made.asset).await;
say(app, &u, "done", size, size, None);
refresh_photos(app).await;
return true;
@@ -996,6 +1000,59 @@ async fn one(app: &AppHandle, u: quince_core::photos::Upload) -> bool {
}
}
+/// A photo added while an album was open goes into that album too, after what is there, as
+/// Photos files an import. The upload itself has already succeeded: if the album is gone, or
+/// Apple refuses, the photo stays in the library and only this step is skipped.
+async fn into_album(
+ app: &AppHandle,
+ http: &reqwest::Client,
+ ck: &str,
+ params: &[(String, String)],
+ u: &quince_core::photos::Upload,
+ asset: &str,
+) {
+ let Some(album) = u.album.as_deref() else {
+ return;
+ };
+ let _one = crate::PHOTOS_PASS.lock().await;
+ let data = app.state::<Data>();
+ let last = {
+ let library = data.0.lock().await;
+ if !library
+ .albums()
+ .map(|a| a.iter().any(|x| x.id == album))
+ .unwrap_or(false)
+ {
+ return;
+ }
+ library.album_last_position(album).ok().flatten()
+ };
+ match quince_icloud::photos::add_to_album(
+ http,
+ ck,
+ params.to_vec(),
+ album,
+ &[asset.to_string()],
+ last,
+ )
+ .await
+ {
+ Ok(placed) => {
+ data.0
+ .lock()
+ .await
+ .put_album_items(
+ &placed
+ .into_iter()
+ .map(|(a, at)| (album.to_string(), a, at))
+ .collect::<Vec<_>>(),
+ )
+ .ok();
+ }
+ Err(e) => eprintln!("photos upload: {} not put in its album: {e}", u.name),
+ }
+}
+
async fn refresh_photos(app: &AppHandle) {
use tauri::Emitter;
let auth = app.state::<Auth>();
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index e4efad1..b36541c 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -102,7 +102,8 @@ export const api = {
photoSetCaption: (id: string, caption: string) => invoke<Photo>("photo_set_caption", { id, caption }),
/** Photos and videos (or folders of them) into the library. Answers the batch; progress
* arrives as PHOTO_UPLOAD events, in the same shape as Drive's. */
- photosUpload: (paths: string[]) => invoke<string>("photos_upload", { paths }),
+ /** Into the library, and into `album` too when one is open. */
+ photosUpload: (paths: string[], album?: string) => invoke<string>("photos_upload", { paths, album: album ?? null }),
photosAlbumCreate: (name: string) => invoke<PhotoAlbum>("photos_album_create", { name }),
photosAlbumRename: (id: string, name: string) => invoke<void>("photos_album_rename", { id, name }),
photosAlbumDelete: (id: string) => invoke<void>("photos_album_delete", { id }),
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 977d95b..0e81ef3 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -1064,11 +1064,12 @@ export function PhotosView() {
const add = useCallback(async (paths: string[]) => {
if (paths.length === 0) return;
try {
- await api.photosUpload(paths);
+ // With an album open, what is added goes into it too, as Photos files an import.
+ await api.photosUpload(paths, album?.id);
} catch (e) {
setError(messageOf(e));
}
- }, []);
+ }, [album]);
const choose = async () => {
try {
@@ -1191,7 +1192,7 @@ export function PhotosView() {
);
return (
- <div className={`px${dropping ? " is-dropping" : ""}`}>
+ <div className={`px${dropping ? " is-dropping" : ""}`} data-drop-label={album ? `Add to ${album.name}` : "Add to Library"}>
<aside className="px-side" aria-label="Photos">
<p className="px-side-heading">Photos</p>
{VIEWS.map(source)}
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 630e747..2c83876 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -176,7 +176,7 @@
repaints it every frame the pointer moves. */
.px { position: relative; }
.px.is-dropping::after {
- content: "Add to Library";
+ content: attr(data-drop-label);
position: absolute;
inset: 8px;
z-index: 3;