Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 78 additions & 64 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
anyhow = "1.0.89"
chrono = "0.4.38"
constcat = "0.5.1"
cosmic-time = { git = "https://github.com/pop-os/cosmic-time.git", version = "0.4.0", features = ["once_cell"] }
directories = "5.0.1"
env_logger = "0.11.5"
futures = "0.3.31"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Dependencies (Linux):

Dependencies (macOS):

- `brew`
- `cargo`
- `just`
- `libxkbcommon`
Expand Down
1 change: 1 addition & 0 deletions i18n/en/cosmicding.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enabled-public-sharing = Public bookmarks sharing enabled
enabled-sharing = Bookmarks sharing enabled
failed = failed
failed-refreshing-accounts = Failed refreshing some accounts ({$accounts})
failed-refreshing-all-accounts = Failed refreshing all accounts
failed-refreshing-bookmarks-for-account = Failed refreshing account {$account}
failed-to-add-account = Failed to add account {$acc}: {$err}
failed-to-edit-account = Failed to edit account {$acc}: {$err}
Expand Down
1 change: 1 addition & 0 deletions i18n/sv/cosmicding.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enabled-public-sharing = Delning av offentliga bokmärken har aktiverats
enabled-sharing = Bokmärkesdelning har aktiverats
failed = misslyckades
failed-refreshing-accounts = Misslyckades att uppdatera vissa konton ({$accounts})
failed-refreshing-all-accounts = Misslyckades med att uppdatera alla konton
failed-refreshing-bookmarks-for-account = Misslyckades att uppdatera konto {$account}
failed-to-add-account = Misslyckades med att lägga till konto {$acc}: {$err}
failed-to-edit-account = Misslyckades med att redigera konto {$acc}: {$err}
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ build-release *args:
if [ "$(uname)" = "Linux" ]; then
just build-release-linux
elif [ "$(uname)" = "Darwin" ]; then
export HOMEBREW_PREFIX="$(brew --prefix)"
export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/lib/pkgconfig"
export LIBRARY_PATH="${HOMEBREW_PREFIX}/lib"
export C_INCLUDE_PATH="${HOMEBREW_PREFIX}/include"
if [ "$(uname -m)" = "arm64" ]; then
just build-release-macos-aarch64
elif [ "$(uname -m)" = "x86_64" ]; then
Expand Down
103 changes: 71 additions & 32 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
use crate::db::{self};
use crate::fl;
use crate::http::{self};
use crate::models::account::{Account, LinkdingAccountApiResponse};
use crate::models::bookmarks::{
Bookmark, BookmarkCheckDetailsResponse, BookmarkRemoveResponse, DetailedResponse,
};
use crate::models::db_cursor::{AccountsPaginationCursor, BookmarksPaginationCursor, Pagination};
use crate::pages::accounts::{add_account, edit_account, PageAccountsView};
use crate::pages::bookmarks::{edit_bookmark, new_bookmark, view_notes, PageBookmarksView};
use crate::{
app::{
actions::ApplicationAction,
Expand All @@ -17,29 +7,52 @@ use crate::{
menu as app_menu,
nav::AppNavPage,
},
models::favicon_cache::Favicon,
};
use cosmic::cosmic_config::{self, Update};
use cosmic::cosmic_theme::{self, ThemeMode};
use cosmic::iced::{
event,
futures::executor::block_on,
keyboard::{Event as KeyEvent, Modifiers},
Event, Length, Subscription,
db::{self},
fl,
http::{self},
models::{
account::{Account, LinkdingAccountApiResponse},
bookmarks::{
Bookmark, BookmarkCheckDetailsResponse, BookmarkRemoveResponse, DetailedResponse,
},
db_cursor::{AccountsPaginationCursor, BookmarksPaginationCursor, Pagination},
favicon_cache::Favicon,
sync_status::SyncStatus,
},
pages::{
accounts::{add_account, edit_account, PageAccountsView},
bookmarks::{edit_bookmark, new_bookmark, view_notes, PageBookmarksView},
},
style::animation::refresh,
};
use cosmic::iced_core::image::Bytes;
use cosmic::iced_widget::tooltip;
use cosmic::widget::menu::key_bind::KeyBind;
use cosmic::widget::{self, about::About, icon, nav_bar};
use cosmic::{
app::{context_drawer, Core, Task},
widget::menu::Action,
cosmic_config::{self, Update},
cosmic_theme::{self, ThemeMode},
iced::{
event,
futures::executor::block_on,
keyboard::{Event as KeyEvent, Modifiers},
Event, Length, Subscription,
},
iced_core::image::Bytes,
iced_widget::tooltip,
widget::{
self,
about::About,
icon,
menu::{key_bind::KeyBind, Action},
nav_bar,
},
Application, ApplicationExt, Element,
};
use cosmic::{Application, ApplicationExt, Element};
use cosmic_time::{chain, Timeline};
use key_bind::key_binds;
use std::any::TypeId;
use std::collections::{HashMap, VecDeque};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::{
any::TypeId,
collections::{HashMap, VecDeque},
time::{Duration, SystemTime, UNIX_EPOCH},
};

pub mod actions;
pub mod config;
Expand All @@ -56,6 +69,9 @@ pub const APPID: &str = constcat::concat!(QUALIFIER, ".", ORG, ".", APP);

const REPOSITORY: &str = "https://github.com/vkhitrin/cosmicding";

pub static REFRESH_ICON: std::sync::LazyLock<refresh::Id> =
std::sync::LazyLock::new(refresh::Id::unique);

pub struct Flags {
pub config_handler: Option<cosmic_config::Config>,
pub config: CosmicConfig,
Expand Down Expand Up @@ -84,6 +100,8 @@ pub struct Cosmicding {
pub config: CosmicConfig,
pub state: ApplicationState,
search_id: widget::Id,
timeline: Timeline,
sync_status: SyncStatus,
toasts: widget::toaster::Toasts<ApplicationAction>,
}

Expand Down Expand Up @@ -113,6 +131,7 @@ impl Application for Cosmicding {
}

fn init(core: Core, flags: Self::Flags) -> (Self, Task<Self::Message>) {
let timeline = Timeline::new();
let db_pool = Some(block_on(async {
db::SqliteDatabase::create().await.unwrap()
}));
Expand Down Expand Up @@ -181,6 +200,8 @@ impl Application for Cosmicding {
placeholder_selected_account_index: 0,
state: ApplicationState::NoEnabledAccounts,
search_id: widget::Id::unique(),
timeline,
sync_status: SyncStatus::default(),
toasts: widget::toaster::Toasts::new(ApplicationAction::CloseToast),
};

Expand All @@ -200,6 +221,7 @@ impl Application for Cosmicding {
tokio::runtime::Runtime::new().unwrap().block_on(async {
app.bookmarks_cursor.refresh_count().await;
});
app.timeline.set_chain(chain![REFRESH_ICON]).start();

(app, Task::batch(commands))
}
Expand Down Expand Up @@ -385,8 +407,12 @@ impl Application for Cosmicding {
}
ApplicationAction::SystemThemeModeChange
}),
// NOTE: (vkhitrin) native implementation is too resource heavy.
// self.timeline
// .as_subscription()
// .map(|(_id, instant)| ApplicationAction::Tick(instant)),
cosmic::iced::time::every(Duration::from_millis(250)).map(ApplicationAction::Tick),
];

Subscription::batch(subscriptions)
}

Expand Down Expand Up @@ -453,15 +479,16 @@ impl Application for Cosmicding {
let account_page_entity = &self.nav.entity_at(0);
self.nav.activate(account_page_entity.unwrap());
}

ApplicationAction::Tick(now) => {
self.timeline.now(now);
}
ApplicationAction::ToggleContextPage(context_page) => {
if self.context_page == context_page {
self.core.window.show_context = !self.core.window.show_context;
} else {
self.context_page = context_page;
self.core.window.show_context = true;
}
//self.set_context_title(context_page.title());
}
ApplicationAction::ContextClose => self.core.window.show_context = false,
ApplicationAction::AccountsView(message) => {
Expand Down Expand Up @@ -710,7 +737,7 @@ impl Application for Cosmicding {
ApplicationAction::DoneRefreshBookmarksForAllAccounts(remote_responses) => {
let mut failed_accounts: Vec<String> = Vec::new();
if let Some(ref mut database) = &mut self.bookmarks_cursor.database {
for response in remote_responses {
for response in remote_responses.iter().cloned() {
if !response.successful {
failed_accounts.push(response.account.display_name.clone());
}
Expand All @@ -729,12 +756,23 @@ impl Application for Cosmicding {
commands.push(self.update(ApplicationAction::LoadBookmarks));
self.state = ApplicationState::Ready;
if failed_accounts.is_empty() {
self.sync_status = SyncStatus::Successful;
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::Action::App),
);
} else if remote_responses.len() == failed_accounts.len() {
self.sync_status = SyncStatus::Failed;
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!(
"failed-refreshing-all-accounts"
)))
.map(cosmic::Action::App),
);
} else {
self.sync_status = SyncStatus::Warning;
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!(
Expand Down Expand Up @@ -844,6 +882,7 @@ impl Application for Cosmicding {
}
}
self.state = ApplicationState::Loading;
self.sync_status = SyncStatus::InProgress;
}
}
ApplicationAction::AddBookmarkForm => {
Expand Down
11 changes: 8 additions & 3 deletions src/app/actions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::models::account::{Account, LinkdingAccountApiResponse};
use crate::models::bookmarks::{Bookmark, BookmarkRemoveResponse, DetailedResponse};
use crate::models::{
account::{Account, LinkdingAccountApiResponse},
bookmarks::{Bookmark, BookmarkRemoveResponse, DetailedResponse},
};
use crate::{
app::{
config::{AppTheme, CosmicConfig, SortOption},
Expand All @@ -8,12 +10,14 @@ use crate::{
},
models::bookmarks::BookmarkCheckDetailsResponse,
};
use cosmic::widget::{self};
use cosmic::{
iced::keyboard::{Key, Modifiers},
iced_core::image::Bytes,
widget::{self},
};

use std::time::Instant;

#[derive(Debug, Clone)]
pub enum ApplicationAction {
AccountsView(AccountsAction),
Expand Down Expand Up @@ -81,6 +85,7 @@ pub enum ApplicationAction {
StartRemoveBookmark(i64, Bookmark),
StartupCompleted,
SystemThemeModeChange,
Tick(Instant),
ToggleContextPage(ContextPage),
UpdateConfig(CosmicConfig),
ViewBookmarkNotes(Bookmark),
Expand Down
3 changes: 1 addition & 2 deletions src/app/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::models::account::Account;
use crate::models::bookmarks::Bookmark;
use crate::models::{account::Account, bookmarks::Bookmark};
#[derive(Clone, Debug, Eq, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum DialogPage {
Expand Down
7 changes: 4 additions & 3 deletions src/app/key_bind.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::collections::HashMap;

use cosmic::iced::keyboard::Key;
use cosmic::widget::menu::key_bind::KeyBind;
use cosmic::widget::menu::key_bind::Modifier;
use cosmic::{
iced::keyboard::Key,
widget::menu::key_bind::{KeyBind, Modifier},
};

use crate::app::menu::MenuAction;

Expand Down
8 changes: 5 additions & 3 deletions src/app/menu.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::collections::HashMap;

use crate::app::config::SortOption;
use cosmic::widget::RcElementWrapper;
use cosmic::{
widget::menu::{
self, action::MenuAction as _MenuAction, key_bind::KeyBind, Item, ItemHeight, ItemWidth,
widget::{
menu::{
self, action::MenuAction as _MenuAction, key_bind::KeyBind, Item, ItemHeight, ItemWidth,
},
RcElementWrapper,
},
Element,
};
Expand Down
9 changes: 8 additions & 1 deletion src/app/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ impl AppNavPage {
match self {
AppNavPage::AccountsView => app
.accounts_view
.view(app.state, &app.accounts_cursor)
.view(
app.state,
app.sync_status,
&app.accounts_cursor,
&app.timeline,
)
.map(ApplicationAction::AccountsView),
AppNavPage::BookmarksView => app
.bookmarks_view
.view(
app.state,
app.sync_status,
&app.bookmarks_cursor,
app.accounts_cursor.total_entries == 0,
&app.timeline,
)
.map(ApplicationAction::BookmarksView),
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn settings() -> cosmic::app::Settings {
.min_width(360.0)
.min_height(180.0),
)
// NOTE: An example of client decorations enabled.
// NOTE: (vkhitrin) An example of client decorations enabled.
// Useless as long as we render the native
// libcosmic menu
// #[cfg(target_os = "macos")]
Expand Down
13 changes: 5 additions & 8 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use crate::app::config::SortOption;
use crate::models::favicon_cache::Favicon;
use crate::{
app::{config::SortOption, APP, APPID, ORG, QUALIFIER},
models::{account::Account, bookmarks::Bookmark, favicon_cache::Favicon},
};
use anyhow::{anyhow, Result};

use std::path::Path;

use sqlx::sqlite::Sqlite;
use sqlx::{migrate::MigrateDatabase, prelude::*, SqlitePool};

use crate::app::{APP, APPID, ORG, QUALIFIER};
use crate::models::account::Account;
use crate::models::bookmarks::Bookmark;
use sqlx::{migrate::MigrateDatabase, prelude::*, sqlite::Sqlite, SqlitePool};

const DB_PATH: &str = constcat::concat!(APPID, "-db", ".sqlite");

Expand Down
Loading
Loading