Skip to content

Commit

Permalink
chore: update libcosmic
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Nov 18, 2024
1 parent 07d4fec commit 00400b3
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 51 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ thiserror = "1.0.65"
[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic.git"
default-features = false
features = ["multi-window", "tokio", "winit", "wgpu", "desktop"]
features = ["multi-window", "tokio", "winit", "wgpu", "about"]

[dependencies.i18n-embed]
version = "0.14"
Expand Down
40 changes: 26 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::core::models::Task;
use crate::core::service::{Provider, TaskService};
use chrono::{Local, NaiveDate};
use cli_clipboard::{ClipboardContext, ClipboardProvider};
use cosmic::app::context_drawer::ContextDrawer;
use cosmic::app::{message, Core, Message as CosmicMessage};
use cosmic::cosmic_config::Update;
use cosmic::cosmic_theme::ThemeMode;
Expand Down Expand Up @@ -62,6 +63,7 @@ pub enum Message {
ToggleContextPage(ContextPage),
Application(ApplicationAction),
Open(String),
ToggleContextDrawer,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -272,15 +274,24 @@ impl Application for Tasks {
(app, app::Task::batch(tasks))
}

fn context_drawer(&self) -> Option<Element<Message>> {
fn context_drawer(&self) -> Option<ContextDrawer<Self::Message>> {
if !self.core.window.show_context {
return None;
}

Some(match self.context_page {
ContextPage::About => widget::about(&self.about, Message::Open),
ContextPage::Settings => self.settings(),
ContextPage::TaskDetails => self.details.view().map(Message::Details),
ContextPage::About => {
app::context_drawer::about(&self.about, Message::Open, Message::ToggleContextDrawer)
}
ContextPage::Settings => {
app::context_drawer::context_drawer(self.settings(), Message::ToggleContextDrawer)
.title(self.context_page.title())
}
ContextPage::TaskDetails => app::context_drawer::context_drawer(
self.details.view().map(Message::Details),
Message::ToggleContextDrawer,
)
.title(self.context_page.title()),
})
}

Expand Down Expand Up @@ -375,7 +386,7 @@ impl Application for Tasks {
match content_task {
content::Task::Focus(id) => tasks
.push(self.update(Message::Application(ApplicationAction::Focus(id)))),
content::Task::GetTasks(list_id) => {
content::Task::Get(list_id) => {
tasks.push(app::Task::perform(
todo::fetch_tasks(list_id, self.service.clone()),
|result| match result {
Expand All @@ -386,7 +397,7 @@ impl Application for Tasks {
},
));
}
content::Task::DisplayTask(task) => {
content::Task::Display(task) => {
let entity =
self.details.priority_model.entity_at(task.priority as u16);
if let Some(entity) = entity {
Expand All @@ -407,7 +418,7 @@ impl Application for Tasks {
self.update(Message::ToggleContextPage(ContextPage::TaskDetails)),
);
}
content::Task::UpdateTask(task) => {
content::Task::Update(task) => {
self.details.task = Some(task.clone());
let task = app::Task::perform(
todo::update_task(task, self.service.clone().clone()),
Expand All @@ -432,7 +443,7 @@ impl Application for Tasks {
tasks.push(task);
}
}
content::Task::CreateTask(task) => {
content::Task::Create(task) => {
let task = app::Task::perform(
todo::create_task(task, self.service.clone()),
|result| match result {
Expand All @@ -453,7 +464,7 @@ impl Application for Tasks {
let details_tasks = self.details.update(message);
for details_task in details_tasks {
match details_task {
details::Task::UpdateTask(task) => {
details::Task::Update(task) => {
tasks.push(self.update(Message::Content(
content::Message::UpdateTask(task.clone()),
)));
Expand All @@ -472,10 +483,12 @@ impl Application for Tasks {
if self.context_page == context_page {
self.core.window.show_context = !self.core.window.show_context;
} else {
self.context_page = context_page.clone();
self.context_page = context_page;
self.core.window.show_context = true;
}
self.set_context_title(context_page.clone().title());
}
Message::ToggleContextDrawer => {
self.core.window.show_context = !self.core.window.show_context
}
Message::Dialog(dialog_action) => match dialog_action {
DialogAction::Open(page) => {
Expand Down Expand Up @@ -752,8 +765,7 @@ impl Application for Tasks {
.id(self.dialog_text_input.clone())
.on_input(move |name| {
Message::Dialog(DialogAction::Update(DialogPage::Rename(
entity.clone(),
name,
*entity, name,
)))
})
.on_submit(Message::Dialog(DialogAction::Complete))
Expand Down Expand Up @@ -783,7 +795,7 @@ impl Application for Tasks {
.align_x(Horizontal::Center),
)
.on_press(Message::Dialog(DialogAction::Update(DialogPage::Icon(
entity.clone(),
*entity,
emoji.to_string(),
))))
.into()
Expand Down
24 changes: 12 additions & 12 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub enum Message {

pub enum Task {
Focus(widget::Id),
GetTasks(String),
DisplayTask(models::Task),
UpdateTask(models::Task),
Get(String),
Display(models::Task),
Update(models::Task),
Delete(String),
CreateTask(models::Task),
Create(models::Task),
Export(Vec<models::Task>),
}

Expand Down Expand Up @@ -186,11 +186,11 @@ impl Content {
match (&self.list, &list) {
(Some(current), Some(list)) => {
if current.id != list.id {
tasks.push(Task::GetTasks(list.id().clone()));
tasks.push(Task::Get(list.id().clone()));
}
}
(None, Some(list)) => {
tasks.push(Task::GetTasks(list.id().clone()));
tasks.push(Task::Get(list.id().clone()));
}
_ => {}
}
Expand All @@ -203,7 +203,7 @@ impl Content {
}
Message::TitleSubmit(id) => {
if let Some(task) = self.tasks.get(id) {
tasks.push(Task::UpdateTask(task.clone()));
tasks.push(Task::Update(task.clone()));
self.editing.insert(id, false);
}
}
Expand All @@ -217,7 +217,7 @@ impl Content {
if editing {
tasks.push(Task::Focus(self.task_input_ids[id].clone()));
} else if let Some(task) = self.tasks.get(id) {
tasks.push(Task::UpdateTask(task.clone()));
tasks.push(Task::Update(task.clone()));
}
}
Message::SetItems(tasks) => {
Expand All @@ -228,7 +228,7 @@ impl Content {
}
}
Message::Select(task) => {
tasks.push(Task::DisplayTask(task));
tasks.push(Task::Display(task));
}
Message::Complete(id, complete) => {
let task = self.tasks.get_mut(id);
Expand All @@ -238,15 +238,15 @@ impl Content {
} else {
Status::NotStarted
};
tasks.push(Task::UpdateTask(task.clone()));
tasks.push(Task::Update(task.clone()));
}
}
Message::Input(input) => self.input = input,
Message::AddTask => {
if let Some(list) = &self.list {
if !self.input.is_empty() {
let task = models::Task::new(self.input.clone(), list.id().clone());
tasks.push(Task::CreateTask(task.clone()));
tasks.push(Task::Create(task.clone()));
let id = self.tasks.insert(task);
self.task_input_ids.insert(id, widget::Id::unique());
self.input.clear();
Expand All @@ -260,7 +260,7 @@ impl Content {
.find(|t| t.id() == updated_task.id());
if let Some(task) = task {
*task = updated_task.clone();
tasks.push(Task::UpdateTask(task.clone()));
tasks.push(Task::Update(task.clone()));
}
}
Message::Export(exported_tasks) => {
Expand Down
6 changes: 3 additions & 3 deletions src/core/service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::Path;

use crate::Error;
use chrono::NaiveDateTime;
Expand Down Expand Up @@ -82,7 +82,7 @@ impl TaskService {

use sqlx::Row;

async fn get_tasks(database_path: &PathBuf) -> Result<Vec<Task>, Error> {
async fn get_tasks(database_path: &Path) -> Result<Vec<Task>, Error> {
let mut conn = sqlx::SqliteConnection::connect(database_path.to_str().unwrap()).await?;
let tasks = sqlx::query("SELECT * FROM tasks")
.map(|row: SqliteRow| Task {
Expand Down Expand Up @@ -124,7 +124,7 @@ async fn get_tasks(database_path: &PathBuf) -> Result<Vec<Task>, Error> {
Ok(tasks)
}

async fn get_lists(database_path: &PathBuf) -> Result<Vec<List>, Error> {
async fn get_lists(database_path: &Path) -> Result<Vec<List>, Error> {
let mut conn = sqlx::SqliteConnection::connect(database_path.to_str().unwrap()).await?;
let tasks = sqlx::query("SELECT * FROM lists")
.map(|row: SqliteRow| List {
Expand Down
6 changes: 3 additions & 3 deletions src/core/services/computer/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ impl ComputerStorageEngine {
std::fs::create_dir_all(&engine.path).ok()?;
}
if !engine.lists_path().exists() {
std::fs::create_dir_all(&engine.lists_path()).ok()?;
std::fs::create_dir_all(engine.lists_path()).ok()?;
}
if !engine.tasks_path().exists() {
std::fs::create_dir_all(&engine.tasks_path()).ok()?;
std::fs::create_dir_all(engine.tasks_path()).ok()?;
}
Some(engine)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ impl ComputerStorageEngine {
.join(&task.id)
.with_extension("ron");
if !path.exists() {
std::fs::create_dir_all(&self.tasks_path().join(&task.parent))?;
std::fs::create_dir_all(self.tasks_path().join(&task.parent))?;
let content = ron::to_string(&task)?;
std::fs::write(path, content)?;
Ok(task)
Expand Down
Loading

0 comments on commit 00400b3

Please sign in to comment.