Ariver
2026-07-03 a075aec123e1f7118f138738f196c2995aa96f98
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<script lang="ts">
  import { onMount } from 'svelte'
  import { Events, Call } from '@wailsio/runtime'
  import { t } from '../../lib/i18n'
  import { engineStatus } from '../../lib/stores/app'
  import AppIcon from '../shared/AppIcon.svelte'
 
  let statusText = $state(t('onboarding.syncModel'))
  let detailText = $state('')
  let progress = $state(0)
  let failed = $state(false)
  let downloadActive = $state(false)
  let cancelling = $state(false)
  let currentModelID = $state('')
 
  onMount(() => {
    const offDownloadProgress = Events.On('model:download-progress', (ev: any) => {
      const data = ev?.data
      if (data?.percent != null) {
        if (data?.modelID) {
          currentModelID = data.modelID
        }
        downloadActive = true
        cancelling = false
        failed = false
        statusText = t('onboarding.syncModel')
        progress = data.percent
        const downloadedMB = Math.floor((data.downloaded || 0) / 1024 / 1024)
        const totalMB = Math.floor((data.total || 0) / 1024 / 1024)
        detailText = `${data.percent.toFixed(1)}% (${downloadedMB}MB / ${totalMB}MB)`
      }
    })
 
    const offEngineStatus = Events.On('engine:status', (ev: any) => {
      const data = ev?.data
      if (data?.status === 'ready') {
        downloadActive = false
        cancelling = false
        failed = false
        statusText = t('onboarding.complete')
        progress = 100
      } else if (data?.status === 'need_model') {
        const error = typeof data?.error === 'string' ? data.error.trim() : ''
        if (error && !downloadActive) {
          statusText = t('onboarding.failed')
          detailText = error
          failed = true
        }
      } else if (data?.status === 'error') {
        downloadActive = false
        cancelling = false
        statusText = t('onboarding.failed')
        detailText = data?.error || ''
        failed = true
      }
    })
 
    triggerDownload()
 
    return () => {
      offDownloadProgress()
      offEngineStatus()
    }
  })
 
  async function triggerDownload() {
    try {
      const current: any = await Call.ByName('voicesnap/services.EngineService.GetCurrentModelStatus')
      currentModelID = typeof current?.modelID === 'string' ? current.modelID : ''
      downloadActive = true
      cancelling = false
      failed = false
      statusText = t('onboarding.syncModel')
      detailText = ''
      await Call.ByName('voicesnap/services.EngineService.DownloadCurrentModel')
      downloadActive = false
      statusText = t('onboarding.optimizing')
      detailText = t('onboarding.extracting')
    } catch (err: any) {
      downloadActive = false
      cancelling = false
      if (isCancelError(err)) {
        statusText = t('onboarding.cancelled')
        detailText = t('onboarding.cancelledDetail')
      } else {
        statusText = t('onboarding.failed')
        detailText = err?.message || String(err)
      }
      failed = true
    }
  }
 
  function isCancelError(err: any): boolean {
    const text = String(err?.message || err || '').toLowerCase()
    return text.includes('context canceled') || text.includes('cancelled') || text.includes('canceled')
  }
 
  async function cancelDownload() {
    if (!downloadActive || cancelling) return
    cancelling = true
    statusText = t('onboarding.cancelling')
    await Call.ByName('voicesnap/services.EngineService.CancelModelDownload', currentModelID)
  }
</script>
 
<div class="onboarding">
  <div class="card">
    <div class="icon">
      <AppIcon size={56} elevated />
    </div>
    <h1 class="title">{t('onboarding.title')}</h1>
 
    <div class="status">
      <p class="status-text" class:failed>{statusText}</p>
      {#if detailText}
        <p class="detail-text">{detailText}</p>
      {/if}
    </div>
 
    <!-- Progress bar -->
    <div class="progress-track">
      <div class="progress-fill" style="width: {progress}%" class:failed></div>
    </div>
 
    <div class="actions">
      {#if downloadActive}
        <button class="action cancel" onclick={cancelDownload} disabled={cancelling}>
          {cancelling ? t('onboarding.cancelling') : t('onboarding.cancel')}
        </button>
      {:else if failed}
        <button class="action primary" onclick={triggerDownload}>
          {t('onboarding.retry')}
        </button>
      {/if}
    </div>
  </div>
</div>
 
<style>
  .onboarding {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--color-bg-secondary);
    padding: var(--spacing-xxl);
  }
 
  .card {
    background: var(--color-bg-primary);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xxl) 48px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
  }
 
  .icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--spacing-lg);
  }
 
  .title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin-bottom: var(--spacing-xl);
  }
 
  .status {
    margin-bottom: var(--spacing-lg);
  }
 
  .status-text {
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-label);
  }
 
  .status-text.failed {
    color: var(--color-red);
  }
 
  .detail-text {
    margin-top: var(--spacing-xs);
    font-size: var(--font-size-sm);
    color: var(--color-secondary-label);
  }
 
  .progress-track {
    height: 6px;
    background: var(--color-bg-secondary);
    border-radius: 3px;
    overflow: hidden;
  }
 
  .progress-fill {
    height: 100%;
    background: var(--color-blue);
    border-radius: 3px;
    transition: width 200ms ease;
  }
 
  .progress-fill.failed {
    background: var(--color-red);
  }
 
  .actions {
    margin-top: var(--spacing-lg);
    min-height: 32px;
  }
 
  .action {
    min-width: 96px;
    height: 32px;
    padding: 0 14px;
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
  }
 
  .action.primary {
    background: var(--color-blue);
  }
 
  .action.cancel {
    background: var(--color-red);
  }
 
  .action:disabled {
    cursor: not-allowed;
    opacity: 0.72;
  }
</style>