Skip to content

Commit 6d70c8e

Browse files
lemarierrajivshah3lucasfernognothingismagickLaegel
authored
feat(updater): Alpha version (#643)
Co-authored-by: Rajiv Shah <rajivshah1@icloud.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: nothingismagick <denjell@mailscript.com> Co-authored-by: Laegel <valentin.chouaf@laposte.net>
1 parent 2ea56cf commit 6d70c8e

File tree

94 files changed

+7572
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+7572
-697
lines changed

.changes/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@
185185
},
186186
"tauri-updater": {
187187
"path": "./tauri-updater",
188-
"manager": "rust",
189-
"publish": false
188+
"manager": "rust"
190189
},
191190
"tauri": {
192191
"path": "./tauri",

.changes/updater-alpha.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri-updater": minor
3+
"tauri-cli": minor
4+
"tauri-bundler": minor
5+
"tauri": minor
6+
---
7+
8+
Alpha version of tauri-updater. Please refer to the `README` for more details.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: updater test artifacts
2+
on:
3+
pull_request:
4+
paths:
5+
- '.github/workflows/artifacts-updater.yml'
6+
- 'tauri/**'
7+
- 'tauri-updater/**'
8+
- 'cli/core/**'
9+
- 'cli/tauri-bundler/**'
10+
- 'examples/updater/**'
11+
12+
jobs:
13+
build-artifacs:
14+
runs-on: ${{ matrix.platform }}
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
platform: [ubuntu-latest, macos-latest, windows-latest]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: install stable
24+
uses: actions-rs/toolchain@v1
25+
with:
26+
toolchain: stable
27+
- name: install webkit2gtk (ubuntu only)
28+
if: matrix.platform == 'ubuntu-latest'
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y webkit2gtk-4.0
32+
- run: cargo install --path ./cli/core --force
33+
- name: install cli deps via yarn
34+
working-directory: ./cli/tauri.js
35+
run: yarn
36+
- name: build cli
37+
working-directory: ./cli/tauri.js
38+
run: yarn build
39+
- name: build sample artifacts (updater)
40+
working-directory: ./examples/updater
41+
run: |
42+
yarn install
43+
node ../../cli/tauri.js/bin/tauri build
44+
env:
45+
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
46+
- uses: actions/upload-artifact@v2
47+
if: matrix.platform == 'ubuntu-latest'
48+
with:
49+
name: linux-updater-artifacts
50+
path: ./target/release/bundle/appimage/updater-example_*.AppImage.*
51+
52+
- uses: actions/upload-artifact@v2
53+
if: matrix.platform == 'windows-latest'
54+
with:
55+
name: windows-updater-artifacts
56+
path: ./target/release/bundle/msi/*
57+
58+
- uses: actions/upload-artifact@v2
59+
if: matrix.platform == 'macos-latest'
60+
with:
61+
name: macos-updater-artifacts
62+
path: ./target/release/bundle/macos/updater-example_*.app.tar.*

.github/workflows/test-bundler.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ jobs:
2323
uses: actions-rs/toolchain@v1
2424
with:
2525
toolchain: stable
26+
- name: install webkit2gtk (ubuntu only)
27+
if: matrix.platform == 'ubuntu-latest'
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install -y webkit2gtk-4.0
2631
- name: test
2732
run: |
2833
cd ./cli/tauri-bundler
@@ -34,6 +39,11 @@ jobs:
3439
steps:
3540
- uses: actions/checkout@v2
3641
- run: rustup component add clippy
42+
- name: install webkit2gtk (ubuntu only)
43+
if: matrix.platform == 'ubuntu-latest'
44+
run: |
45+
sudo apt-get update
46+
sudo apt-get install -y webkit2gtk-4.0
3747
- name: clippy check
3848
uses: actions-rs/clippy-check@v1
3949
with:

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ members = [
1313
"examples/api/src-tauri",
1414
"examples/helloworld/src-tauri",
1515
"examples/multiwindow/src-tauri",
16+
# used to build updater artifacts
17+
"examples/updater/src-tauri",
1618
]
1719

1820
# default to small, optimized workspace release binaries

api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"./cli": "./dist/cli.js",
99
"./dialog": "./dist/dialog.js",
1010
"./event": "./dist/event.js",
11+
"./updater": "./dist/updater.js",
1112
"./fs": "./dist/fs.js",
1213
"./path": "./dist/path.js",
1314
"./http": "./dist/http.js",

api/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default [
1414
path: './src/path.ts',
1515
dialog: './src/dialog.ts',
1616
event: './src/event.ts',
17+
updater: './src/updater.ts',
1718
http: './src/http.ts',
1819
index: './src/index.ts',
1920
shell: './src/shell.ts',

api/src/bundle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'regenerator-runtime/runtime'
22
import * as cli from './cli'
33
import * as dialog from './dialog'
44
import * as event from './event'
5+
import * as updater from './updater'
56
import * as fs from './fs'
67
import * as path from './path'
78
import * as http from './http'
@@ -15,6 +16,7 @@ export {
1516
cli,
1617
dialog,
1718
event,
19+
updater,
1820
fs,
1921
path,
2022
http,

api/src/updater.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { once, listen, emit, UnlistenFn } from './helpers/event'
2+
3+
export type UpdateStatus = 'PENDING' | 'ERROR' | 'DONE' | 'UPTODATE'
4+
5+
export interface UpdateStatusResult {
6+
error?: string
7+
status: UpdateStatus
8+
}
9+
10+
export interface UpdateManifest {
11+
version: string
12+
date: string
13+
body: string
14+
}
15+
16+
export interface UpdateResult {
17+
manifest?: UpdateManifest
18+
shouldUpdate: boolean
19+
}
20+
21+
export async function installUpdate(): Promise<void> {
22+
let unlistenerFn: UnlistenFn | undefined
23+
24+
function cleanListener(): void {
25+
if (unlistenerFn) {
26+
unlistenerFn()
27+
}
28+
unlistenerFn = undefined
29+
}
30+
31+
return new Promise((resolve, reject) => {
32+
function onStatusChange(statusResult: UpdateStatusResult): void {
33+
if (statusResult.error) {
34+
cleanListener()
35+
return reject(statusResult.error)
36+
}
37+
38+
// install complete
39+
if (statusResult.status === 'DONE') {
40+
cleanListener()
41+
return resolve()
42+
}
43+
}
44+
45+
// listen status change
46+
listen('tauri://update-status', (data: { payload: any }) => {
47+
onStatusChange(data?.payload as UpdateStatusResult)
48+
})
49+
.then((fn) => {
50+
unlistenerFn = fn
51+
})
52+
.catch((e) => {
53+
cleanListener()
54+
// dispatch the error to our checkUpdate
55+
throw e
56+
})
57+
58+
// start the process we dont require much security as it's
59+
// handled by rust
60+
emit('tauri://update-install').catch((e) => {
61+
cleanListener()
62+
// dispatch the error to our checkUpdate
63+
throw e
64+
})
65+
})
66+
}
67+
68+
export async function checkUpdate(): Promise<UpdateResult> {
69+
let unlistenerFn: UnlistenFn | undefined
70+
71+
function cleanListener(): void {
72+
if (unlistenerFn) {
73+
unlistenerFn()
74+
}
75+
unlistenerFn = undefined
76+
}
77+
78+
return new Promise((resolve, reject) => {
79+
function onUpdateAvailable(manifest: UpdateManifest): void {
80+
cleanListener()
81+
return resolve({
82+
manifest,
83+
shouldUpdate: true
84+
})
85+
}
86+
87+
function onStatusChange(statusResult: UpdateStatusResult): void {
88+
if (statusResult.error) {
89+
cleanListener()
90+
return reject(statusResult.error)
91+
}
92+
93+
if (statusResult.status === 'UPTODATE') {
94+
cleanListener()
95+
return resolve({
96+
shouldUpdate: false
97+
})
98+
}
99+
}
100+
101+
// wait to receive the latest update
102+
once('tauri://update-available', (data: { payload: any }) => {
103+
onUpdateAvailable(data?.payload as UpdateManifest)
104+
}).catch((e) => {
105+
cleanListener()
106+
// dispatch the error to our checkUpdate
107+
throw e
108+
})
109+
110+
// listen status change
111+
listen('tauri://update-status', (data: { payload: any }) => {
112+
onStatusChange(data?.payload as UpdateStatusResult)
113+
})
114+
.then((fn) => {
115+
unlistenerFn = fn
116+
})
117+
.catch((e) => {
118+
cleanListener()
119+
// dispatch the error to our checkUpdate
120+
throw e
121+
})
122+
123+
// start the process
124+
emit('tauri://update').catch((e) => {
125+
cleanListener()
126+
// dispatch the error to our checkUpdate
127+
throw e
128+
})
129+
})
130+
}

0 commit comments

Comments
 (0)