118 lines
6.0 KiB
Rust
118 lines
6.0 KiB
Rust
// 開始使用: what a new install shows instead of a chat. There are no bots until the person makes
|
||
// one; the guide takes them through it — connect a model, make the first bot — or signs in to
|
||
// bring the bots they already have on another computer.
|
||
|
||
use super::*;
|
||
|
||
impl App {
|
||
/// The first AI service that is ready to answer (has its key).
|
||
pub(super) fn ready_provider(&self) -> Option<ProviderKind> {
|
||
ALL_PROVIDERS.iter().copied().find(|k| k.needs_key() && !providers::resolve_key(*k, &self.state.provider(*k).api_key).is_empty())
|
||
}
|
||
|
||
pub(super) fn welcome(&mut self, ui: &mut egui::Ui) {
|
||
let p = self.pal;
|
||
let ready = self.ready_provider();
|
||
let signed_in = !self.state.remote.host_token.is_empty();
|
||
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
|
||
let w = (ui.available_width() - 48.0).clamp(240.0, 520.0);
|
||
ui.add_space((ui.available_height() * 0.12).clamp(24.0, 90.0));
|
||
ui.vertical_centered(|ui| {
|
||
ui.set_max_width(w);
|
||
ui.label(RichText::new(t("歡迎使用 AnyBot")).size(26.0).strong().color(p.text));
|
||
ui.add_space(4.0);
|
||
ui.label(RichText::new(t("跟著下面的步驟,一分鐘就能開始聊天。")).size(FONT_BASE).color(p.text2));
|
||
ui.add_space(22.0);
|
||
});
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(((ui.available_width() - w) / 2.0).max(0.0));
|
||
ui.vertical(|ui| {
|
||
ui.set_width(w);
|
||
// A screen of another computer: its bots are on the way.
|
||
if self.mir.on && !self.mir.online {
|
||
let status = self.mir.status.lock().unwrap().clone();
|
||
setting_card(ui, p, |ui| {
|
||
ui.horizontal(|ui| {
|
||
ui.spinner();
|
||
ui.label(RichText::new(t("正在同步帳號裡的 Bot…")).strong());
|
||
});
|
||
if !status.is_empty() {
|
||
hint(ui, status, p);
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
let mut go_keys = false;
|
||
let mut go_new = false;
|
||
let mut go_account = false;
|
||
step(ui, p, 1, "連上 AI 模型", ready.is_some(), |ui| {
|
||
match ready {
|
||
Some(k) => hint(ui, format!("已經可以用 {}。", k.label()), p),
|
||
None => {
|
||
hint(ui, "選一個 AI 服務(xAI、OpenAI、Claude、Gemini…),貼上它的 API 金鑰。也可以用自己電腦上的 Ollama,不用金鑰。", p);
|
||
ui.add_space(6.0);
|
||
if ui.add(primary_button("設定模型", p)).clicked() {
|
||
go_keys = true;
|
||
}
|
||
}
|
||
}
|
||
});
|
||
step(ui, p, 2, "建立你的第一個 Bot", false, |ui| {
|
||
hint(ui, "幫它取名字、寫下它要做什麼。之後隨時可以再加更多 Bot。", p);
|
||
ui.add_space(6.0);
|
||
let b = if ready.is_some() { primary_button("建立 Bot", p) } else { secondary_button("建立 Bot") };
|
||
if ui.add(b).clicked() {
|
||
go_new = true;
|
||
}
|
||
});
|
||
ui.add_space(6.0);
|
||
setting_card(ui, p, |ui| {
|
||
ui.label(RichText::new(t("在別台電腦用過 AnyBot?")).strong());
|
||
if signed_in {
|
||
let note = self.rm.note.lock().unwrap().clone();
|
||
hint(ui, if note.is_empty() { "已登入帳號。帳號裡沒有別的 Bot,從上面建立第一個吧。".to_string() } else { note }, p);
|
||
} else {
|
||
hint(ui, "登入你的帳號,那邊的 Bot、聊天和設定會自動同步到這台;這台的也會同步上去。", p);
|
||
ui.add_space(6.0);
|
||
if ui.add(secondary_button("登入帳號")).clicked() {
|
||
go_account = true;
|
||
}
|
||
}
|
||
});
|
||
if go_keys {
|
||
self.show_settings = true;
|
||
self.settings_tab = SettingsTab::Providers;
|
||
self.settings_provider = ProviderKind::Xai;
|
||
}
|
||
if go_new {
|
||
self.new_bot();
|
||
}
|
||
if go_account {
|
||
self.show_settings = true;
|
||
self.settings_tab = SettingsTab::Remote;
|
||
}
|
||
});
|
||
});
|
||
});
|
||
}
|
||
}
|
||
|
||
/// One numbered step of the guide (a check mark once it is done).
|
||
fn step(ui: &mut egui::Ui, p: Palette, n: u32, title: &str, done: bool, body: impl FnOnce(&mut egui::Ui)) {
|
||
setting_card(ui, p, |ui| {
|
||
ui.horizontal(|ui| {
|
||
let (r, _) = ui.allocate_exact_size(vec2(24.0, 24.0), egui::Sense::hover());
|
||
let fill = if done { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.primary };
|
||
ui.painter().circle_filled(r.center(), 12.0, fill);
|
||
let mark = if done { "✓".to_string() } else { n.to_string() };
|
||
ui.painter().text(r.center(), egui::Align2::CENTER_CENTER, mark, egui::FontId::proportional(13.0), if done { Color32::WHITE } else { p.on_primary });
|
||
ui.add_space(4.0);
|
||
ui.label(RichText::new(t(title)).size(FONT_BASE).strong().color(p.text));
|
||
});
|
||
ui.horizontal(|ui| {
|
||
ui.add_space(32.0);
|
||
ui.vertical(|ui| body(ui));
|
||
});
|
||
});
|
||
}
|