From 36fa2e3313759e90289e235e96cf48c25fbb3db4 Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:57:46 +0100 Subject: [PATCH] fix: don't store torrentPath on UI --- common/modules/webtorrent.js | 7 +++++-- common/views/Settings/TorrentSettings.svelte | 2 +- electron/src/main/dialog.js | 20 ++++++++++++++++++++ electron/src/main/main.js | 1 + electron/src/main/store.js | 2 +- electron/src/main/util.js | 18 ------------------ 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/common/modules/webtorrent.js b/common/modules/webtorrent.js index b759ddd..6c3a7b4 100644 --- a/common/modules/webtorrent.js +++ b/common/modules/webtorrent.js @@ -37,6 +37,7 @@ export default class TorrentClient extends WebTorrent { player = '' /** @type {ReturnType} */ playerProcess = null + torrentPath = '' constructor (ipc, storageQuota, serverMode, settingOverrides = {}, controller) { const settings = { ...defaults, ...storedSettings, ...settingOverrides } @@ -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 @@ -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 @@ -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 { diff --git a/common/views/Settings/TorrentSettings.svelte b/common/views/Settings/TorrentSettings.svelte index 7ad9fd3..4ee5686 100644 --- a/common/views/Settings/TorrentSettings.svelte +++ b/common/views/Settings/TorrentSettings.svelte @@ -147,7 +147,7 @@
- + {/if} diff --git a/electron/src/main/dialog.js b/electron/src/main/dialog.js index 2d86468..0efc60b 100644 --- a/electron/src/main/dialog.js +++ b/electron/src/main/dialog.js @@ -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) + } + }) } } diff --git a/electron/src/main/main.js b/electron/src/main/main.js index a18165a..5f8439f 100644 --- a/electron/src/main/main.js +++ b/electron/src/main/main.js @@ -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]) }) } diff --git a/electron/src/main/store.js b/electron/src/main/store.js index 17f2806..c13aaee 100644 --- a/electron/src/main/store.js +++ b/electron/src/main/store.js @@ -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: '' }) diff --git a/electron/src/main/util.js b/electron/src/main/util.js index 754d1d7..72a0ecc 100644 --- a/electron/src/main/util.js +++ b/electron/src/main/util.js @@ -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 })