pear-runtime-updater 0.0.10 → 0.0.12

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.
Files changed (3) hide show
  1. package/README.md +6 -2
  2. package/index.js +17 -8
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -8,6 +8,10 @@ npm install pear-runtime-updater
8
8
 
9
9
  Listens for P2P over-the-air (OTA) updates for [Pear](https://docs.pears.com) apps. Replicates from a pear upgrade link and emits when a new version is available.
10
10
 
11
+ ## MVP - EXPERIMENTAL
12
+
13
+ This boilerplate is MVP and Experimental.
14
+
11
15
  ## Usage
12
16
 
13
17
  ```js
@@ -59,7 +63,7 @@ process.on('beforeExit', () => updater.close())
59
63
 
60
64
  #### `updater.on('updating')`
61
65
 
62
- Emitted when an update is in progress (download started).
66
+ Emitted when an update is in progress.
63
67
 
64
68
  #### `updater.on('updating-delta', data)`
65
69
 
@@ -79,7 +83,7 @@ Apply the update by swapping the current app with the received build through ato
79
83
 
80
84
  #### `await updater.close()`
81
85
 
82
- Closes the updater. Call when shutting down the app.
86
+ Shut it down. You should do this when closing your app for best performance.
83
87
 
84
88
  ## License
85
89
 
package/index.js CHANGED
@@ -8,7 +8,8 @@ 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')
11
+ const MSIXManager = require('msix-manager')
12
+ const { platform, arch, isWindows } = require('which-runtime')
12
13
  const isMobile = platform === 'ios' || platform === 'android'
13
14
  const host = platform + '-' + arch
14
15
 
@@ -31,17 +32,15 @@ module.exports = class PearRuntime extends ReadyResource {
31
32
  this.length = upgrade.length || 0
32
33
  this.fork = upgrade.fork || 0
33
34
  this.link = link.serialize({ drive: { fork: this.fork, length: this.length, key: this.key } })
34
- this.store = new Corestore(path.join(this.dir, 'pear-runtime/corestore'))
35
- this.drive = new Hyperdrive(this.store, this.key)
36
35
  } else {
37
36
  this.key = null
38
37
  this.length = null
39
38
  this.fork = null
40
39
  this.link = null
41
- this.store = null
42
- this.drive = null
43
40
  }
44
41
 
42
+ this.store = null
43
+ this.drive = null
45
44
  this.swarm = null
46
45
  this.next = null
47
46
  this.checkout = null
@@ -52,7 +51,11 @@ module.exports = class PearRuntime extends ReadyResource {
52
51
  }
53
52
 
54
53
  async _open() {
55
- if (!this.updates) return
54
+ if (!this.drive) return
55
+ if (this.store === null) {
56
+ this.store = new Corestore(path.join(this.dir, 'pear-runtime/corestore'))
57
+ }
58
+ if (this.drive === null) this.drive = new Hyperdrive(this.store, this.key)
56
59
  await this.drive.ready()
57
60
 
58
61
  if (this.bundled) {
@@ -90,8 +93,14 @@ module.exports = class PearRuntime extends ReadyResource {
90
93
 
91
94
  // mac only for now, linux similar, windows, more pain
92
95
  const segments = [this.next, 'by-arch', host, 'app']
93
- if (!isMobile) segments.push(this.name)
94
- await fsx.swap(path.join(...segments), this.app)
96
+ if (!isMobile && !isWindows) segments.push(this.name)
97
+ if (isWindows) {
98
+ const manager = new MSIXManager()
99
+ const msix = this.name.slice(0, -3) + 'msix'
100
+ await manager.addPackage(...segments, msix)
101
+ } else {
102
+ await fsx.swap(path.join(...segments), this.app)
103
+ }
95
104
  await fs.promises.rm(this.next, { recursive: true, force: true })
96
105
  }
97
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-runtime-updater",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
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"