feat: gemini render support, links

This commit is contained in:
Artemy Egorov 2024-08-04 20:30:00 +03:00
parent d96b863ea8
commit 135cb5c1a2
21 changed files with 220 additions and 174 deletions

157
src-tauri/Cargo.lock generated
View file

@ -246,9 +246,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.16.1" version = "1.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -301,9 +301,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.6" version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc"
dependencies = [ dependencies = [
"jobserver", "jobserver",
"libc", "libc",
@ -603,9 +603,9 @@ dependencies = [
[[package]] [[package]]
name = "dalet" name = "dalet"
version = "1.0.0-pre9" version = "1.0.0-pre.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2095f83b5256dc9a981639c3250aba53c02736a3601c1e6b2c54c27ec786274a" checksum = "8cccea0b163fbc0bc06f125bf69dfff4518336b63b86462f8c711366eef9e3e3"
dependencies = [ dependencies = [
"clap", "clap",
"enum-procs", "enum-procs",
@ -727,9 +727,9 @@ dependencies = [
[[package]] [[package]]
name = "dunce" name = "dunce"
version = "1.0.4" version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
[[package]] [[package]]
name = "embed-resource" name = "embed-resource"
@ -740,7 +740,7 @@ dependencies = [
"cc", "cc",
"memchr", "memchr",
"rustc_version", "rustc_version",
"toml 0.8.16", "toml 0.8.19",
"vswhom", "vswhom",
"winreg 0.52.0", "winreg 0.52.0",
] ]
@ -825,9 +825,9 @@ dependencies = [
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.30" version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@ -1149,7 +1149,7 @@ checksum = "10c6ae9f6fa26f4fb2ac16b528d138d971ead56141de489f8111e259b9df3c4a"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"heck 0.4.1", "heck 0.4.1",
"proc-macro-crate", "proc-macro-crate 1.3.1",
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1244,7 +1244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684c0456c086e8e7e9af73ec5b84e35938df394712054550e81558d21c44ab0d" checksum = "684c0456c086e8e7e9af73ec5b84e35938df394712054550e81558d21c44ab0d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"proc-macro-crate", "proc-macro-crate 1.3.1",
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1263,7 +1263,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"http 0.2.12", "http 0.2.12",
"indexmap 2.2.6", "indexmap 2.3.0",
"slab", "slab",
"tokio", "tokio",
"tokio-util", "tokio-util",
@ -1282,7 +1282,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"http 1.1.0", "http 1.1.0",
"indexmap 2.2.6", "indexmap 2.3.0",
"slab", "slab",
"tokio", "tokio",
"tokio-util", "tokio-util",
@ -1622,9 +1622,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.2.6" version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown 0.14.5", "hashbrown 0.14.5",
@ -2016,7 +2016,7 @@ version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate 1.3.1",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 1.0.109",
@ -2028,7 +2028,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate 3.1.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.72", "syn 2.0.72",
@ -2387,7 +2387,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"indexmap 2.2.6", "indexmap 2.3.0",
"quick-xml", "quick-xml",
"serde", "serde",
"time", "time",
@ -2414,9 +2414,12 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.17" version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "precomputed-hash" name = "precomputed-hash"
@ -2434,6 +2437,15 @@ dependencies = [
"toml_edit 0.19.15", "toml_edit 0.19.15",
] ]
[[package]]
name = "proc-macro-crate"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [
"toml_edit 0.21.1",
]
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@ -2609,9 +2621,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.5" version = "1.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -2720,7 +2732,7 @@ dependencies = [
"once_cell", "once_cell",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"rustls-pemfile 2.1.2", "rustls-pemfile 2.1.3",
"serde", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
@ -2828,9 +2840,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pemfile" name = "rustls-pemfile"
version = "2.1.2" version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"rustls-pki-types", "rustls-pki-types",
@ -2969,12 +2981,13 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.120" version = "1.0.122"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da"
dependencies = [ dependencies = [
"indexmap 2.2.6", "indexmap 2.3.0",
"itoa 1.0.11", "itoa 1.0.11",
"memchr",
"ryu", "ryu",
"serde", "serde",
] ]
@ -3021,7 +3034,7 @@ dependencies = [
"chrono", "chrono",
"hex", "hex",
"indexmap 1.9.3", "indexmap 1.9.3",
"indexmap 2.2.6", "indexmap 2.3.0",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
@ -3303,7 +3316,7 @@ dependencies = [
"cfg-expr 0.15.8", "cfg-expr 0.15.8",
"heck 0.5.0", "heck 0.5.0",
"pkg-config", "pkg-config",
"toml 0.8.16", "toml 0.8.19",
"version-compare 0.2.0", "version-compare 0.2.0",
] ]
@ -3378,9 +3391,9 @@ dependencies = [
[[package]] [[package]]
name = "target-lexicon" name = "target-lexicon"
version = "0.12.15" version = "0.12.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]] [[package]]
name = "tauri" name = "tauri"
@ -3581,12 +3594,13 @@ dependencies = [
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.10.1" version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" checksum = "b8fcd239983515c23a32fb82099f97d0b11b8c72f654ed659363a95c3dad7a53"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"once_cell",
"rustix", "rustix",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@ -3784,21 +3798,21 @@ dependencies = [
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.16" version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c" checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
dependencies = [ dependencies = [
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"toml_edit 0.22.17", "toml_edit 0.22.20",
] ]
[[package]] [[package]]
name = "toml_datetime" name = "toml_datetime"
version = "0.6.7" version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@ -3809,7 +3823,7 @@ version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [ dependencies = [
"indexmap 2.2.6", "indexmap 2.3.0",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
@ -3818,15 +3832,26 @@ dependencies = [
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.22.17" version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [ dependencies = [
"indexmap 2.2.6", "indexmap 2.3.0",
"toml_datetime",
"winnow 0.5.40",
]
[[package]]
name = "toml_edit"
version = "0.22.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
dependencies = [
"indexmap 2.3.0",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"winnow 0.6.16", "winnow 0.6.18",
] ]
[[package]] [[package]]
@ -4295,11 +4320,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]] [[package]]
name = "winapi-util" name = "winapi-util"
version = "0.1.8" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -4412,6 +4437,15 @@ dependencies = [
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.48.5" version = "0.48.5"
@ -4661,9 +4695,9 @@ dependencies = [
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.6.16" version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c" checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -4758,6 +4792,27 @@ dependencies = [
"rustix", "rustix",
] ]
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.72",
]
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.8.1" version = "1.8.1"

View file

@ -26,7 +26,7 @@ tauri = { version = "1", features = [
] } ] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
dalet = "1.0.0-pre9" dalet = "1.0.0-pre.10"
tokio = { version = "1.39.2", features = ["full"] } tokio = { version = "1.39.2", features = ["full"] }
tokio-rustls = { version = "0.26.0", default-features = false, features = [ tokio-rustls = { version = "0.26.0", default-features = false, features = [

View file

@ -14,9 +14,10 @@ use utils::{read_or_create_jsonl, read_or_create_number};
#[tauri::command] #[tauri::command]
async fn update_input( async fn update_input(
input: String, input: String,
new_tab: bool,
state: tauri::State<'_, Mutex<VigiState>>, state: tauri::State<'_, Mutex<VigiState>>,
) -> Result<(), VigiError> { ) -> Result<(), VigiError> {
state.lock().await.update_input(input); state.lock().await.update_input(input, new_tab).await?;
Ok(()) Ok(())
} }

View file

@ -4,13 +4,11 @@ use tokio_rustls::rustls::{
}; };
/// TODO: update to secure version when supported /// TODO: update to secure version when supported
pub fn insecure_gemini_client() -> tokio_gemini::Client { pub fn insecure_gemini_client_config() -> ClientConfig {
tokio_gemini::Client::from(
ClientConfig::builder() ClientConfig::builder()
.dangerous() .dangerous()
.with_custom_certificate_verifier(std::sync::Arc::new(NoCertVerification {})) .with_custom_certificate_verifier(std::sync::Arc::new(NoCertVerification {}))
.with_no_client_auth(), .with_no_client_auth()
)
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -1,11 +1,11 @@
use crate::types::VigiError;
use bytes::Bytes; use bytes::Bytes;
use insecure_gemini_client::insecure_gemini_client_config;
use mime::Mime; use mime::Mime;
use reqwest::header::CONTENT_TYPE; use reqwest::header::CONTENT_TYPE;
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
use url::Url; use url::Url;
use crate::types::VigiError;
use super::{insecure_gemini_client, ReqResult}; use super::{insecure_gemini_client, ReqResult};
pub async fn process_url(url: Url) -> Result<ReqResult, VigiError> { pub async fn process_url(url: Url) -> Result<ReqResult, VigiError> {
@ -40,7 +40,7 @@ async fn process_http(url: String) -> Result<ReqResult, VigiError> {
} }
async fn process_gemini(url: String) -> Result<ReqResult, VigiError> { async fn process_gemini(url: String) -> Result<ReqResult, VigiError> {
let mut res = insecure_gemini_client::insecure_gemini_client() let mut res = tokio_gemini::Client::from(insecure_gemini_client_config())
.request(&url) .request(&url)
.await .await
.map_err(|_| VigiError::Network)?; .map_err(|_| VigiError::Network)?;

View file

@ -150,8 +150,14 @@ impl VigiState {
Ok(()) Ok(())
} }
pub fn update_input(&mut self, input: String) { pub async fn update_input(&mut self, input: String, new_tab: bool) -> Result<(), VigiError> {
if new_tab {
self.add_tab().await?;
}
self.top_bar_input = input; self.top_bar_input = input;
Ok(())
} }
pub async fn load_input_force(&mut self) -> Result<(), VigiError> { pub async fn load_input_force(&mut self) -> Result<(), VigiError> {

View file

@ -1,40 +1,17 @@
<script lang="ts"> <script lang="ts">
import type { Root } from "@txtdot/dalet";
import Block from "./Block.svelte"; import Block from "./Block.svelte";
import Renderer from "./DaletlRenderer/Renderer.svelte"; import Renderer from "./DaletlRenderer/Renderer.svelte";
import { isLoading, state } from "$lib/stores"; import { isLoading, state } from "$lib/stores";
import type { VigiState } from "$lib/types";
import GooLoadSpin from "$lib/icons/GooLoadSpin.svelte"; import GooLoadSpin from "$lib/icons/GooLoadSpin.svelte";
import { slide } from "svelte/transition"; import { slide } from "svelte/transition";
let loading = false;
let data: Root;
let tabId = 0;
state.subscribe((st) => {
data = (st as VigiState).current_data;
console.log("ada");
if (!loading) {
tabId = (st as VigiState).current_tab_index;
}
});
isLoading.subscribe((val) => {
loading = val;
if (loading) {
tabId = -1;
}
});
</script> </script>
<Block className="browser-window"> <Block className="browser-window">
{#if loading} {#if $isLoading}
<div transition:slide> <div transition:slide>
<GooLoadSpin /> <GooLoadSpin />
</div> </div>
{/if} {/if}
<Renderer {data} /> <Renderer />
</Block> </Block>

View file

@ -1,10 +1,12 @@
<script lang="ts"> <script lang="ts">
import type { Root } from "@txtdot/dalet";
import TagRenderer from "./TagRenderer.svelte"; import TagRenderer from "./TagRenderer.svelte";
import { state } from "$lib/stores";
export let data: Root = []; import ToTopScroller from "../ToTopScroller.svelte";
</script> </script>
{#each data as tag} {#each $state.current_data as tag, i}
{#if i === 0}
<ToTopScroller />
{/if}
<TagRenderer {tag} /> <TagRenderer {tag} />
{/each} {/each}

View file

@ -1,10 +1,15 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte"; import BodyRenderer from "../BodyRenderer.svelte";
import { goToLink } from "$lib/utils";
export let tag: Tag; export let tag: Tag;
function goTo() {
goToLink(tag.argument as string, true);
}
</script> </script>
<button class="btn"> <button class="btn" on:click={goTo}>
<BodyRenderer body={tag.body} ifNull={tag.argument} /> <BodyRenderer body={tag.body} ifNull={tag.argument} />
</button> </button>

View file

@ -1,11 +1,9 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte";
export let tag: Tag; export let tag: Tag;
export let body = tag.body as string;
export let argument = tag.argument as string | undefined;
</script> </script>
<pre class={`pre code${argument ? ` lang-${argument}` : ""}`}><code>{body}</code <pre class={`pre code${tag.argument ? ` lang-${tag.argument}` : ""}`}><code
>{tag.body}</code
></pre> ></pre>

View file

@ -1,23 +1,19 @@
<script lang="ts"> <script lang="ts">
import type { Argument, Body, Tag } from "@txtdot/dalet"; import type { Argument, Body, Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte";
export let tag: Tag; export let tag: Tag;
let body = tag.body as string;
let argument = tag.argument as number | null;
</script> </script>
{#if argument === 2} {#if tag.argument === 2}
<h2 class="h2">{body}</h2> <h2 class="h2">{tag.body}</h2>
{:else if argument === 3} {:else if tag.argument === 3}
<h3 class="h3">{body}</h3> <h3 class="h3">{tag.body}</h3>
{:else if argument === 4} {:else if tag.argument === 4}
<h4 class="h4">{body}</h4> <h4 class="h4">{tag.body}</h4>
{:else if argument === 5} {:else if tag.argument === 5}
<h5 class="h5">{body}</h5> <h5 class="h5">{tag.body}</h5>
{:else if argument === 6} {:else if tag.argument === 6}
<h6 class="h6">{body}</h6> <h6 class="h6">{tag.body}</h6>
{:else} {:else}
<h1 class="h1">{body}</h1> <h1 class="h1">{tag.body}</h1>
{/if} {/if}

View file

@ -1,10 +1,15 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte"; import BodyRenderer from "../BodyRenderer.svelte";
import { goToLink } from "$lib/utils";
export let tag: Tag; export let tag: Tag;
function goTo() {
goToLink(tag.argument as string, true);
}
</script> </script>
<button class="link"> <button class="link" on:click={goTo}>
<BodyRenderer body={tag.body} ifNull={tag.argument} /> <BodyRenderer body={tag.body} ifNull={tag.argument} />
</button> </button>

View file

@ -1,10 +1,15 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte"; import BodyRenderer from "../BodyRenderer.svelte";
import { goToLink } from "$lib/utils";
export let tag: Tag; export let tag: Tag;
function goTo() {
goToLink(tag.argument as string);
}
</script> </script>
<button class="navbtn"> <button class="navbtn" on:click={goTo}>
<BodyRenderer body={tag.body} ifNull={tag.argument} /> <BodyRenderer body={tag.body} ifNull={tag.argument} />
</button> </button>

View file

@ -1,10 +1,15 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte"; import BodyRenderer from "../BodyRenderer.svelte";
import { goToLink } from "$lib/utils";
export let tag: Tag; export let tag: Tag;
function goTo() {
goToLink(tag.argument as string);
}
</script> </script>
<button class="navlink"> <button class="navlink" on:click={goTo}>
<BodyRenderer body={tag.body} ifNull={tag.argument} /> <BodyRenderer body={tag.body} ifNull={tag.argument} />
</button> </button>

View file

@ -1,9 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte";
export let tag: Tag; export let tag: Tag;
export let body = tag.body as string;
</script> </script>
<pre class="pre">{body}</pre> <pre class="pre">{tag.body}</pre>

View file

@ -1,11 +1,11 @@
<script lang="ts"> <script lang="ts">
import type { Tag } from "@txtdot/dalet"; import type { Tag } from "@txtdot/dalet";
import BodyRenderer from "../BodyRenderer.svelte";
import TagRenderer from "../TagRenderer.svelte"; import TagRenderer from "../TagRenderer.svelte";
export let tag: Tag; export let tag: Tag;
let body = tag.body as Tag[]; let body = tag.body as Tag[];
$: body = tag.body as Tag[];
</script> </script>
<ul class="ul"> <ul class="ul">

View file

@ -14,11 +14,6 @@
let tabElement: HTMLButtonElement; let tabElement: HTMLButtonElement;
let hovered = false; let hovered = false;
let loading = false;
isLoading.subscribe((val) => {
loading = val;
});
</script> </script>
<div <div
@ -39,7 +34,7 @@
{/if} {/if}
<button <button
class={`tab${loading && active ? " loading" : ""}`} class={`tab${$isLoading && active ? " loading" : ""}`}
class:active class:active
transition:slide={{ duration: 100 }} transition:slide={{ duration: 100 }}
bind:this={tabElement} bind:this={tabElement}
@ -49,14 +44,8 @@
} }
}} }}
> >
<!-- <div class="static right-0">
{#if loading && active}
<GooLoad />
{/if}
</div> -->
<div> <div>
{tab.title} {tab.title || tab.url}
</div> </div>
</button> </button>
</div> </div>

View file

@ -0,0 +1,7 @@
<script lang="ts">
import { onMount } from "svelte";
onMount(() => {
document.getElementsByClassName("browser-window")[0]?.scrollTo(0, 0);
});
</script>

View file

@ -1,30 +1,20 @@
import { invoke } from "@tauri-apps/api"; import { invoke as inv } from "@tauri-apps/api";
import { isLoading, state } from "./stores"; import { isLoading, state } from "./stores";
import type { VigiState } from "./types"; import type { VigiState } from "./types";
import { get } from "svelte/store";
import type { InvokeArgs } from "@tauri-apps/api/tauri";
export async function updateVigiState() { export async function updateVigiState() {
try {
let st = await invoke("get_js_state"); let st = await invoke("get_js_state");
state.set(st as VigiState); state.set(st as VigiState);
} catch (e) {
writeError(e);
}
} }
export async function updateAndLoadInput(input: string) { export async function updateAndLoadInput(input: string, newTab?: boolean) {
await invoke("update_input", { input }); await invoke("update_input", { input, newTab: !!newTab });
await updateVigiState(); await updateVigiState();
isLoading.set(true);
try {
await invoke("load_input_force"); await invoke("load_input_force");
await updateVigiState(); await updateVigiState();
} catch (e) {
writeError(e, input);
} finally {
isLoading.set(false);
}
} }
export async function addTab() { export async function addTab() {
@ -45,16 +35,14 @@ export async function removeTab(index: number) {
} }
export async function loadInput() { export async function loadInput() {
isLoading.set(true);
try {
await invoke("load_input"); await invoke("load_input");
await updateVigiState(); await updateVigiState();
} catch (e) {
writeError(e);
} finally {
isLoading.set(false);
} }
export async function goToLink(link: string, newTab?: boolean) {
const top_bar_input = get(state).top_bar_input;
const new_input = new URL(link, top_bar_input);
await updateAndLoadInput(new_input.toString(), newTab);
} }
function writeError(e: unknown, input?: string) { function writeError(e: unknown, input?: string) {
@ -66,3 +54,16 @@ function writeError(e: unknown, input?: string) {
return st; return st;
}); });
} }
export async function invoke(f: string, args?: InvokeArgs): Promise<unknown> {
isLoading.set(true);
try {
let result = await inv(f, args);
isLoading.set(false);
return result;
} catch (e) {
writeError(e);
isLoading.set(false);
throw new Error("Invoke failed");
}
}

View file

@ -5,18 +5,16 @@
import Sidebar from "$lib/components/Sidebar.svelte"; import Sidebar from "$lib/components/Sidebar.svelte";
import BrowserWindow from "$lib/components/BrowserWindow.svelte"; import BrowserWindow from "$lib/components/BrowserWindow.svelte";
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "$lib/utils";
import { loadInput, updateVigiState } from "$lib/utils"; import { loadInput, updateVigiState } from "$lib/utils";
import { isLoading } from "$lib/stores"; import { isLoading } from "$lib/stores";
let sidebarOpen = true; let sidebarOpen = true;
(async () => { (async () => {
isLoading.set(true);
await invoke("setup"); await invoke("setup");
await updateVigiState(); await updateVigiState();
await loadInput(); await loadInput();
isLoading.set(false);
})(); })();
document.addEventListener("keypress", (e: KeyboardEvent) => { document.addEventListener("keypress", (e: KeyboardEvent) => {