Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
refactor: one delete for saved translations, and the Keychain is asked only for a song a translator is offered for
My-Name-Is-Jeff95a8a06b680f
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.mindex 27644f4a..79355972 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m@@ -1922,10 +1922,13 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {// what the song has: a switch for each, reading what tapping it will do.- (void)offerExtras {NSString *language = SGLyricsTranslationTarget();- BOOL ai = SGAITranslatorReady(), onDevice = SGOnDeviceTranslation.translationAvailable;- BOOL intelligence = [SGOnDeviceTranslation appleIntelligenceAvailable:language];- // A translator is offered only for a song in another language than the one it would translate into.- BOOL translatable = (_foreign || SGHidden(SGKeyLyricsTranslateEverySong)) && _untranslated && (ai || onDevice || intelligence);+ // A translator is offered only for a song in another language than the one it would translate into,+ // and the translators are asked after (an AI translator's key is a Keychain read).+ BOOL wanted = _lines && !_sample && (_foreign || SGHidden(SGKeyLyricsTranslateEverySong)) && _untranslated;+ BOOL onDevice = wanted && SGOnDeviceTranslation.translationAvailable;+ BOOL intelligence = wanted && [SGOnDeviceTranslation appleIntelligenceAvailable:language];+ BOOL ai = wanted && SGAITranslatorReady();+ BOOL translatable = ai || onDevice || intelligence;BOOL offered = _lines && !_sample && (_hasSpoken || _hasTranslation || translatable);if (!offered) {_extrasBox.hidden = YES;diff --git a/tweak/Sources/Shared/LyricsTranslation/SavedTranslations.m b/tweak/Sources/Shared/LyricsTranslation/SavedTranslations.mindex 793b5e87..1d1144c1 100644--- a/tweak/Sources/Shared/LyricsTranslation/SavedTranslations.m+++ b/tweak/Sources/Shared/LyricsTranslation/SavedTranslations.m@@ -100,19 +100,23 @@ SGTranslationSource *SGLyricsSaveTranslation(NSString *track, NSString *languagereturn [SGTranslationSource by:source.by model:source.model made:now];}-void SGLyricsDeleteSavedTranslation(NSString *track, NSString *language) {- if (!track.length || !language.length) return;- SGLyricsForgetAITranslation(track, language);- // After any write still queued, so it cannot bring the file back.+// After any write still queued, so it cannot bring a file back.+static void deleteQueued(NSURL *url, NSString *what) {dispatch_async(writes(), ^{- [NSFileManager.defaultManager removeItemAtURL:fileFor(track, language) error:nil];+ [NSFileManager.defaultManager removeItemAtURL:url error:nil];dispatch_async(dispatch_get_main_queue(), ^{- SGLog(@"translation: %@ in %@ deleted", track, language);+ SGLog(@"translation: %@ deleted", what);[NSNotificationCenter.defaultCenter postNotificationName:SGLyricsTranslationsDidChangeNotification object:nil];});});}+void SGLyricsDeleteSavedTranslation(NSString *track, NSString *language) {+ if (!track.length || !language.length) return;+ SGLyricsForgetAITranslation(track, language);+ deleteQueued(fileFor(track, language), [NSString stringWithFormat:@"%@ in %@", track, language]);+}+static NSString *summary(void) {NSArray<NSURL *> *all = files();if (!all.count) return @"None";@@ -134,14 +138,7 @@ SGModRow *SGSavedTranslationsRow(void) {message:@"Songs translated before are translated again the next time you ask." preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {SGLyricsForgetAITranslation(nil, nil);- // After any write still queued, so it cannot bring a song's file back.- dispatch_async(writes(), ^{- [NSFileManager.defaultManager removeItemAtURL:folder() error:nil];- dispatch_async(dispatch_get_main_queue(), ^{- SGLog(@"translation: saved translations deleted");- [NSNotificationCenter.defaultCenter postNotificationName:SGLyricsTranslationsDidChangeNotification object:nil];- });- });+ deleteQueued(folder(), @"saved translations");}]];[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];[SGTopController() presentViewController:alert animated:YES completion:nil];