Skip to content

Commit

Permalink
[*] improve ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Mar 21, 2024
1 parent 127d4bd commit 78a0b1a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 59 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@ crate-type = ["cdylib"]

[dependencies]
log = "0.4"
env_logger = "0.10"
chrono = "0.4"
anyhow = "1.0"
serde_json = "1.0"
lazy_static = "1.4"
clipboard = "0.5"
webbrowser = "0.8"
serde_json = "1.0"
lazy_static = "1.4"

uuid = { version = "1.6", features = ["v4"] }
tokio = {version = "1.35", features = ["full"]}
serde = { version = "1.0", features = ["serde_derive"] }

[target.'cfg(not(target_os = "android"))'.dependencies]
slint = "1.5"
env_logger = "0.10"
platform-dirs = "0.3"
reqwest = { version = "0.11", features = ["json", "socks"]}
slint = { version = "1.5", features = ["backend-android-activity-05"] }

[target.'cfg(target_os = "android")'.dependencies]
reqwest = { version = "0.11", features = ["rustls-tls", "native-tls-vendored", "json", "socks"]}
android_logger = "0.13"
slint = { version = "1.5", features = ["backend-android-activity-05"] }
reqwest = { version = "0.11", features = ["rustls-tls", "native-tls-vendored", "json", "socks"]}

[build-dependencies]
slint-build = "1.5"
cmd_lib = "1.9"
slint-build = "1.5"

[target.'cfg(target_os = "windows")'.build-dependencies]
embed-resource = "2.4"
Expand Down
45 changes: 30 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ mod logic;
mod util;
mod version;

use logic::{clipboard, message};

use anyhow::Result;

Check warning on line 13 in src/lib.rs

View workflow job for this annotation

GitHub Actions / action-run

unused import: `anyhow::Result`
use chrono::Local;
use env_logger::fmt::Color as LColor;
use std::io::Write;
use logic::{clipboard, message};

#[cfg(not(target_os = "android"))]
fn init_logger() {

Check warning on line 17 in src/lib.rs

View workflow job for this annotation

GitHub Actions / action-run

function `init_logger` is never used
use chrono::Local;
use env_logger::fmt::Color;
use std::io::Write;

env_logger::builder()
.format(|buf, record| {
let ts = Local::now().format("%Y-%m-%d %H:%M:%S");
let mut level_style = buf.style();
match record.level() {
log::Level::Warn | log::Level::Error => {
level_style.set_color(LColor::Red).set_bold(true)
level_style.set_color(Color::Red).set_bold(true)
}
_ => level_style.set_color(LColor::Blue).set_bold(true),
_ => level_style.set_color(Color::Blue).set_bold(true),
};

writeln!(
Expand All @@ -47,10 +48,22 @@ fn init_logger() {
.init();
}

async fn ui_before() -> Result<()> {
#[cfg(target_os = "android")]
fn init_logger() {
android_logger::init_once(
android_logger::Config::default()
.with_max_level(log::LevelFilter::Trace)
.with_filter(
android_logger::FilterBuilder::new()
.filter_level(log::LevelFilter::Debug)
.build(),
),
);
}

fn ui_before() {

Check warning on line 64 in src/lib.rs

View workflow job for this annotation

GitHub Actions / action-run

function `ui_before` is never used
init_logger();
config::init();
Ok(())
}

fn ui_after(ui: &AppWindow) {

Check warning on line 69 in src/lib.rs

View workflow job for this annotation

GitHub Actions / action-run

function `ui_after` is never used
Expand All @@ -61,26 +74,28 @@ fn ui_after(ui: &AppWindow) {

#[cfg(not(target_os = "android"))]
#[tokio::main]
async fn main() -> Result<()> {
async fn main() {

Check warning on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / action-run

function `main` is never used
log::debug!("start...");

ui_before().await?;
let ui = AppWindow::new()?;
ui_before();
let ui = AppWindow::new().unwrap();
ui_after(&ui);
ui.run().unwrap();

log::debug!("exit...");
Ok(())
}

#[cfg(target_os = "android")]
#[no_mangle]
#[tokio::main]
async fn android_main(app: slint::android::AndroidApp) {
slint::android::init(app).unwrap();
log::debug!("start...");

ui_before().await.unwrap();
slint::android::init(app).unwrap();
ui_before();
let ui = AppWindow::new().unwrap();
ui_after(&ui);
ui.run().unwrap();

log::debug!("exit...");
}
54 changes: 16 additions & 38 deletions ui/appwindow.slint
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,30 @@ import { Message } from "./base/message.slint";
export component AppWindow inherits Window {
default-font-size: Theme.default-font-size;
default-font-family: Theme.default-font-family;
// width: Theme.default-width;
width: Theme.default-width;
// height: Theme.default-height;
background: Theme.base-background;
background: Theme.basic-black-color;
icon: @image-url("./images/icon.png");
title: "rssbox";

init => { }

fscope := FocusScope {
property <bool> is-ctrl-pressed: false;
key-pressed(event) => {
if (event.text == Key.Control) {
is-ctrl-pressed = true;
} else if (event.text == Key.Escape) {
modal.hide();
}

if (is-ctrl-pressed) {
if (event.text == ",") { }
}
accept
}

key-released(event) => {
if (event.text == Key.Control) {
is-ctrl-pressed = false;
}
accept
}

HorizontalLayout {
panel := Panel { }
}
Rectangle {
background: Theme.base-background;
panel := Panel { }
}

modal := Rectangle {
function hide() { }
}
modal := Rectangle {
function hide() { }
}

msg := Message {
x: root.width / 2 - self.width / 2;
y: 50px;
text: Store.message.text;
type: Store.message.text-type;
clicked => {
Logic.copy-to-clipboard(self.text);
}
msg := Message {
x: root.width / 2 - self.width / 2;
y: 50px;
text: Store.message.text;
type: Store.message.text-type;
clicked => {
Logic.copy-to-clipboard(self.text);
}
}
}
Expand Down

0 comments on commit 78a0b1a

Please sign in to comment.