Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Setup auto updates

Vishnu Mohandasbd2e6a626c92
diff --git a/.github/workflows/ensu-release.yml b/.github/workflows/ensu-release.yml
index 5a2079a5cb..e1404e67c9 100644
--- a/.github/workflows/ensu-release.yml
+++ b/.github/workflows/ensu-release.yml
@@ -221,7 +221,7 @@ jobs:
includeDebug: false
includeRelease: true
includeUpdaterJson: false
- args: ${{ format('--target {0} --bundles {1}', matrix.platform.rust-target, matrix.platform.bundle-targets) }}
+ args: ${{ format('--target {0} --bundles {1} --features updater', matrix.platform.rust-target, matrix.platform.bundle-targets) }}
build-android:
runs-on: ubuntu-22.04
diff --git a/rust/apps/ensu/src-tauri/Cargo.lock b/rust/apps/ensu/src-tauri/Cargo.lock
index 537843241a..a8e2f196fb 100644
--- a/rust/apps/ensu/src-tauri/Cargo.lock
+++ b/rust/apps/ensu/src-tauri/Cargo.lock
@@ -432,6 +432,9 @@ name = "bytes"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
+dependencies = [
+ "serde",
+]
[[package]]
name = "cairo-rs"
@@ -1035,7 +1038,7 @@ dependencies = [
"rustc_version",
"toml 0.8.23",
"vswhom",
- "winreg",
+ "winreg 0.52.0",
]
[[package]]
@@ -1079,7 +1082,7 @@ dependencies = [
"ensu-db",
"ente-core",
"hkdf",
- "reqwest",
+ "reqwest 0.12.28",
"serde",
"serde_json",
"sha2",
@@ -1117,7 +1120,7 @@ dependencies = [
"hex",
"md-5",
"rand_core 0.6.4",
- "reqwest",
+ "reqwest 0.12.28",
"salsa20",
"serde",
"serde_json",
@@ -1742,6 +1745,25 @@ dependencies = [
"syn 1.0.109",
]
+[[package]]
+name = "h2"
+version = "0.3.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d"
+dependencies = [
+ "bytes",
+ "fnv",
+ "futures-core",
+ "futures-sink",
+ "futures-util",
+ "http 0.2.12",
+ "indexmap 2.13.0",
+ "slab",
+ "tokio",
+ "tokio-util",
+ "tracing",
+]
+
[[package]]
name = "h2"
version = "0.4.13"
@@ -1889,6 +1911,17 @@ dependencies = [
"itoa 1.0.18",
]
+[[package]]
+name = "http-body"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
+dependencies = [
+ "bytes",
+ "http 0.2.12",
+ "pin-project-lite",
+]
+
[[package]]
name = "http-body"
version = "1.0.1"
@@ -1908,7 +1941,7 @@ dependencies = [
"bytes",
"futures-core",
"http 1.4.0",
- "http-body",
+ "http-body 1.0.1",
"pin-project-lite",
]
@@ -1924,6 +1957,36 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
+[[package]]
+name = "httpdate"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
+
+[[package]]
+name = "hyper"
+version = "0.14.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7"
+dependencies = [
+ "bytes",
+ "futures-channel",
+ "futures-core",
+ "futures-util",
+ "h2 0.3.27",
+ "http 0.2.12",
+ "http-body 0.4.6",
+ "httparse",
+ "httpdate",
+ "itoa 1.0.18",
+ "pin-project-lite",
+ "socket2 0.5.10",
+ "tokio",
+ "tower-service",
+ "tracing",
+ "want",
+]
+
[[package]]
name = "hyper"
version = "1.8.1"
@@ -1934,9 +1997,9 @@ dependencies = [
"bytes",
"futures-channel",
"futures-core",
- "h2",
+ "h2 0.4.13",
"http 1.4.0",
- "http-body",
+ "http-body 1.0.1",
"httparse",
"itoa 1.0.18",
"pin-project-lite",
@@ -1953,7 +2016,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58"
dependencies = [
"http 1.4.0",
- "hyper",
+ "hyper 1.8.1",
"hyper-util",
"rustls",
"rustls-native-certs",
@@ -1963,6 +2026,19 @@ dependencies = [
"tower-service",
]
+[[package]]
+name = "hyper-tls"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
+dependencies = [
+ "bytes",
+ "hyper 0.14.32",
+ "native-tls",
+ "tokio",
+ "tokio-native-tls",
+]
+
[[package]]
name = "hyper-util"
version = "0.1.20"
@@ -1974,14 +2050,14 @@ dependencies = [
"futures-channel",
"futures-util",
"http 1.4.0",
- "http-body",
- "hyper",
+ "http-body 1.0.1",
+ "hyper 1.8.1",
"ipnet",
"libc",
"percent-encoding",
"pin-project-lite",
- "socket2",
- "system-configuration",
+ "socket2 0.6.3",
+ "system-configuration 0.7.0",
"tokio",
"tower-service",
"tracing",
@@ -2630,6 +2706,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+[[package]]
+name = "minisign-verify"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22f9645cb765ea72b8111f36c522475d2daa0d22c957a9826437e97534bc4e9e"
+
[[package]]
name = "miniz_oxide"
version = "0.8.9"
@@ -2651,6 +2733,23 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "native-tls"
+version = "0.2.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"
+dependencies = [
+ "libc",
+ "log",
+ "openssl",
+ "openssl-probe",
+ "openssl-sys",
+ "schannel",
+ "security-framework 3.7.0",
+ "security-framework-sys",
+ "tempfile",
+]
+
[[package]]
name = "ndk"
version = "0.6.0"
@@ -2884,12 +2983,50 @@ dependencies = [
"windows-sys 0.42.0",
]
+[[package]]
+name = "openssl"
+version = "0.10.76"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "951c002c75e16ea2c65b8c7e4d3d51d5530d8dfa7d060b4776828c88cfb18ecf"
+dependencies = [
+ "bitflags 2.11.0",
+ "cfg-if",
+ "foreign-types",
+ "libc",
+ "once_cell",
+ "openssl-macros",
+ "openssl-sys",
+]
+
+[[package]]
+name = "openssl-macros"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
[[package]]
name = "openssl-probe"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
+[[package]]
+name = "openssl-sys"
+version = "0.9.112"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb"
+dependencies = [
+ "cc",
+ "libc",
+ "pkg-config",
+ "vcpkg",
+]
+
[[package]]
name = "ordered-stream"
version = "0.2.0"
@@ -3317,7 +3454,7 @@ dependencies = [
"quinn-udp",
"rustc-hash",
"rustls",
- "socket2",
+ "socket2 0.6.3",
"thiserror 2.0.18",
"tokio",
"tracing",
@@ -3354,7 +3491,7 @@ dependencies = [
"cfg_aliases",
"libc",
"once_cell",
- "socket2",
+ "socket2 0.6.3",
"tracing",
"windows-sys 0.60.2",
]
@@ -3574,6 +3711,48 @@ version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
+[[package]]
+name = "reqwest"
+version = "0.11.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
+dependencies = [
+ "base64 0.21.7",
+ "bytes",
+ "encoding_rs",
+ "futures-core",
+ "futures-util",
+ "h2 0.3.27",
+ "http 0.2.12",
+ "http-body 0.4.6",
+ "hyper 0.14.32",
+ "hyper-tls",
+ "ipnet",
+ "js-sys",
+ "log",
+ "mime",
+ "native-tls",
+ "once_cell",
+ "percent-encoding",
+ "pin-project-lite",
+ "rustls-pemfile",
+ "serde",
+ "serde_json",
+ "serde_urlencoded",
+ "sync_wrapper 0.1.2",
+ "system-configuration 0.5.1",
+ "tokio",
+ "tokio-native-tls",
+ "tokio-util",
+ "tower-service",
+ "url",
+ "wasm-bindgen",
+ "wasm-bindgen-futures",
+ "wasm-streams",
+ "web-sys",
+ "winreg 0.50.0",
+]
+
[[package]]
name = "reqwest"
version = "0.12.28"
@@ -3586,11 +3765,11 @@ dependencies = [
"futures-channel",
"futures-core",
"futures-util",
- "h2",
+ "h2 0.4.13",
"http 1.4.0",
- "http-body",
+ "http-body 1.0.1",
"http-body-util",
- "hyper",
+ "hyper 1.8.1",
"hyper-rustls",
"hyper-util",
"js-sys",
@@ -3605,7 +3784,7 @@ dependencies = [
"serde",
"serde_json",
"serde_urlencoded",
- "sync_wrapper",
+ "sync_wrapper 1.0.2",
"tokio",
"tokio-rustls",
"tower",
@@ -3734,6 +3913,15 @@ dependencies = [
"security-framework 3.7.0",
]
+[[package]]
+name = "rustls-pemfile"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
+dependencies = [
+ "base64 0.21.7",
+]
+
[[package]]
name = "rustls-pki-types"
version = "1.14.0"
@@ -4137,6 +4325,16 @@ version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
+[[package]]
+name = "socket2"
+version = "0.5.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678"
+dependencies = [
+ "libc",
+ "windows-sys 0.52.0",
+]
+
[[package]]
name = "socket2"
version = "0.6.3"
@@ -4280,6 +4478,12 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "sync_wrapper"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
+
[[package]]
name = "sync_wrapper"
version = "1.0.2"
@@ -4300,6 +4504,17 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "system-configuration"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
+dependencies = [
+ "bitflags 1.3.2",
+ "core-foundation 0.9.4",
+ "system-configuration-sys 0.5.0",
+]
+
[[package]]
name = "system-configuration"
version = "0.7.0"
@@ -4308,7 +4523,17 @@ checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
dependencies = [
"bitflags 2.11.0",
"core-foundation 0.9.4",
- "system-configuration-sys",
+ "system-configuration-sys 0.6.0",
+]
+
+[[package]]
+name = "system-configuration-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
]
[[package]]
@@ -4429,6 +4654,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ae1f57c291a6ab8e1d2e6b8ad0a35ff769c9925deb8a89de85425ff08762d0c"
dependencies = [
"anyhow",
+ "base64 0.22.1",
+ "bytes",
"cocoa",
"dirs-next",
"dunce",
@@ -4443,7 +4670,10 @@ dependencies = [
"heck 0.5.0",
"http 0.2.12",
"ignore",
+ "indexmap 1.9.3",
+ "infer",
"log",
+ "minisign-verify",
"objc",
"once_cell",
"open",
@@ -4452,6 +4682,7 @@ dependencies = [
"rand 0.8.5",
"raw-window-handle",
"regex",
+ "reqwest 0.11.27",
"rfd",
"semver",
"serde",
@@ -4466,12 +4697,14 @@ dependencies = [
"tauri-utils",
"tempfile",
"thiserror 1.0.69",
+ "time",
"tokio",
"url",
"uuid",
"webkit2gtk",
"webview2-com",
"windows 0.39.0",
+ "zip",
]
[[package]]
@@ -4759,10 +4992,20 @@ dependencies = [
"libc",
"mio",
"pin-project-lite",
- "socket2",
+ "socket2 0.6.3",
"windows-sys 0.61.2",
]
+[[package]]
+name = "tokio-native-tls"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
+dependencies = [
+ "native-tls",
+ "tokio",
+]
+
[[package]]
name = "tokio-rustls"
version = "0.26.4"
@@ -4900,7 +5143,7 @@ dependencies = [
"futures-core",
"futures-util",
"pin-project-lite",
- "sync_wrapper",
+ "sync_wrapper 1.0.2",
"tokio",
"tower-layer",
"tower-service",
@@ -4916,7 +5159,7 @@ dependencies = [
"bytes",
"futures-util",
"http 1.4.0",
- "http-body",
+ "http-body 1.0.1",
"iri-string",
"pin-project-lite",
"tower",
@@ -5289,6 +5532,19 @@ dependencies = [
"wasmparser",
]
+[[package]]
+name = "wasm-streams"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65"
+dependencies = [
+ "futures-util",
+ "js-sys",
+ "wasm-bindgen",
+ "wasm-bindgen-futures",
+ "web-sys",
+]
+
[[package]]
name = "wasmparser"
version = "0.244.0"
@@ -5959,6 +6215,16 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "winreg"
+version = "0.50.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
+dependencies = [
+ "cfg-if",
+ "windows-sys 0.48.0",
+]
+
[[package]]
name = "winreg"
version = "0.52.0"
@@ -6340,6 +6606,17 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "zip"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261"
+dependencies = [
+ "byteorder",
+ "crc32fast",
+ "crossbeam-utils",
+]
+
[[package]]
name = "zmij"
version = "1.0.21"
diff --git a/rust/apps/ensu/src-tauri/Cargo.toml b/rust/apps/ensu/src-tauri/Cargo.toml
index 5dbd13c939..72f4ec3933 100644
--- a/rust/apps/ensu/src-tauri/Cargo.toml
+++ b/rust/apps/ensu/src-tauri/Cargo.toml
@@ -20,6 +20,7 @@ keyring = { version = "3", default-features = false, features = ["apple-native",
[features]
custom-protocol = ["tauri/custom-protocol"]
+updater = ["tauri/updater"]
[profile.release]
opt-level = 3
diff --git a/rust/apps/ensu/src-tauri/tauri.conf.json b/rust/apps/ensu/src-tauri/tauri.conf.json
index ccb4267e0b..a98ae987d5 100644
--- a/rust/apps/ensu/src-tauri/tauri.conf.json
+++ b/rust/apps/ensu/src-tauri/tauri.conf.json
@@ -56,6 +56,11 @@
},
"security": {
"csp": null
+ },
+ "updater": {
+ "active": false,
+ "dialog": false,
+ "endpoints": ["https://ente.com/release-info/ensu-desktop.json"]
}
}
}
diff --git a/web/apps/ensu/src/pages/_app.tsx b/web/apps/ensu/src/pages/_app.tsx
index 12f8bdbff9..e6ce10d914 100644
--- a/web/apps/ensu/src/pages/_app.tsx
+++ b/web/apps/ensu/src/pages/_app.tsx
@@ -20,6 +20,7 @@ import { logStartupBanner } from "ente-base/log-web";
import "katex/dist/katex.min.css";
import type { AppProps } from "next/app";
import React, { useCallback, useEffect, useMemo } from "react";
+import { setupAutoAppUpdates } from "services/app-update";
import { ensuLogout } from "services/logout";
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
@@ -33,6 +34,8 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
logStartupBanner(savedLocalUser()?.id);
}, []);
+ useEffect(() => setupAutoAppUpdates(), []);
+
useEffect(() => {
if (typeof window === "undefined") return;
const isTauri = "__TAURI__" in window || "__TAURI_IPC__" in window;
diff --git a/web/apps/ensu/src/services/app-update.ts b/web/apps/ensu/src/services/app-update.ts
new file mode 100644
index 0000000000..bc0b6c47da
--- /dev/null
+++ b/web/apps/ensu/src/services/app-update.ts
@@ -0,0 +1,64 @@
+import log from "ente-base/log";
+import { isTauriAppRuntime } from "services/secure-storage";
+
+const oneDay = 24 * 60 * 60 * 1000;
+
+let intervalId: number | undefined;
+let inFlightUpdateCheck: Promise<void> | undefined;
+
+const checkForAppUpdates = async () => {
+ if (!isTauriAppRuntime()) return;
+ if (inFlightUpdateCheck) return inFlightUpdateCheck;
+
+ const run = async () => {
+ try {
+ const [{ checkUpdate, installUpdate }, { relaunch }] =
+ await Promise.all([
+ import("@tauri-apps/api/updater"),
+ import("@tauri-apps/api/process"),
+ ]);
+
+ const update = await checkUpdate();
+ if (!update.shouldUpdate) {
+ log.debug(() => "Ensu is already on the latest version");
+ return;
+ }
+
+ const version = update.manifest?.version ?? "unknown";
+ log.info(`Installing Ensu update ${version}`);
+ await installUpdate();
+ log.info(`Installed Ensu update ${version}, relaunching`);
+ await relaunch();
+ } catch (e) {
+ log.error("Failed to auto-update Ensu", e);
+ }
+ };
+
+ inFlightUpdateCheck = run().finally(() => {
+ inFlightUpdateCheck = undefined;
+ });
+
+ return inFlightUpdateCheck;
+};
+
+export const setupAutoAppUpdates = () => {
+ if (
+ !isTauriAppRuntime() ||
+ process.env.NODE_ENV !== "production" ||
+ intervalId
+ ) {
+ return () => {};
+ }
+
+ void checkForAppUpdates();
+ intervalId = window.setInterval(() => {
+ void checkForAppUpdates();
+ }, oneDay);
+
+ return () => {
+ if (intervalId) {
+ window.clearInterval(intervalId);
+ intervalId = undefined;
+ }
+ };
+};
diff --git a/web/apps/ensu/src/types/tauri.d.ts b/web/apps/ensu/src/types/tauri.d.ts
index 343b760621..50a5816b45 100644
--- a/web/apps/ensu/src/types/tauri.d.ts
+++ b/web/apps/ensu/src/types/tauri.d.ts
@@ -28,6 +28,26 @@ declare module "@tauri-apps/api/dialog" {
): Promise<string | null>;
}
+declare module "@tauri-apps/api/process" {
+ export function relaunch(): Promise<void>;
+}
+
declare module "@tauri-apps/api/shell" {
export function open(path: string): Promise<void>;
}
+
+declare module "@tauri-apps/api/updater" {
+ export interface UpdateManifest {
+ version: string;
+ date: string;
+ body: string;
+ }
+
+ export interface UpdateResult {
+ manifest?: UpdateManifest;
+ shouldUpdate: boolean;
+ }
+
+ export function checkUpdate(): Promise<UpdateResult>;
+ export function installUpdate(): Promise<void>;
+}