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
7 changes: 6 additions & 1 deletion .github/workflows/recover-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,10 @@ jobs:
run: |
set -euo pipefail
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name complete-release --dir out
notes="docs/releases/$VERSION.md"
if [ ! -f "$notes" ]; then
notes="$RUNNER_TEMP/release-notes.md"
printf '%s\n' "Private Music $VERSION: Windows, macOS, Linux and Android." > "$notes"
fi
gh release create "$TAG" out/* --repo "$GITHUB_REPOSITORY" --verify-tag --latest \
--title "Private Music $VERSION" --notes-file "docs/releases/$VERSION.md"
--title "Private Music $VERSION" --notes-file "$notes"
5 changes: 4 additions & 1 deletion engine/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ impl Shared {
self.start_current(inner, events);
} else {
self.cancel_recovery(inner, events);
// Следующее нажатие Play снова может взять файл с диска. Иначе один сбой
// офлайн-копии навсегда предпочитает сеть.
inner.refreshed.clear();
inner.status = Status::Idle;
self.remote().stop();
events.push(UiEvent::State(inner.state()));
Expand Down Expand Up @@ -1101,7 +1104,7 @@ impl Controller {
/// же позиция, полный набор попыток.
pub fn retry(&self) {
self.shared.with(|inner, events| {
if inner.queue.current().is_none() || inner.source_offline {
if inner.queue.current().is_none() {
return;
}
let position = inner.position;
Expand Down
3 changes: 3 additions & 0 deletions engine/src/media_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ pub fn apply(controller: &Controller, action: MediaAction) {
MediaAction::Play => match state.status {
Status::Paused => controller.resume(),
Status::Idle => controller.toggle(),
// Гарнитура и экран блокировки шлют Play, пока трек ещё грузится. Пустой
// ответ оставлял воспроизведение висеть; повтор стартует текущий трек заново.
Status::Loading | Status::Buffering => controller.retry(),
_ => {}
},
MediaAction::Pause => {
Expand Down
18 changes: 17 additions & 1 deletion engine/src/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ impl OfflineStore {
};
let mut index = self.lock();
let previous = index.insert(track.id(), entry.clone());
self.write_index(&index)?;
if let Err(error) = self.write_index(&index) {
index.remove(&track.id());
if let Some(previous) = previous { index.insert(previous.track.id(), previous); }
let _ = fs::remove_file(self.dir.join(&entry.file));
return Err(error);
}
if let Some(previous) = previous.filter(|old| old.file != entry.file) {
let _ = fs::remove_file(self.dir.join(&previous.file));
}
Expand Down Expand Up @@ -252,6 +257,17 @@ mod tests {
}
}

#[test]
fn a_failed_index_write_removes_the_new_file_and_keeps_the_old_index() {
let dir = tempfile::tempdir().unwrap();
let store = OfflineStore::open(dir.path()).unwrap();
fs::create_dir(dir.path().join(INDEX)).unwrap();
let error = store.save(&track(7, 1), ElementaryKind::Mp3, b"audio").unwrap_err();
assert!(matches!(error, Error::Stream(_)));
assert!(store.list().is_empty(), "the in-memory index rolls back");
assert!(!dir.path().join("7_1.mp3").exists(), "the audio file is not left without an index");
}

#[test]
fn saves_lists_and_survives_a_restart() {
let dir = tempfile::tempdir().unwrap();
Expand Down
8 changes: 5 additions & 3 deletions ui-tests/ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2839,11 +2839,13 @@ test("product: tuned mix identities, playlist locators and restored track metada
const valid=playlistLink('https://vk.com/music?z=audio_playlist-123_456_key%2Ftest');
const invalid=['https://evil.example/playlist/-123_456','https://[email protected]/playlist/-123_456','https://vk.com/playlist/0_1','https://vk.com/playlist/1_0','https://vk.com:444/playlist/-1_2'].every(url=>{try{playlistLink(url);return false;}catch{return true;}});
const track={track_id:1,owner_id:7,title:'t',artist:'a',duration:200,artists:[{id:'artist1',name:'a'}],album:{album_id:12,owner_id:-1,title:'album'},stream_url:'secret-expiring-url'};
saveQueue([track],0,73);const saved=loadQueue();
return {a,b,c,colors:new Set(colors).size,valid,invalid,mood:moodMatch('Desktop stop',['top']),saved};
const radio={source:{kind:'catalog',mix_id:'common',options:null},next_offset:40};
saveQueue([track],0,73,{source:radio.source,next_offset:40,secret:'drop-me'});const saved=loadQueue();
saveQueue([track],0,1,{source:{kind:'nope'},next_offset:1});const dropped=loadQueue();
return {a,b,c,colors:new Set(colors).size,valid,invalid,mood:moodMatch('Desktop stop',['top']),saved,radio,dropped};
});
assert.equal(output.a,output.b);assert.notEqual(output.a,output.c);assert.ok(output.colors>=10);assert.equal(output.valid.owner_id,-123);assert.equal(output.valid.access_key,'key');assert.equal(output.invalid,true);assert.equal(output.mood,false);
assert.equal(output.saved.position,73);assert.equal(output.saved.tracks[0].album.album_id,12);assert.equal(output.saved.tracks[0].artists[0].id,'artist1');assert.equal(output.saved.tracks[0].stream_url,null);assert.deepEqual(app.problems,[]);
assert.equal(output.saved.position,73);assert.equal(output.saved.tracks[0].album.album_id,12);assert.equal(output.saved.tracks[0].artists[0].id,'artist1');assert.equal(output.saved.tracks[0].stream_url,null);assert.deepEqual(output.saved.radio,output.radio);assert.equal(output.dropped.radio,null);assert.deepEqual(app.problems,[]);
}finally{await app.close();}
});

Expand Down
15 changes: 12 additions & 3 deletions ui/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,12 @@ async function applyStartupState() {
set("player", state);
if (state.queue_len === 0) {
const saved = loadQueue();
if (saved) await api.loadQueue(saved.tracks, saved.index, saved.position);
if (saved) {
if (saved.radio) await api.restoreRadio(saved.radio, saved.tracks, saved.index, saved.position);
else await api.loadQueue(saved.tracks, saved.index, saved.position);
// Выход мог случиться, пока очередь читалась с диска.
if (shell !== activeShell || !store.session.signed_in) return;
}
}
} catch (error) {
toast(errorText(error), { error: true });
Expand Down Expand Up @@ -652,6 +657,10 @@ function onBackendEvent(event) {
set("session", session);
signedOut();
toast(t("error.unauthorized"), { error: true });
}).catch(() => {
set("session", { signed_in: false, profile: null, persistent: true });
signedOut();
toast(t("error.unauthorized"), { error: true });
});
break;
}
Expand All @@ -662,13 +671,13 @@ function scheduleQueueSave(state) {
const now = Date.now();
if (now - lastQueueSave < 5000 || !state.track) return;
lastQueueSave = now;
saveQueue(store.queue.tracks, state.queue_index, state.position);
saveQueue(store.queue.tracks, state.queue_index, state.position, state.radio_context);
}

subscribe("queue", ({ tracks, current }) => {
lastQueueSave = Date.now();
const sameTrack = tracks[current] && store.player.track && trackKey(tracks[current]) === trackKey(store.player.track);
saveQueue(tracks, current, sameTrack ? store.player.position : 0);
saveQueue(tracks, current, sameTrack ? store.player.position : 0, store.player.radio_context);
});

// ------------------------------------------------------------------ ярлыки
Expand Down
2 changes: 2 additions & 0 deletions ui/js/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ async function connectivityBack() {
else showChip(t("net.failed"), "failed");
return;
}
// Сессия недействительна: API ответил, но это не «связь восстановлена».
return;
}
}
if (mine === connectionGeneration) confirmedBack(store.session.signed_in);
Expand Down
7 changes: 4 additions & 3 deletions ui/js/persist.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { radioSnapshot } from "./radio-snapshot.js";
import { PALETTES } from "./themes.js";
// Что сохраняется при перезапуске: громкость, перемешивание, повтор и последняя очередь. Хранится в
// собственном localStorage окна; здесь никогда не хранятся никакие учетные данные.
Expand Down Expand Up @@ -95,7 +96,7 @@ function trim(track) {
};
}

export function saveQueue(tracks, index, position) {
export function saveQueue(tracks, index, position, radio = null) {
if (!tracks.length || index == null || index < 0 || index >= tracks.length) {
try { localStorage.removeItem(QUEUE); } catch { /* хранилище может быть недоступно */ }
return;
Expand All @@ -106,15 +107,15 @@ export function saveQueue(tracks, index, position) {
start = Math.max(0, Math.min(index - 50, tracks.length - MAX_SAVED));
end = start + MAX_SAVED;
}
write(QUEUE, { tracks: tracks.slice(start, end).map(trim), index: index - start, position });
write(QUEUE, { tracks: tracks.slice(start, end).map(trim), index: index - start, position, radio: radioSnapshot(radio) });
}

export function loadQueue() {
const saved = read(QUEUE);
if (!saved || !Array.isArray(saved.tracks) || !saved.tracks.length) return null;
const index = Number.isInteger(saved.index) ? saved.index : 0;
if (index < 0 || index >= saved.tracks.length) return null;
return { tracks: saved.tracks, index, position: Number.isFinite(saved.position) ? saved.position : 0 };
return { tracks: saved.tracks, index, position: Number.isFinite(saved.position) ? saved.position : 0, radio: radioSnapshot(saved.radio) };
}

export function clearQueue() {
Expand Down
Loading