Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear playlistItems when navigating on YT #2587

Open
wants to merge 14 commits into
base: feature/Playlists
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fixed videos expiring and logic for NowPlaying bar.

  • Loading branch information
Brandon-T committed Apr 14, 2020
commit 67bee5c8836214746400ab165c2ab5ab50e53ef1
@@ -2149,11 +2149,6 @@ extension BrowserViewController: TabDelegate {
guard let self = self else { return }
self.onUpdateNowPlaying(tab: tab)
}.bind(to: tab)

tab.existingPlaylistItems.observe { [weak self] _, _ in
guard let self = self else { return }
self.onUpdateNowPlaying(tab: tab)
}.bind(to: tab)
}

func tab(_ tab: Tab, willDeleteWebView webView: WKWebView) {
@@ -3563,31 +3558,27 @@ extension BrowserViewController: NowPlayingBarDelegate {
}

func onUpdateNowPlaying(tab: Tab) {
let items = tab.playlistItems.value + tab.existingPlaylistItems.value
if items.isEmpty {

let newItems = tab.playlistItems.value.filter({ !Playlist.shared.itemExists(item: $0) })
let existingItems = tab.playlistItems.value.filter({ Playlist.shared.itemExists(item: $0) })

//Items for this tab already exist in the playlist..
if !existingItems.isEmpty {
nowPlayingBar.isHidden = false

if Playlist.shared.currentlyPlayingInfo.value != nil {
nowPlayingBar.state = .addedNowPlaying
} else {
nowPlayingBar.state = .existing
}
} else if newItems.isEmpty { //No playlist items found on the page..
if Playlist.shared.currentlyPlayingInfo.value != nil {
nowPlayingBar.state = .nowPlaying
nowPlayingBar.isHidden = false
} else {
nowPlayingBar.isHidden = true
}
} else if items.count == 1 {
nowPlayingBar.isHidden = false

if Playlist.shared.itemExists(item: items[0]) {
if Playlist.shared.currentlyPlayingInfo.value != nil {
nowPlayingBar.state = .addedNowPlaying
} else {
nowPlayingBar.state = .existing
}
} else {
if Playlist.shared.currentlyPlayingInfo.value != nil {
nowPlayingBar.state = .addNowPlaying
} else {
nowPlayingBar.state = .add
}
}
} else {
} else if !newItems.isEmpty {
nowPlayingBar.isHidden = false

if Playlist.shared.currentlyPlayingInfo.value != nil {
@@ -123,7 +123,6 @@ extension BrowserViewController: WKNavigationDelegate {

if url.scheme == "about" {
self.tabManager.tabForWebView(webView)?.playlistItems.value = []
self.tabManager.tabForWebView(webView)?.existingPlaylistItems.value = []
decisionHandler(.allow)
return
}
@@ -261,7 +260,6 @@ extension BrowserViewController: WKNavigationDelegate {
self.tabManager.selectedTab?.blockAllAlerts = false
}
self.tabManager.tabForWebView(webView)?.playlistItems.value = []
self.tabManager.tabForWebView(webView)?.existingPlaylistItems.value = []
decisionHandler(.allow)
return
}
@@ -141,8 +141,8 @@ class PlaylistManager: TabContentScript {
do {
guard let item = try PlaylistInfo.from(message: message) else { return }

//Update playlist with new items..
if !Playlist.shared.itemExists(item: item) {
//Update playlist existing items..
if let items = tab?.playlistItems, let index = items.value.firstIndex(where: { $0.src == item.src }) {
if items.value[index].duration < 0.01 {
items.value[index].duration = item.duration
@@ -154,16 +154,9 @@ class PlaylistManager: TabContentScript {
}
}
} else {
//Update playlist with existing items..
if let items = tab?.existingPlaylistItems, let index = items.value.firstIndex(where: { $0.src == item.src }) {
if items.value[index].duration < 0.01 {
items.value[index].duration = item.duration
items.refresh()
}
} else {
if !item.src.isEmpty {
tab?.existingPlaylistItems.value.append(item)
}
//Update playlist with new items..
if !item.src.isEmpty, tab?.playlistItems.value.contains(where: { $0.src == item.src }) != true {
tab?.playlistItems.value.append(item)
}
}
} catch {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.