ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / aura-kotlin / src / avdForm.ts 342 строк · изменён 14 нояб., 04:52
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
import * as vscode from 'vscode' ;
import { AndroidPanel } from './android' ;
import { tr } from './l10n' ;
interface InitData {
ok: boolean ;
error? : string ;
profiles: Array < { id: string ; name: string } > ;
images: string [ ] ;
arch: string ;
current AvdCreateForm
panel vscode WebviewPanel
busy
android AndroidPanel
name
panel vscode window
vscode ViewColumn Active
enableScripts retainContextWhenHidden
panel iconPath
panel webview html crypto
panel AvdCreateForm current AvdCreateForm current
panel webview message message
android AndroidPanel name
AvdCreateForm current
AvdCreateForm current panel
AvdCreateForm current android onCreated
message type profileId image downloadApi name start
message type
message type busy
busy
msg object panel webview msg
tools android
tools
image message image
image message downloadApi
arch process arch
image
type text image
android tools sdkmanager image
image
image
type text message name
android name message name image profileId message profileId
message start
type text
android message name
type name message name
message name
error
type text error error message error
busy
data InitData ok profiles images arch process arch
tools android
tools
data error
profiles images
android tools avdmanager
android tools sdkmanager
data ok
data profiles profiles
data images images
error
data error error error message error
panel webview type data
nonce
}
export
class
AvdCreateForm
{
private
static
:
|
undefined
;
private
readonly
:
.
;
private
=
false
;
private
constructor
(
private
readonly
:
,
private
readonly
onCreated
:
(
:
string
)
=>
void
,
)
{
this
.
=
.
.
createWebviewPanel
(
'auraKotlin.avdCreate'
,
tr
(
'New emulator (AVD)'
)
,
.
.
,
{
:
true
,
:
true
}
,
)
;
this
.
.
=
new
vscode
.
ThemeIcon
(
'device-mobile'
)
;
this
.
.
.
=
this
.
html
(
.
randomUUID
(
)
)
;
this
.
.
onDidDispose
(
(
)
=>
{
if
(
.
===
this
)
{
.
=
undefined
;
}
}
)
;
this
.
.
.
onDidReceiveMessage
(
=>
void
this
.
onMessage
(
)
)
;
}
static
show
(
:
,
onCreated
:
(
:
string
)
=>
void
)
:
void
{
if
(
.
)
{
.
.
.
reveal
(
)
;
return
;
}
.
=
new
AvdCreateForm
(
,
)
;
}
private
async
onMessage
(
:
{
?
:
string
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
boolean
}
)
:
Promise
<
void
>
{
if
(
?.
===
'init'
)
{
await
this
.
sendInit
(
)
;
return
;
}
if
(
?.
!==
'create'
||
this
.
)
{
return
;
}
this
.
=
true
;
const
post
=
(
:
)
=>
void
this
.
.
.
postMessage
(
)
;
try
{
const
=
await
this
.
.
avdTools
(
)
;
if
(
!
)
{
throw
new
Error
(
tr
(
'Android SDK is not configured. Open Android Doctor and set the SDK path.'
)
)
;
}
let
=
String
(
.
??
''
)
;
if
(
!
&&
.
)
{
const
=
.
===
'arm64'
?
'arm64-v8a'
:
'x86_64'
;
=
` system-images;android- ${ message. downloadApi} ;google_apis; ${ arch} `
;
post
(
{
:
'status'
,
:
tr
(
'Downloading system image {0}… (licenses are accepted automatically)'
,
)
}
)
;
if
(
!
await
this
.
.
installSystemImage
(
.
,
)
)
{
throw
new
Error
(
tr
(
'Failed to download {0}. Run sdkmanager manually and accept licenses.'
,
)
)
;
}
}
if
(
!
)
{
throw
new
Error
(
tr
(
'Select a system image.'
)
)
;
}
post
(
{
:
'status'
,
:
tr
(
'Creating emulator {0}…'
,
String
(
.
??
''
)
)
}
)
;
await
this
.
.
createAvdAdvanced
(
{
:
String
(
.
??
''
)
.
trim
(
)
,
,
:
String
(
.
??
''
)
}
)
;
if
(
.
)
{
post
(
{
:
'status'
,
:
tr
(
'Starting the emulator…'
)
}
)
;
await
this
.
.
startAvd
(
String
(
.
??
''
)
.
trim
(
)
)
;
}
post
(
{
:
'done'
,
:
String
(
.
??
''
)
.
trim
(
)
}
)
;
this
.
onCreated
(
String
(
.
??
''
)
.
trim
(
)
)
;
}
catch
(
)
{
post
(
{
:
'error'
,
:
instanceof
Error
?
.
:
String
(
)
}
)
;
}
finally
{
this
.
=
false
;
}
}
private
async
sendInit
(
)
:
Promise
<
void
>
{
const
:
=
{
:
false
,
:
[
]
,
:
[
]
,
:
.
===
'arm64'
?
'arm64-v8a'
:
'x86_64'
}
;
try
{
const
=
await
this
.
.
avdTools
(
)
;
if
(
!
)
{
.
=
tr
(
'Android SDK is not configured. Run "Android: Doctor" and set the SDK path, then reopen this form.'
)
;
}
else
{
const
[
,
]
=
await
Promise
.
all
(
[
this
.
.
listDeviceProfiles
(
.
)
,
this
.
.
listSystemImages
(
.
)
,
]
)
;
.
=
true
;
.
=
;
.
=
;
}
}
catch
(
)
{
.
=
instanceof
Error
?
.
:
String
(
)
;
}
void
this
.
.
.
postMessage
(
{
:
'init'
,
}
)
;
}
private
html
(
:
string
)
:
string
{
return
` <!doctype html><html><head><meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce- ${ nonce} ';">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> ${ tr ( 'New emulator' ) } </title>
<style>
:root {
--sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
--r-ctl: 6px; --r-card: 10px;
--dur-1: 90ms; --dur-2: 160ms; --dur-3: 240ms;
--ease-out: cubic-bezier(.2, 0, 0, 1);
--text: var(--vscode-foreground);
--muted: var(--vscode-descriptionForeground);
--surface: color-mix(in srgb, var(--vscode-editor-foreground) 4%, var(--vscode-editor-background));
--border: color-mix(in srgb, var(--vscode-editor-foreground) 14%, transparent);
--focus: var(--vscode-focusBorder);
--danger: var(--vscode-errorForeground);
--ok: var(--vscode-testing-iconPassed, var(--vscode-charts-green));
}
* { box-sizing: border-box; }
body {
margin: 0; padding: var(--sp-5) var(--sp-5) var(--sp-6);
font-family: var(--vscode-font-family); font-size: 13px; color: var(--text);
background: var(--vscode-editor-background);
}
.shell { max-width: 560px; margin-inline: auto; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 var(--sp-1); animation: fadeUp .3s var(--ease-out) both; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 var(--sp-5); animation: fadeUp .3s var(--ease-out) both; animation-delay: 40ms; }
.card {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4);
animation: fadeUp .35s var(--ease-out) both; animation-delay: 80ms;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.field { display: flex; flex-direction: column; gap: var(--sp-1); }
.field label { font-size: 11px; color: var(--muted); letter-spacing: .02em; }
.field .hint { font-size: 11px; color: var(--muted); }
input[type=text], select {
width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--r-ctl);
background: var(--vscode-input-background); color: var(--vscode-input-foreground);
font-family: inherit; font-size: 13px; outline: none;
transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
input[type=text]:hover, select:hover { border-color: color-mix(in srgb, var(--focus) 50%, var(--border)); }
input[type=text]:focus, select:focus {
border-color: var(--focus);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 25%, transparent);
}
.row { display: flex; gap: var(--sp-3); }
.row .field { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: var(--sp-2); cursor: pointer; user-select: none; color: var(--muted); transition: color var(--dur-1) var(--ease-out); }
.check:hover { color: var(--text); }
.check input { accent-color: var(--vscode-button-background); }
/* Кнопки: подъём при наведении, микро-сжатие при нажатии, фокус-кольцо */
.actions { display: flex; gap: var(--sp-2); align-items: center; }
.btn {
padding: 7px 18px; border: 1px solid transparent; border-radius: var(--r-ctl);
background: var(--vscode-button-background); color: var(--vscode-button-foreground);
font-family: inherit; font-size: 13px; cursor: pointer;
transition: background var(--dur-2) var(--ease-out), transform var(--dur-1) var(--ease-out), box-shadow var(--dur-2) var(--ease-out), opacity var(--dur-2) var(--ease-out);
}
.btn:hover:not(:disabled) { background: var(--vscode-button-hoverBackground); transform: translateY(-1px); box-shadow: 0 3px 8px color-mix(in srgb, #000 30%, transparent); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.97); box-shadow: none; transition-duration: var(--dur-1); }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible { outline: 1px solid var(--focus); outline-offset: 2px; }
.btn.ghost {
background: transparent; color: var(--muted); border-color: var(--border);
}
.btn.ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--focus) 8%, transparent); color: var(--text); border-color: var(--focus); box-shadow: none; }
.status { display: none; align-items: center; gap: var(--sp-2); font-size: 12px; color: var(--muted); }
.status.show { display: flex; animation: fadeUp .25s var(--ease-out); }
.spinner { width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 30%, transparent); border-top-color: var(--text); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { display: none; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-card); font-size: 12.5px; animation: fadeUp .25s var(--ease-out); }
.banner.show { display: block; }
.banner.error { background: color-mix(in srgb, var(--danger) 10%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.banner.ok { background: color-mix(in srgb, var(--ok) 10%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.api-row { display: none; }
.api-row.show { display: flex; animation: fadeUp .25s var(--ease-out); }
.skeleton { height: 34px; border-radius: var(--r-ctl); background: linear-gradient(90deg, var(--surface) 25%, color-mix(in srgb, var(--vscode-editor-foreground) 8%, var(--surface)) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
</style></head><body>
<div class="shell">
<h1> ${ tr ( 'New emulator (AVD)' ) } </h1>
<p class="sub"> ${ tr ( 'Phone model, Android version and name — the emulator will appear in the Android panel.' ) } </p>
<div class="banner error" id="bannerError"></div>
<div class="banner ok" id="bannerOk"></div>
<div class="card" id="form" style="display:none">
<div class="field">
<label for="profile"> ${ tr ( 'Device model' ) } </label>
<select id="profile"></select>
</div>
<div class="field">
<label for="image"> ${ tr ( 'System image' ) } </label>
<select id="image"></select>
<span class="hint" id="archHint"></span>
</div>
<div class="field api-row" id="apiRow">
<label for="api"> ${ tr ( 'API level to download' ) } </label>
<input type="text" id="api" value="35" maxlength="2" inputmode="numeric">
<span class="hint"> ${ tr ( 'Image will be downloaded via sdkmanager (~1 GB), licenses are accepted automatically.' ) } </span>
</div>
<div class="field">
<label for="name"> ${ tr ( 'Emulator name' ) } </label>
<input type="text" id="name" maxlength="40">
<span class="hint"> ${ tr ( 'Letters, digits, dot, dash and underscore.' ) } </span>
</div>
<label class="check"><input type="checkbox" id="startAfter" checked> ${ tr ( 'Start emulator after creation' ) } </label>
<div class="actions">
<button class="btn" id="btnCreate"> ${ tr ( 'Create emulator' ) } </button>
<div class="status" id="status"><span class="spinner"></span><span id="statusText"></span></div>
</div>
</div>
<div class="card" id="loading"><div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div></div>
</div>
<script nonce=" ${ nonce} ">
'use strict';
const vscode = acquireVsCodeApi();
const $ = (id) => document.getElementById(id);
const state = { profiles: [], images: [], arch: 'x86_64', busy: false, nameTouched: false };
function showBanner(id, text) {
for (const other of ['bannerError', 'bannerOk']) { $(other).classList.remove('show'); }
const el = $(id);
el.textContent = text;
el.classList.add('show');
}
function setStatus(text) {
$('status').classList.toggle('show', !!text);
$('statusText').textContent = text ?? '';
}
function setBusy(busy) {
state.busy = busy;
$('btnCreate').disabled = busy;
for (const el of document.querySelectorAll('#form select, #form input')) { el.disabled = busy; }
if (!busy) { setStatus(''); }
}
function apiOf(image) {
const m = /android-(\\d+)/.exec(image ?? '');
return m ? m[1] : '';
}
function suggestName() {
if (state.nameTouched) { return; }
const profile = $('profile').value || 'pixel';
const image = $('image').value;
const api = image ? apiOf(image) : $('api').value.trim();
$('name').value = profile.replace(/\\s+/g, '_') + (api ? '_api_' + api : '');
}
function fillForm(data) {
state.profiles = data.profiles;
state.images = data.images;
state.arch = data.arch;
$('profile').innerHTML = data.profiles.map(p => '<option value="' + p.id + '">' + p.name + '</option>').join('');
const pixel = data.profiles.findIndex(p => /pixel/i.test(p.name));
if (pixel >= 0) { $('profile').selectedIndex = pixel; }
const sorted = [...data.images].sort((a, b) => Number(apiOf(b)) - Number(apiOf(a)));
$('image').innerHTML = sorted.map(i => '<option value="' + i + '">API ' + apiOf(i) + ' · ' + i + '</option>').join('')
+ '<option value=""> ${ tr ( 'Download new system image…' ) } </option>';
$('archHint').textContent = ' ${ tr ( 'Architecture:' ) } ' + data.arch;
$('loading').style.display = 'none';
$('form').style.display = '';
suggestName();
}
$('image').addEventListener('change', () => {
$('apiRow').classList.toggle('show', !$('image').value);
suggestName();
});
$('profile').addEventListener('change', suggestName);
$('api').addEventListener('input', suggestName);
$('name').addEventListener('input', () => { state.nameTouched = true; });
$('btnCreate').addEventListener('click', () => {
if (state.busy) { return; }
const name = $('name').value.trim();
if (!/^[\\w.-]+$/.test(name)) { showBanner('bannerError', ' ${ tr ( 'Name: only letters, digits, dot, dash and underscore.' ) } '); return; }
const image = $('image').value;
const api = $('api').value.trim();
if (!image && !/^\\d{2}$/.test(api)) { showBanner('bannerError', ' ${ tr ( 'API level — two digits, e.g. 35.' ) } '); return; }
setBusy(true);
setStatus(image ? ' ${ tr ( 'Creating emulator…' ) } ' : ' ${ tr ( 'Downloading system image…' ) } ');
vscode.postMessage({
type: 'create',
profileId: $('profile').value,
image,
downloadApi: image ? undefined : api,
name,
start: $('startAfter').checked
});
});
window.addEventListener('message', (event) => {
const msg = event.data;
if (msg.type === 'init') {
if (msg.data.ok) { fillForm(msg.data); }
else {
$('loading').style.display = 'none';
showBanner('bannerError', msg.data.error || ' ${ tr ( 'Failed to get SDK data.' ) } ');
}
} else if (msg.type === 'status') {
setStatus(msg.text);
} else if (msg.type === 'error') {
setBusy(false);
showBanner('bannerError', msg.text || ' ${ tr ( 'Emulator creation error.' ) } ');
} else if (msg.type === 'done') {
setBusy(false);
setStatus('');
showBanner('bannerOk', ' ${ tr ( 'Emulator "{0}" has been created and is now in the Android panel list.' ) } '.replace('{0}', msg.name));
}
});
vscode.postMessage({ type: 'init' });
</script>
</body></html> `
;
}
}