swadhinbiswas Initial release v0.1.0 · 1/16/2026
ed7a4e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* Update Checker Component
*
* Checks for app updates and shows notification banner when update is available.
* Uses Tauri's updater plugin for automatic updates.
*/
import { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { Download, X, RefreshCw, CheckCircle, AlertCircle } from 'lucide-react';
import { check } from '@tauri-apps/plugin-updater';
import { relaunch } from '@tauri-apps/plugin-process';
type UpdateStatus = 'idle' | 'checking' | 'available' | 'downloading' | 'ready' | 'error' | 'upToDate';
interface UpdateInfo {
version: string;
body: string;
date: string;
}
export default function UpdateChecker() {
const [status, setStatus] = useState<UpdateStatus>('idle');
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | null>(null);
const [progress, setProgress] = useState(0);
const [error, setError] = useState<string | null>(null);
const [dismissed, setDismissed] = useState(false);
// Check for updates on mount and periodically
useEffect(() => {
// Check after 5 seconds to not slow down initial load
const initialCheck = setTimeout(() => {
checkForUpdates();
}, 5000);
// Check every 6 hours
const interval = setInterval(() => {
checkForUpdates();
}, 6 * 60 * 60 * 1000);
return () => {
clearTimeout(initialCheck);
clearInterval(interval);
};
}, []);
const checkForUpdates = async () => {
try {
setStatus('checking');
setError(null);
const update = await check();
if (update) {
setUpdateInfo({
version: update.version,
body: update.body || 'Bug fixes and improvements',
date: update.date || new Date().toISOString(),
});
setStatus('available');
setDismissed(false);
} else {
setStatus('upToDate');
// Hide "up to date" after 3 seconds
setTimeout(() => setStatus('idle'), 3000);
}
} catch (err) {
// Fail silently - update server may not be configured yet
console.warn('Update check failed:', err);
setStatus('idle');
}
};
const downloadAndInstall = async () => {
try {
setStatus('downloading');
setProgress(0);
const update = await check();
if (!update) {
setStatus('idle');
return;
}
// Download with progress
await update.downloadAndInstall((event: any) => {
if (event.event === 'Started') {
console.log('Download started');
} else if (event.event === 'Progress') {
const eventData = event.data as any;
const total = eventData?.contentLength || eventData?.total || 0;
const downloaded = eventData?.chunkLength || eventData?.downloaded || 0;
if (total > 0) {
setProgress(Math.round((downloaded / total) * 100));
}
} else if (event.event === 'Finished') {
console.log('Download finished');
}
});
setStatus('ready');
} catch (err) {
console.error('Update download failed:', err);
setError(err instanceof Error ? err.message : 'Failed to download update');
setStatus('error');
}
};
const restartApp = async () => {
try {
await relaunch();
} catch (err) {
console.error('Failed to restart:', err);
}
};
// Don't show if dismissed or idle
if (dismissed || status === 'idle') {
return null;
}
return (
<AnimatePresence>
<motion.div
initial={{ y: -50, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: -50, opacity: 0 }}
className="fixed top-0 left-0 right-0 z-[60] flex justify-center p-2"
>
<div className="flex items-center gap-3 px-4 py-2 rounded-lg shadow-lg bg-gradient-to-r from-primary-600 to-primary-500 text-white max-w-2xl">
{/* Status Icon */}
{status === 'checking' && (
<RefreshCw className="w-5 h-5 animate-spin" />
)}
{status === 'available' && (
<Download className="w-5 h-5" />
)}
{status === 'downloading' && (
<RefreshCw className="w-5 h-5 animate-spin" />
)}
{status === 'ready' && (
<CheckCircle className="w-5 h-5" />
)}
{status === 'upToDate' && (
<CheckCircle className="w-5 h-5" />
)}
{status === 'error' && (
<AlertCircle className="w-5 h-5" />
)}
{/* Message */}
<div className="flex-1">
{status === 'checking' && (
<span className="text-sm">Checking for updates...</span>
)}
{status === 'available' && updateInfo && (
<span className="text-sm">
<strong>Update available!</strong> ChanDesk v{updateInfo.version}
</span>
)}
{status === 'downloading' && (
<span className="text-sm">
Downloading update... {progress}%
</span>
)}
{status === 'ready' && (
<span className="text-sm">
Update ready! Restart to apply.
</span>
)}
{status === 'upToDate' && (
<span className="text-sm">You're on the latest version!</span>
)}
{status === 'error' && (
<span className="text-sm text-red-200">{error}</span>
)}
</div>
{/* Actions */}
{status === 'available' && (
<button
onClick={downloadAndInstall}
className="px-3 py-1 text-sm font-medium bg-white text-primary-600 rounded hover:bg-gray-100 transition-colors"
>
Update Now
</button>
)}
{status === 'ready' && (
<button
onClick={restartApp}
className="px-3 py-1 text-sm font-medium bg-white text-primary-600 rounded hover:bg-gray-100 transition-colors"
>
Restart
</button>
)}
{status === 'error' && (
<button
onClick={checkForUpdates}
className="px-3 py-1 text-sm font-medium bg-white/20 rounded hover:bg-white/30 transition-colors"
>
Retry
</button>
)}
{/* Dismiss */}
{['available', 'error', 'upToDate'].includes(status) && (
<button
onClick={() => setDismissed(true)}
className="p-1 hover:bg-white/20 rounded transition-colors"
>
<X className="w-4 h-4" />
</button>
)}
</div>
</motion.div>
</AnimatePresence>
);
}