Skip to content

Commit

Permalink
feat: favorite impl
Browse files Browse the repository at this point in the history
* first impl

* hum

* Update db.rs

* Update db.rs

* fix test

* impl UI

* Update db.rs

* Update justfile
  • Loading branch information
wiiznokes authored Sep 29, 2024
1 parent dd49980 commit b60ffbc
Show file tree
Hide file tree
Showing 15 changed files with 562 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[env]
RUST_LOG = "warn,cosmic_ext_applet_clipboard_manager=debug"
RUST_BACKTRACE = "full"
# RUST_BACKTRACE = "full"

20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tracing-journald = "0.3"
constcat = "0.5"
nucleo = "0.5"
futures = "0.3"
include_dir = "0.7.4"

[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic"
Expand Down
4 changes: 3 additions & 1 deletion i18n/en/cosmic_ext_applet_clipboard_manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ clear_entries = Clear
show_qr_code = Show QR code
return_to_clipboard = Return to clipboard
qr_code_error = Error while generating the QR code
horizontal_layout = Horizontal
horizontal_layout = Horizontal
add_favorite = Add Favorite
remove_favorite = Remove Favorite
4 changes: 3 additions & 1 deletion i18n/fr/cosmic_ext_applet_clipboard_manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ clear_entries = Nettoyer
show_qr_code = Afficher le code QR
return_to_clipboard = Retourner au presse-papier
qr_code_error = Erreur pendant la génération du code QR
horizontal_layout = Horizontal
horizontal_layout = Horizontal
add_favorite = Ajouter aux Favoris
remove_favorite = Retirer des Favoris
12 changes: 1 addition & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ bin-dst := base-dir / 'bin' / NAME
desktop-dst := share-dst / 'applications' / APPID + '.desktop'
icon-dst := share-dst / 'icons/hicolor/scalable/apps' / APPID + '-symbolic.svg'
env-dst := rootdir / 'etc/profile.d' / NAME + '.sh'
migrations-dst := share-dst / NAME / 'migrations'


default: build-release

Expand All @@ -27,26 +25,18 @@ build-debug *args:
build-release *args:
cargo build --release {{args}}

install: install-migrations
install:
install -Dm0755 {{bin-src}} {{bin-dst}}
install -Dm0644 res/desktop_entry.desktop {{desktop-dst}}
install -Dm0644 res/app_icon.svg {{icon-dst}}
install -Dm0644 res/env.sh {{env-dst}}

install-migrations:
#!/usr/bin/env sh
set -ex
for file in ./migrations/*; do
install -Dm0644 $file "{{migrations-dst}}/$(basename "$file")"
done

uninstall:
rm {{bin-dst}}
rm {{desktop-dst}}
rm {{icon-dst}}
rm {{env-dst}}
rm -r {{share-dst}}/{{NAME}}

clean:
cargo clean
Expand Down
7 changes: 7 additions & 0 deletions migrations/20240929151638_favorite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS FavoriteClipboardEntries (
id INTEGER PRIMARY KEY,
position INTEGER NOT NULL,
FOREIGN KEY (id) REFERENCES ClipboardEntries(creation) ON DELETE CASCADE,
-- UNIQUE (position),
CHECK (position >= 0)
);
1 change: 1 addition & 0 deletions res/icons/star24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icons/star_fill24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ impl cosmic::Application for AppState {
config_set!(horizontal, horizontal);
}
},
AppMsg::AddFavorite(entry) => {
block_on(async {
if let Err(err) = self.db.add_favorite(&entry, None).await {
error!("{err}");
}
});
}
AppMsg::RemoveFavorite(entry) => {
block_on(async {
if let Err(err) = self.db.remove_favorite(&entry).await {
error!("{err}");
}
});
}
}
Command::none()
}
Expand Down
2 changes: 1 addition & 1 deletion src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn sub() -> Subscription<ClipboardMessage> {
None
};

let data = Entry::new_now(mime_type, contents, metadata);
let data = Entry::new_now(mime_type, contents, metadata, false);

info!("sending data to database: {:?}", data);
output.send(ClipboardMessage::Data(data)).await.unwrap();
Expand Down
Loading

0 comments on commit b60ffbc

Please sign in to comment.