Skip to content

Commit

Permalink
Merge pull request ytmdesktop#765 from NovusTheory/continue-left-off-fix
Browse files Browse the repository at this point in the history
🐛 Fix continue where you left off
  • Loading branch information
mingjun97 authored Jul 13, 2021
2 parents 46c60aa + 3bdb382 commit 45ed2e7
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ async function createWindow() {
`)
}
initialized = true
settingsProvider.set('window-url', view.webContents.getURL())
view.webContents.insertCSS(`
/* width */
::-webkit-scrollbar {
Expand Down Expand Up @@ -586,6 +585,42 @@ async function createWindow() {
}
}

/**
* Update the saved url if settings-continue-where-left-of is enabled
*/
if (settingsProvider.get('settings-continue-where-left-of')) {
view.webContents
.executeJavaScript(
`
document.querySelector('.yt-uix-sessionlink').href;
`
)
.then((result) => {
if (result) {
const url = new URL(result)
// Hostname correction as the provided url is for youtube.com
url.hostname = 'music.youtube.com'
settingsProvider.set(
'window-url',
url.toString()
)
} else {
// No session link found so just default to the current url
settingsProvider.set(
'window-url',
view.webContents.getURL()
)
}
})
.catch(() => {
// JavaScript errored, assume no session link found and default to current url
settingsProvider.set(
'window-url',
view.webContents.getURL()
)
})
}

writeLog({ type: 'info', data: `Listen: ${title} - ${author}` })
discordRPC.setActivity(getAll())
}
Expand Down

0 comments on commit 45ed2e7

Please sign in to comment.