Skip to content

Commit

Permalink
feat: dpad navigation, wt error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Dec 8, 2023
1 parent 053c4ad commit e09053b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
3 changes: 2 additions & 1 deletion capacitor/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:banner="@drawable/banner">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name=".MainActivity"
Expand Down
2 changes: 1 addition & 1 deletion capacitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@capacitor/core": "^5.5.1",
"@capacitor/ios": "^5.5.1",
"@capacitor/status-bar": "^5.0.6",
"capacitor-nodejs": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.6/capacitor-nodejs.tgz",
"capacitor-nodejs": "https://github.com/funniray/Capacitor-NodeJS/releases/download/nodejs-18/capacitor-nodejs-1.0.0-beta.6.tgz",
"capacitor-plugin-safe-area": "^2.0.5",
"common": "workspace:*",
"cordova-plugin-navigationbar": "^1.0.31",
Expand Down
4 changes: 3 additions & 1 deletion capacitor/src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import TorrentClient from 'common/modules/webtorrent.js'
import { channel } from 'bridge'
import { statfs } from 'fs/promises'

async function storageQuota (directory) {
return Infinity
const { bsize, bavail } = await statfs(directory)
return bsize * bavail
}

if (typeof localStorage === 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion capacitor/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const capacitorConfig = {
patterns: [
{ from: join(__dirname, 'public', 'nodejs') }
]
}),
})
]
}

Expand Down
11 changes: 11 additions & 0 deletions common/modules/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ function navigateDPad (direction = 'up') {

closestElement.element.focus()
}
const keyMap = {
ArrowDown: 'down',
ArrowUp: 'up',
ArrowLeft: 'left',
ArrowRight: 'right'
}

document.addEventListener('keydown', e => {
e.preventDefault()
navigateDPad(keyMap[e.key])
})
13 changes: 6 additions & 7 deletions common/modules/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ export default class TorrentClient extends WebTorrent {
cat: new HTTPTracker({}, atob('aHR0cDovL255YWEudHJhY2tlci53Zjo3Nzc3L2Fubm91bmNl'))
}

process.on('uncaughtException', this.dispatchError.bind(this))
this.on('error', this.dispatchError.bind(this))
}

loadLastTorrent (t) {
const torrent = localStorage.getItem('torrent') || t
if (torrent) this.addTorrent(new Uint8Array(JSON.parse(torrent)), JSON.parse(localStorage.getItem('lastFinished')))
const torrent = localStorage.getItem('torrent') ? new Uint8Array(JSON.parse(localStorage.getItem('torrent'))) : t
if (torrent) this.addTorrent(t, JSON.parse(localStorage.getItem('lastFinished')))
}

async handleTorrent (torrent) {
Expand Down Expand Up @@ -176,12 +177,12 @@ export default class TorrentClient extends WebTorrent {
}

dispatchError (e) {
if (e instanceof ErrorEvent) return this.dispatchError(e.error)
if (e instanceof PromiseRejectionEvent) return this.dispatchError(e.reason)
if (typeof ErrorEvent !== 'undefined' && e instanceof ErrorEvent) return this.dispatchError(e.error)
if (typeof PromiseRejectionEvent !== 'undefined' && e instanceof PromiseRejectionEvent) return this.dispatchError(e.reason)
for (const exclude of TorrentClient.excludedErrorMessages) {
if (e.message?.startsWith(exclude)) return
}
this.dispatch('error', e)
this.dispatch('error', JSON.stringify(e))
}

async addTorrent (data, skipVerify = false) {
Expand Down Expand Up @@ -209,8 +210,6 @@ export default class TorrentClient extends WebTorrent {
switch (data.type) {
case 'current': {
if (data.data) {
console.log('adding torrent')
console.log(data.data)
const torrent = await this.get(data.data.infoHash)
const found = torrent?.files.find(file => file.path === data.data.path)
if (!found) return
Expand Down
20 changes: 14 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e09053b

Please sign in to comment.