pear-runtime-updater 0.0.14 → 1.0.1
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 +18 -13
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -8,8 +8,7 @@ const fsx = require('fs-native-extensions')
|
|
|
8
8
|
const ReadyResource = require('ready-resource')
|
|
9
9
|
const link = require('pear-link')
|
|
10
10
|
const hid = require('hypercore-id-encoding')
|
|
11
|
-
const { platform, arch } = require('which-runtime')
|
|
12
|
-
const isMobile = platform === 'ios' || platform === 'android'
|
|
11
|
+
const { platform, arch, isWindows } = require('which-runtime')
|
|
13
12
|
const host = platform + '-' + arch
|
|
14
13
|
|
|
15
14
|
module.exports = class PearRuntime extends ReadyResource {
|
|
@@ -22,7 +21,8 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
22
21
|
this.dir = opts.dir
|
|
23
22
|
this.version = opts.version || 0
|
|
24
23
|
this.app = opts.app
|
|
25
|
-
this.name = this.app && path.basename(this.app)
|
|
24
|
+
this.name = opts.name ?? (this.app && path.basename(this.app))
|
|
25
|
+
if (isWindows) this.name = path.basename(this.name, path.extname(this.name)) + '.msix'
|
|
26
26
|
this.bundled = opts.bundled || !!this.app
|
|
27
27
|
|
|
28
28
|
if (this.updates) {
|
|
@@ -78,20 +78,26 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async _close() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
await this.
|
|
84
|
-
await this.
|
|
81
|
+
if (!this.updates) return
|
|
82
|
+
|
|
83
|
+
await this.drive.close()
|
|
84
|
+
if (this.checkout !== null) await this.checkout.close()
|
|
85
|
+
await this.store.close()
|
|
86
|
+
await this.swarm.destroy()
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
async applyUpdate() {
|
|
88
90
|
if (!this.updated || this.applied || !this.bundled) return
|
|
89
91
|
this.applied = true
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
const nextApp = path.join(this.next, 'by-arch', host, 'app', this.name)
|
|
94
|
+
if (isWindows) {
|
|
95
|
+
const MSIXManager = require('msix-manager') // require must be here for platform compatibility
|
|
96
|
+
const manager = new MSIXManager()
|
|
97
|
+
await manager.addPackage(nextApp)
|
|
98
|
+
} else {
|
|
99
|
+
await fsx.swap(nextApp, this.app)
|
|
100
|
+
}
|
|
95
101
|
await fs.promises.rm(this.next, { recursive: true, force: true })
|
|
96
102
|
}
|
|
97
103
|
|
|
@@ -121,11 +127,10 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
121
127
|
const local = new Localdrive(next)
|
|
122
128
|
|
|
123
129
|
this.emit('updating')
|
|
124
|
-
const prefix = `/by-arch/${host}/app
|
|
130
|
+
const prefix = `/by-arch/${host}/app/${this.name}`
|
|
125
131
|
for await (const data of co.mirror(local, { prefix })) {
|
|
126
132
|
this.emit('updating-delta', data)
|
|
127
133
|
}
|
|
128
|
-
if (isMobile) await local.put(`${prefix}/package.json`, manifest)
|
|
129
134
|
|
|
130
135
|
await co.close()
|
|
131
136
|
await local.close()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-runtime-updater",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Listens for OTA Pear App updates",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Holepunch Inc",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"hyperdrive": "^13.2.1",
|
|
42
42
|
"hyperswarm": "^4.16.0",
|
|
43
43
|
"localdrive": "^2.2.0",
|
|
44
|
+
"msix-manager": "^0.1.1",
|
|
44
45
|
"pear-link": "^4.2.1",
|
|
45
46
|
"ready-resource": "^1.2.0",
|
|
46
47
|
"which-runtime": "^1.3.2"
|