pear-runtime-updater 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const ReadyResource = require('ready-resource')
|
|
|
9
9
|
const link = require('pear-link')
|
|
10
10
|
const hid = require('hypercore-id-encoding')
|
|
11
11
|
const { platform, arch } = require('which-runtime')
|
|
12
|
+
const isMobile = platform === 'ios' || platform === 'android'
|
|
12
13
|
const host = platform + '-' + arch
|
|
13
14
|
|
|
14
15
|
module.exports = class PearRuntime extends ReadyResource {
|
|
@@ -51,7 +52,7 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
async _open() {
|
|
54
|
-
if (this.updates
|
|
55
|
+
if (!this.updates) return
|
|
55
56
|
await this.drive.ready()
|
|
56
57
|
|
|
57
58
|
if (this.bundled) {
|
|
@@ -88,7 +89,9 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
88
89
|
this.applied = true
|
|
89
90
|
|
|
90
91
|
// mac only for now, linux similar, windows, more pain
|
|
91
|
-
|
|
92
|
+
const segments = [this.next, 'by-arch', host, 'app']
|
|
93
|
+
if (!isMobile) segments.push(this.name)
|
|
94
|
+
await fsx.swap(path.join(...segments), this.app)
|
|
92
95
|
await fs.promises.rm(this.next, { recursive: true, force: true })
|
|
93
96
|
}
|
|
94
97
|
|
|
@@ -97,7 +100,7 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
async _update() {
|
|
100
|
-
if (this.updating || this.updates
|
|
103
|
+
if (this.updating || !this.updates) return
|
|
101
104
|
this.updating = true
|
|
102
105
|
|
|
103
106
|
const length = this.drive.core.length
|
|
@@ -118,10 +121,11 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
118
121
|
const local = new Localdrive(next)
|
|
119
122
|
|
|
120
123
|
this.emit('updating')
|
|
121
|
-
const prefix =
|
|
124
|
+
const prefix = `/by-arch/${host}/app${isMobile ? '' : `/${this.name}`}`
|
|
122
125
|
for await (const data of co.mirror(local, { prefix })) {
|
|
123
126
|
this.emit('updating-delta', data)
|
|
124
127
|
}
|
|
128
|
+
if (isMobile) await local.put(`${prefix}/package.json`, manifest)
|
|
125
129
|
|
|
126
130
|
await co.close()
|
|
127
131
|
await local.close()
|