mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Changing the music folder offers to move everything
- Move everything: files are moved (renamed on the same drive, copied across drives), with play counts, likes, history, playlists and linked folders carried over - Or keep them where they are: the old folder stays in your library - Name clashes keep both files; identical duplicates aren't copied twice - Refused while downloads are running
This commit is contained in:
@@ -1151,10 +1151,53 @@ function bindCommit() {
|
||||
|
||||
async function chooseFolder() {
|
||||
const path = await invoke("pick_folder").catch(() => null);
|
||||
if (!path) return;
|
||||
state.settings = await invoke("save_settings", { patch: { outputDir: path } });
|
||||
updateCommit();
|
||||
renderSettings();
|
||||
const old = state.settings.outputDir;
|
||||
if (!path || path === old) return;
|
||||
const report = await invoke("folder_report", { path: old }).catch(() => ({ files: 0, bytes: 0 }));
|
||||
if (!report.files) {
|
||||
state.settings = await invoke("save_settings", { patch: { outputDir: path } });
|
||||
updateCommit();
|
||||
renderSettings();
|
||||
return;
|
||||
}
|
||||
const body = h("div", { class: "stack" },
|
||||
h("p", {}, `Your current folder has ${plural(report.files, "file")} (${fmtBytes(report.bytes)}).`),
|
||||
h("div", { class: "move-paths" }, h("code", {}, old), icon("arrow-right"), h("code", {}, path)),
|
||||
h("p", { class: "muted small" }, "Moving keeps your play counts, likes, history and playlists. If you keep them where they are, Atmosphere still shows them in your library."));
|
||||
const choice = await modal("Move your music to the new folder?", body, [{ label: "Keep them where they are", value: "keep" }, { label: "Move everything", value: "move", primary: true }]);
|
||||
if (!choice) return;
|
||||
if (choice === "keep") {
|
||||
const folders = [...new Set([...(state.settings.libraryFolders || []), old, path])];
|
||||
state.settings = await invoke("save_settings", { patch: { outputDir: path, libraryFolders: folders } });
|
||||
updateCommit();
|
||||
renderSettings();
|
||||
invoke("library_scan").catch(() => {});
|
||||
return;
|
||||
}
|
||||
const bar = h("div", { class: "update-bar" }, h("span", { class: "update-fill" }));
|
||||
const label = h("p", { class: "muted small" }, "Starting…");
|
||||
const wrap = h("div", { class: "modal-wrap" }, h("div", { class: "modal", role: "dialog", "aria-modal": "true", "aria-label": "Moving music" }, h("h2", {}, "Moving your music"), bar, label));
|
||||
document.body.append(wrap);
|
||||
const off = await listen("atmosphere://move", (e) => {
|
||||
const { done, total } = e.payload || {};
|
||||
if (total) {
|
||||
bar.firstChild.style.width = `${((done / total) * 100).toFixed(1)}%`;
|
||||
label.textContent = `${done} of ${plural(total, "file")}`;
|
||||
}
|
||||
});
|
||||
try {
|
||||
const r = await invoke("move_music", { to: path });
|
||||
state.settings = await invoke("get_settings");
|
||||
toast(r.failed.length ? `Moved ${plural(r.moved, "file")}. ${r.failed.length} couldn't be moved and stayed put.` : `Moved ${plural(r.moved, "file")} to the new folder`, r.failed.length ? "err" : "ok");
|
||||
await loadLibrary();
|
||||
} catch (e) {
|
||||
toast(errText(e), "err");
|
||||
} finally {
|
||||
off();
|
||||
wrap.remove();
|
||||
updateCommit();
|
||||
renderSettings();
|
||||
}
|
||||
}
|
||||
|
||||
function updateCommit() {
|
||||
|
||||
@@ -1165,3 +1165,8 @@ body.mini-mode > *:not(#mini):not(.toasts):not(.modal-wrap):not(script) { displa
|
||||
.pick-page.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
.pick-page.dim { opacity: 0.6; }
|
||||
.pick-page span { font-size: 12px; color: var(--text-2); }
|
||||
|
||||
/* moving folders */
|
||||
.move-paths { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: var(--s2); align-items: center; }
|
||||
.move-paths code { font-size: 12px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2, var(--surface)); border: 1px solid var(--hairline); overflow-wrap: anywhere; }
|
||||
.move-paths .i { color: var(--text-3); }
|
||||
|
||||
Reference in New Issue
Block a user