Skip to content

Commit 8ebf20d

Browse files
committed
feat: add version management and update UI for checking updates
1 parent 01764ba commit 8ebf20d

File tree

7 files changed

+94
-17
lines changed

7 files changed

+94
-17
lines changed

release.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ update_version_in_files() {
7474
sed -i '' "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" package.json
7575
sed -i '' "s/version = \"$old_version\"/version = \"$new_version\"/" src-tauri/Cargo.toml
7676
sed -i '' "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" src-tauri/tauri.conf.json
77+
# Aggiorna version.js
78+
sed -i '' "s/APP_VERSION = '$old_version'/APP_VERSION = '$new_version'/" src/version.js
7779
else
7880
# Linux
7981
sed -i "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" package.json
8082
sed -i "s/version = \"$old_version\"/version = \"$new_version\"/" src-tauri/Cargo.toml
8183
sed -i "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" src-tauri/tauri.conf.json
84+
# Aggiorna version.js
85+
sed -i "s/APP_VERSION = '$old_version'/APP_VERSION = '$new_version'/" src/version.js
8286
fi
8387

8488
print_success "Versione aggiornata nei file di configurazione"
@@ -107,10 +111,10 @@ commit_and_tag() {
107111
local message="$2"
108112

109113
print_step "Aggiunta file modificati a git..."
110-
git add package.json src-tauri/Cargo.toml src-tauri/Cargo.lock src-tauri/tauri.conf.json
114+
git add package.json src-tauri/Cargo.toml src-tauri/Cargo.lock src-tauri/tauri.conf.json src/version.js
111115

112116
# Se ci sono altri file modificati, chiedi se aggiungerli
113-
if [[ -n $(git status --porcelain | grep -v "package.json\|Cargo.toml\|Cargo.lock\|tauri.conf.json") ]]; then
117+
if [[ -n $(git status --porcelain | grep -v "package.json\|Cargo.toml\|Cargo.lock\|tauri.conf.json\|version.js") ]]; then
114118
print_warning "Ci sono altri file modificati. Vuoi aggiungerli al commit? (y/N)"
115119
read -r response
116120
if [[ "$response" =~ ^[Yy]$ ]]; then

src/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,12 @@ <h3>Current Version</h3>
713713
<span class="status-text">Checking for updates...</span>
714714
</div>
715715
</div>
716+
<div class="version-actions">
717+
<button class="btn btn-primary" id="check-updates-btn">
718+
<i class="ri-refresh-line"></i>
719+
Check for Updates
720+
</button>
721+
</div>
716722
</div>
717723
</div>
718724

@@ -744,10 +750,6 @@ <h3>Update Settings</h3>
744750
<h3>Update Actions</h3>
745751

746752
<div class="update-actions">
747-
<button class="btn btn-primary" id="check-updates-btn">
748-
<i class="ri-refresh-line"></i>
749-
Check for Updates
750-
</button>
751753
<button class="btn btn-secondary" id="view-changelog-btn">
752754
<i class="ri-file-text-line"></i>
753755
View Changelog

src/main.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,31 @@ function setupUpdateManagement() {
515515
const downloadUpdateBtn = document.getElementById('download-update-btn');
516516
const skipUpdateBtn = document.getElementById('skip-update-btn');
517517

518-
// Set current version
519-
if (currentVersionElement) {
520-
currentVersionElement.textContent = '0.1.0'; // You should get this from tauri.conf.json
521-
}
522-
if (currentVersionDisplay) {
523-
currentVersionDisplay.textContent = '0.1.0';
518+
// Set current version - get it from update manager
519+
async function setCurrentVersion() {
520+
try {
521+
const currentVersion = await updateManager.getCurrentVersion();
522+
if (currentVersionElement) {
523+
currentVersionElement.textContent = currentVersion;
524+
}
525+
if (currentVersionDisplay) {
526+
currentVersionDisplay.textContent = currentVersion;
527+
}
528+
console.log('📋 Versione corrente impostata:', currentVersion);
529+
} catch (error) {
530+
console.error('❌ Errore nel recupero versione corrente:', error);
531+
// Fallback ai valori di default
532+
if (currentVersionElement) {
533+
currentVersionElement.textContent = '0.1.0';
534+
}
535+
if (currentVersionDisplay) {
536+
currentVersionDisplay.textContent = '0.1.0';
537+
}
538+
}
524539
}
540+
541+
// Imposta la versione corrente
542+
setCurrentVersion();
525543

526544
// Setup repository link
527545
if (viewReleasesLink) {

src/managers/update-manager.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* tramite GitHub releases utilizzando il plugin updater di Tauri.
66
*/
77

8+
import { APP_VERSION } from '../version.js';
9+
810
export class UpdateManager {
911
constructor() {
1012
this.updateAvailable = false;
@@ -617,13 +619,49 @@ export class UpdateManager {
617619
return testVersion;
618620
}
619621

622+
// Prova prima l'API Tauri
620623
if (window.__TAURI__?.app?.getVersion) {
621-
return await window.__TAURI__.app.getVersion();
624+
const version = await window.__TAURI__.app.getVersion();
625+
console.log('📋 Versione da Tauri API:', version);
626+
return version;
627+
}
628+
629+
// Prova l'API core di Tauri se disponibile
630+
if (window.__TAURI__?.core?.invoke) {
631+
try {
632+
const version = await window.__TAURI__.core.invoke('plugin:app|version');
633+
console.log('📋 Versione da Tauri core:', version);
634+
return version;
635+
} catch (coreError) {
636+
console.warn('⚠️ Tauri core invoke non disponibile:', coreError);
637+
}
638+
}
639+
640+
// Usa la versione importata dal file version.js
641+
if (APP_VERSION && APP_VERSION !== '0.1.18') {
642+
console.log('📋 Versione da version.js:', APP_VERSION);
643+
return APP_VERSION;
622644
}
623-
return '0.1.0'; // fallback
645+
646+
// Fallback: leggi dal package.json se possibile
647+
try {
648+
const response = await fetch('./package.json');
649+
if (response.ok) {
650+
const packageData = await response.json();
651+
if (packageData.version) {
652+
console.log('📋 Versione da package.json:', packageData.version);
653+
return packageData.version;
654+
}
655+
}
656+
} catch (fetchError) {
657+
console.warn('⚠️ Non riesco a leggere package.json:', fetchError);
658+
}
659+
660+
console.warn('⚠️ Nessun metodo per ottenere la versione funziona, uso APP_VERSION');
661+
return APP_VERSION; // fallback alla versione importata
624662
} catch (error) {
625-
console.warn('Non riesco a ottenere la versione corrente:', error);
626-
return '0.1.0';
663+
console.warn('❌ Errore nel recupero versione corrente:', error);
664+
return APP_VERSION; // fallback alla versione importata
627665
}
628666
}
629667

src/styles/settings.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@
442442
color: var(--error-color);
443443
}
444444

445+
/* Version Actions */
446+
.version-actions {
447+
margin-top: 12px;
448+
display: flex;
449+
justify-content: flex-start;
450+
}
451+
452+
.version-actions .btn {
453+
font-size: 14px;
454+
padding: 8px 16px;
455+
}
456+
445457
/* Update Actions */
446458
.update-actions {
447459
display: flex;

src/utils/theme-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ThemeLoader {
3939
// that gets updated by the build process or manually maintained
4040

4141
// This could be enhanced to use a build-time script that generates this list
42-
const knownThemes = [
42+
const knownThemes = [
4343
'espresso.css',
4444
'matrix.css',
4545
'pommodore64.css'

src/version.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Questo file viene generato automaticamente durante il build
2+
// Contiene la versione corrente dell'applicazione
3+
export const APP_VERSION = '0.1.18';

0 commit comments

Comments
 (0)