Skip to content

Commit 1a154d0

Browse files
authored
Merge pull request #14 from murdercode/fix-updated
feat: implement UpdateManagerV2 for Tauri v2 with automatic update ch…
2 parents 7d9f155 + 6ebd028 commit 1a154d0

File tree

15 files changed

+3714
-77
lines changed

15 files changed

+3714
-77
lines changed

UPDATER_SETUP.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Setup Aggiornamenti Sicuri per macOS - VERSIONE CORRETTA
2+
3+
## ⚠️ IMPORTANTE: Sistema Ibrido Implementato
4+
5+
Questo progetto usa un **approccio ibrido** per gestire gli aggiornamenti:
6+
7+
1. **Controllo Versione**: Usa GitHub API per controllare se c'è una nuova versione
8+
2. **Download/Install**: Usa l'API ufficiale Tauri quando possibile
9+
3. **Fallback**: Se l'API Tauri fallisce, guida l'utente al download manuale
10+
11+
### Perché questo approccio?
12+
13+
L'API GitHub restituisce un formato JSON diverso da quello richiesto da Tauri v2:
14+
15+
**GitHub API**`{"tag_name": "v0.2.2", "assets": [...], ...}`
16+
**Tauri richiede**`{"version": "0.2.2", "platforms": {"darwin-x86_64": {...}}, ...}`
17+
18+
Il nostro UpdateManager gestisce questa conversione automaticamente.
19+
20+
## 🔧 Configurazione Attuale
21+
22+
Il sistema è già configurato e funzionante:
23+
24+
**tauri.conf.json**: Configurato per usare GitHub API
25+
**UpdateManager**: Gestisce conversione formato + fallback
26+
**UI**: Integrata con progress bar e notifiche
27+
**Test Mode**: Disponibile per sviluppo
28+
29+
## 🧪 Test Immediato
30+
31+
Puoi testare subito il sistema:
32+
33+
```javascript
34+
// Apri console browser e prova:
35+
36+
// Test simulato (sempre disponibile)
37+
window.updateManagerV2Debug.testUpdate()
38+
39+
// Test reale (controlla GitHub per aggiornamenti veri)
40+
window.updateManagerV2Debug.checkRealUpdate()
41+
42+
// Verifica stato
43+
window.updateManagerV2Debug.getStatus()
44+
```
45+
46+
## � Cosa Succede Durante un Aggiornamento
47+
48+
### 1. **Controllo Automatico**
49+
- ✅ Ogni ora (se abilitato)
50+
- ✅ All'avvio dell'app (dopo 30 secondi)
51+
- ✅ Manuale con pulsante "Check for Updates"
52+
53+
### 2. **Processo di Verifica**
54+
1. Controlla GitHub API per l'ultima release
55+
2. Confronta con versione locale
56+
3. Se disponibile, prova API Tauri per download automatico
57+
4. Se API Tauri fallisce, offre download manuale
58+
59+
### 3. **Download e Installazione**
60+
- **Automatico**: Se l'API Tauri funziona
61+
- **Manuale**: Se necessario, apre pagina download
62+
- **Progress**: Barra di progresso in tempo reale
63+
- **Riavvio**: Automatico dopo installazione
64+
65+
## 🔐 Setup Chiavi di Firma (Opzionale)
66+
67+
Per aggiornamenti completamente automatici, genera le chiavi:
68+
69+
```bash
70+
npm run tauri signer generate -- -w ~/.tauri/presto.key
71+
```
72+
73+
Poi aggiorna la `pubkey` in `tauri.conf.json` con il contenuto di `~/.tauri/presto.key.pub`.
74+
75+
**NOTA**: Anche senza chiavi, il sistema funziona con download manuale.
76+
77+
## 🔍 Verifica Sistema
78+
79+
```bash
80+
# Verifica configurazione
81+
npm run dev
82+
83+
# In console browser:
84+
window.updateManagerV2Debug.getStatus()
85+
```
86+
87+
**Output atteso**:
88+
```
89+
{
90+
updateAvailable: false,
91+
isChecking: false,
92+
developmentMode: true, // true in dev, false in prod
93+
version: "v2-corrected" // conferma versione corretta
94+
}
95+
```
96+
97+
## 🚀 Deploy
98+
99+
1. **Build**: `npm run build`
100+
2. **Test**: Installa l'app e prova il controllo aggiornamenti
101+
3. **Release**: Pubblica su GitHub Releases (con file .app.tar.gz)
102+
103+
## 📁 File Necessari per Release
104+
105+
Quando crei una release su GitHub, assicurati di includere:
106+
107+
- `presto.app.tar.gz` (generato da `npm run build`)
108+
- `presto.app.tar.gz.sig` (se hai le chiavi di firma)
109+
110+
Il sistema li troverà automaticamente.
111+
112+
## 🔧 Risoluzione Problemi
113+
114+
### "Aggiornamento non disponibile"
115+
- ✅ Normale se sei all'ultima versione
116+
- ✅ Usa `testUpdate()` per simulare aggiornamento
117+
118+
### "Download manuale richiesto"
119+
- ✅ Normale se non hai configurato le chiavi di firma
120+
- ✅ Il sistema aprirà automaticamente la pagina di download
121+
122+
### "Errore di rete"
123+
- ✅ Verifica connessione Internet
124+
- ✅ Controlla se GitHub è accessibile
125+
126+
## 🎯 Stato Attuale: PRONTO
127+
128+
Il sistema è **completamente funzionante** e pronto per l'uso:
129+
130+
- ✅ Controllo automatico abilitato
131+
- ✅ UI integrata e funzionante
132+
- ✅ Fallback per download manuale
133+
- ✅ Modalità test per sviluppo
134+
- ✅ Compatibile con macOS
135+
136+
**Non serve configurare nulla di più** - funziona subito!

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"@tauri-apps/api": "^2.5.0",
2020
"@tauri-apps/plugin-dialog": "^2.2.2",
2121
"@tauri-apps/plugin-notification": "^2",
22+
"@tauri-apps/plugin-opener": "^2",
23+
"@tauri-apps/plugin-process": "^2",
2224
"@tauri-apps/plugin-updater": "^2.7.1"
2325
}
2426
}

src-tauri/Cargo.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ tauri-plugin-dialog = { version = "2", default-features = false }
3838
tauri-plugin-notification = { version = "2", default-features = false }
3939
tauri-plugin-autostart = { version = "2", default-features = false }
4040
tauri-plugin-updater = { version = "2", default-features = false }
41+
tauri-plugin-process = { version = "2", default-features = false }
4142
tauri-plugin-aptabase = "1.0.0"
4243
serde = { version = "1", features = ["derive"], default-features = false }
4344
serde_json = { version = "1", default-features = false }

src-tauri/capabilities/default.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
"core:default",
1010
"core:path:default",
1111
"core:event:default",
12+
"core:app:default",
13+
"core:app:allow-version",
14+
"core:webview:default",
15+
"core:webview:allow-internal-toggle-devtools",
1216
"opener:default",
17+
"opener:allow-open-url",
1318
"notification:default",
1419
"notification:allow-is-permission-granted",
1520
"notification:allow-request-permission",
@@ -27,12 +32,6 @@
2732
"autostart:allow-is-enabled",
2833
"updater:default",
2934
"updater:allow-check",
30-
"updater:allow-download-and-install",
31-
"core:app:default",
32-
"core:app:allow-version",
33-
"opener:default",
34-
"opener:allow-open-url",
35-
"core:webview:default",
36-
"core:webview:allow-internal-toggle-devtools"
35+
"updater:allow-download-and-install"
3736
]
3837
}

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ pub fn run() {
760760
None,
761761
))
762762
.plugin(tauri_plugin_updater::Builder::new().build())
763+
.plugin(tauri_plugin_process::init())
763764
.plugin(tauri_plugin_aptabase::Builder::new("A-EU-9457123106").build())
764765
.invoke_handler(tauri::generate_handler![
765766
greet,

src-tauri/tauri.conf.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
}
2525
},
2626
"bundle": {
27+
"createUpdaterArtifacts": true,
2728
"targets": [
2829
"dmg",
2930
"app"
@@ -54,11 +55,11 @@
5455
},
5556
"plugins": {
5657
"updater": {
57-
"active": true,
5858
"endpoints": [
5959
"https://api.github.com/repos/murdercode/presto/releases/latest"
6060
],
61-
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEIwQTUwNDBBQkRENTBDQjgKUldT\nNEROVzlDZ1Nsc0Q4eExoSG5jbjE1N1ppLzZRYUFvUUNqR1VYQmJFaEpvcFpjV3c4VDljSHoK"
61+
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEIwQTUwNDBBQkRENTBDQjgKUldT\nNEROVzlDZ1Nsc0Q4eExoSG5jbjE1N1ppLzZRYUFvUUNqR1VYQmJFaEpvcFpjV3c4VDljSHoK",
62+
"dangerousInsecureTransportProtocol": false
6263
}
6364
}
6465
}

src/index.html

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<link rel="stylesheet" href="styles/main.css" />
1111
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1212
<title>Presto</title>
13+
<script src="/managers/update-manager-global.js" defer></script>
1314
<script type="module" src="/main.js" defer></script>
1415
</head>
1516

@@ -746,55 +747,6 @@ <h3>Update Settings</h3>
746747
</div>
747748
</div>
748749

749-
<div class="settings-section">
750-
<h3>Update Actions</h3>
751-
752-
<div class="update-actions">
753-
<button class="btn btn-secondary" id="view-changelog-btn">
754-
<i class="ri-file-text-line"></i>
755-
View Changelog
756-
</button>
757-
</div>
758-
759-
<div class="update-progress" id="update-progress" style="display: none;">
760-
<div class="progress-info">
761-
<h4 id="progress-title">Checking for updates...</h4>
762-
<p id="progress-description">Please wait while we check for the latest version.</p>
763-
</div>
764-
<div class="progress-bar">
765-
<div class="progress-fill" id="progress-fill" style="width: 0%"></div>
766-
<span class="progress-text" id="progress-text">0%</span>
767-
</div>
768-
</div>
769-
770-
<div class="update-info" id="update-info" style="display: none;">
771-
<div class="update-details">
772-
<h4>Update Available</h4>
773-
<div class="version-comparison">
774-
<div class="version-item">
775-
<span class="version-label">Current:</span>
776-
<span class="version-value" id="current-version-display">0.1.0</span>
777-
</div>
778-
<div class="version-arrow"></div>
779-
<div class="version-item">
780-
<span class="version-label">Latest:</span>
781-
<span class="version-value" id="latest-version-display">0.2.0</span>
782-
</div>
783-
</div>
784-
<div class="update-actions">
785-
<button class="btn btn-primary" id="download-update-btn">
786-
<i class="ri-download-line"></i>
787-
Download & Install
788-
</button>
789-
<button class="btn btn-secondary" id="skip-update-btn">
790-
<i class="ri-close-line"></i>
791-
Skip This Version
792-
</button>
793-
</div>
794-
</div>
795-
</div>
796-
</div>
797-
798750
<div class="settings-section">
799751
<h3>Release Information</h3>
800752
<div class="release-info">
@@ -809,6 +761,44 @@ <h3>Release Information</h3>
809761
<span class="source-label">Update Source:</span>
810762
<code class="source-url" id="update-source-url">GitHub Releases</code>
811763
</div>
764+
765+
<div class="update-progress" id="update-progress" style="display: none;">
766+
<div class="progress-info">
767+
<h4 id="progress-title">Checking for updates...</h4>
768+
<p id="progress-description">Please wait while we check for the latest version.</p>
769+
</div>
770+
<div class="progress-bar">
771+
<div class="progress-fill" id="progress-fill" style="width: 0%"></div>
772+
<span class="progress-text" id="progress-text">0%</span>
773+
</div>
774+
</div>
775+
776+
<div class="update-info" id="update-info" style="display: none;">
777+
<div class="update-details">
778+
<h4>Update Available</h4>
779+
<div class="version-comparison">
780+
<div class="version-item">
781+
<span class="version-label">Current:</span>
782+
<span class="version-value" id="current-version-display">0.1.0</span>
783+
</div>
784+
<div class="version-arrow"></div>
785+
<div class="version-item">
786+
<span class="version-label">Latest:</span>
787+
<span class="version-value" id="latest-version-display">0.2.0</span>
788+
</div>
789+
</div>
790+
<div class="update-actions">
791+
<button class="btn btn-primary" id="download-update-btn">
792+
<i class="ri-download-line"></i>
793+
Download & Install
794+
</button>
795+
<button class="btn btn-secondary" id="skip-update-btn">
796+
<i class="ri-close-line"></i>
797+
Skip This Version
798+
</button>
799+
</div>
800+
</div>
801+
</div>
812802
</div>
813803
</div>
814804
</div>

0 commit comments

Comments
 (0)