Skip to content

Commit

Permalink
fix: don't store torrentPath on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Mar 22, 2024
1 parent 17498e8 commit 36fa2e3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
7 changes: 5 additions & 2 deletions common/modules/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class TorrentClient extends WebTorrent {
player = ''
/** @type {ReturnType<spawn>} */
playerProcess = null
torrentPath = ''

constructor (ipc, storageQuota, serverMode, settingOverrides = {}, controller) {
const settings = { ...defaults, ...storedSettings, ...settingOverrides }
Expand All @@ -63,6 +64,9 @@ export default class TorrentClient extends WebTorrent {
ipc.on('player', (event, data) => {
this.player = data
})
ipc.on('torrentPath', (event, data) => {
this.torrentPath = data
})
this.settings = settings

this.serverMode = serverMode
Expand Down Expand Up @@ -212,7 +216,7 @@ export default class TorrentClient extends WebTorrent {
if (this.torrents.length) await this.remove(this.torrents[0])
const torrent = await this.add(data, {
private: this.settings.torrentPeX,
path: this.settings.torrentPath,
path: this.torrentPath,
destroyStoreOnDestroy: !this.settings.torrentPersist,
skipVerify,
announce
Expand Down Expand Up @@ -247,7 +251,6 @@ export default class TorrentClient extends WebTorrent {
this.playerProcess.once('close', () => {
this.playerProcess = null
const seconds = (Date.now() - startTime) / 1000
console.log(seconds)
this.dispatch('externalWatched', seconds)
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion common/views/Settings/TorrentSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<div class='input-group-prepend'>
<button type='button' use:click={handleFolder} class='btn btn-primary input-group-append'>Select Folder</button>
</div>
<input type='url' class='form-control bg-dark' bind:value={settings.torrentPath} placeholder='/tmp' />
<input type='url' class='form-control bg-dark' readonly value={settings.torrentPath} placeholder='/tmp' />
</div>
</SettingCard>
{/if}
Expand Down
20 changes: 20 additions & 0 deletions electron/src/main/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,25 @@ export default class Dialog {
sender.send('player', basename(path, extname(path)))
}
})
ipcMain.on('dialog', async ({ sender }) => {
const { filePaths, canceled } = await dialog.showOpenDialog({
title: 'Select torrent download location',
properties: ['openDirectory']
})
if (canceled) return
if (filePaths.length) {
let path = filePaths[0]
if (!(path.endsWith('\\') || path.endsWith('/'))) {
if (path.indexOf('\\') !== -1) {
path += '\\'
} else if (path.indexOf('/') !== -1) {
path += '/'
}
}
store.set('torrentPath', path)
torrentWindow.webContents.send('torrentPath', path)
sender.send('path', path)
}
})
}
}
1 change: 1 addition & 0 deletions electron/src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function createWindow () {
await torrentLoad
webtorrentWindow.webContents.postMessage('port', null, [port1])
webtorrentWindow.webContents.postMessage('player', store.get('player'))
webtorrentWindow.webContents.postMessage('torrentPath', store.get('torrentPath'))
sender.postMessage('port', null, [port2])
})
}
Expand Down
2 changes: 1 addition & 1 deletion electron/src/main/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ function parseDataFile (filePath, defaults) {
}
}

export default new Store('settings', { angle: 'default', player: '' })
export default new Store('settings', { angle: 'default', player: '', torrentPath: '' })
18 changes: 0 additions & 18 deletions electron/src/main/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ ipcMain.on('close', () => {
app.quit()
})

ipcMain.on('dialog', async ({ sender }) => {
const { filePaths, canceled } = await dialog.showOpenDialog({
properties: ['openDirectory']
})
if (canceled) return
if (filePaths.length) {
let path = filePaths[0]
if (!(path.endsWith('\\') || path.endsWith('/'))) {
if (path.indexOf('\\') !== -1) {
path += '\\'
} else if (path.indexOf('/') !== -1) {
path += '/'
}
}
sender.send('path', path)
}
})

ipcMain.on('version', ({ sender }) => {
sender.send('version', app.getVersion()) // fucking stupid
})
Expand Down

0 comments on commit 36fa2e3

Please sign in to comment.