Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
[*] Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Sep 20, 2023
1 parent 8eda5dc commit da63557
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
14 changes: 7 additions & 7 deletions chatbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ keywords= ["ChatGPT", "Slint", "Rust"]
log = "0.4"
env_logger = "0.9"
chrono = "0.4"
serde = "1.0.139"
serde_derive = "1.0.139"
serde_json = "1.0.82"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
lazy_static = "1.4"
rusqlite = "0.27"
clipboard = "0.5"
anyhow = "1.0"
platform-dirs = "0.3"
rodio = "0.17"
bytes = "1.4.0"
bytes = "1.4"
cpal = "0.15"
hound = "3.5"

slint = { version = "1.2", features = ["log"] }
uuid = { version = "1.3", features = ["v4"] }
reqwest = { version = "0.11", features = ["json", "stream", "socks"] }
tokio = {version = "1.17", features = ["full"]}
tokio-stream = "0.1.12"
rand = "0.8.5"
tokio-stream = "0.1"
rand = "0.8"

[build-dependencies]
slint-build = "1.0.0"
slint-build = "1.2"
cmd_lib = "1.3"

16 changes: 10 additions & 6 deletions chatbox/src/logic/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub fn init(ui: &AppWindow) {
}

let mut datas: Vec<ChatItem> = ui.global::<Store>().get_session_datas().iter().collect();

let datas_is_empty = datas.is_empty();
let uuid = Uuid::new_v4().to_string();

datas.push(ChatItem {
Expand All @@ -234,11 +234,15 @@ pub fn init(ui: &AppWindow) {
ui.global::<Store>()
.set_session_datas(Rc::new(VecModel::from(datas)).into());

for i in 1..=2 {
let ui = ui.as_weak();
Timer::single_shot(Duration::from_millis(i * 100), move || {
ui.unwrap().invoke_chats_scroll_to_bottom()
});
if !datas_is_empty {
for i in 1..=2 {
let ui = ui.as_weak();
Timer::single_shot(Duration::from_millis(i * 100), move || {
ui.unwrap().invoke_chats_scroll_to_bottom()
});
}
} else {
ui.invoke_jump_to_viewport_y(0_f32);
}

let (system_prompt, api_model, _, use_history) =
Expand Down
14 changes: 11 additions & 3 deletions chatbox/src/logic/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,29 @@ pub fn init(ui: &AppWindow) {
ui.get_archive_search_text(),
);

let sessions_model = Rc::new(VecModel::from(sessions));
let sessions_model = ModelRc::new(VecModel::from(sessions));
if sessions_model.row_count() > 0 {
ui.global::<Store>()
.set_session_datas(sessions_model.row_data(0).unwrap().chat_items);
}

ui.global::<Store>()
.set_chat_sessions(sessions_model.into());
.set_chat_sessions(sessions_model);
ui.global::<Logic>()
.invoke_show_message((tr("删除会话成功") + "!").into(), "success".into());
});

ui.global::<Logic>().on_reset_current_session(move || {
let ui = ui_reset_handle.unwrap();
ui.global::<Store>().set_session_datas(ModelRc::default());
// ui.global::<Store>().set_session_datas(ModelRc::default());

ui.global::<Store>()
.get_session_datas()
.as_any()
.downcast_ref::<VecModel<ChatItem>>()
.expect("We know we set a VecModel earlier")
.set_vec(vec![]);
ui.invoke_jump_to_viewport_y(0_f32);

ui.global::<Logic>()
.invoke_show_message((tr("重置成功") + "!").into(), "success".into());
Expand Down
2 changes: 1 addition & 1 deletion chatbox/src/version.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub static VERSION: &str = "v1.6.29";
pub static VERSION: &str = "v1.6.30";
4 changes: 4 additions & 0 deletions chatbox/ui/base/md.slint
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export component MD inherits Rectangle {

callback copy(string);

TouchArea {
mouse-cursor: MouseCursor.text;
}

vbox := VerticalLayout {
for item in items : HorizontalLayout {
if item.text-type == "plain" : Rectangle {
Expand Down
3 changes: 3 additions & 0 deletions chatbox/ui/rightPanel/body/panel.slint
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export component Body inherits Rectangle {
in-out property viewport-y <=> lv.viewport-y;
in-out property viewport-height <=> lv.viewport-height;

// border-width: 2px;
// border-color: red;

function new-chat-text(utext: string, btext: string) -> string {
return utext + "\n\n" + btext;
}
Expand Down

0 comments on commit da63557

Please sign in to comment.