Skip to content

OS Notifications #7399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2,356 changes: 1,375 additions & 981 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tauri-apps/plugin-fs": "^2.0.1",
"@tauri-apps/plugin-http": "^2.0.1",
"@tauri-apps/plugin-log": "^2.0.0",
"@tauri-apps/plugin-notification": "^2.2.1",
"@tauri-apps/plugin-os": "^2.0.0",
"@tauri-apps/plugin-process": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.1",
Expand Down Expand Up @@ -59,14 +60,14 @@
"jsdom": "^24.1.1",
"lexical": "0.17.0",
"lscache": "^1.3.2",
"marked": "catalog:",
"mocha": "^10.7.0",
"nanoevents": "^9.0.0",
"postcss": "^8.4.38",
"postcss-load-config": "^5.1.0",
"postcss-nesting": "^12.1.5",
"postcss-pxtorem": "^6.1.0",
"posthog-js": "1.136.4",
"marked": "catalog:",
"reflect-metadata": "^0.2.2",
"svelte": "catalog:svelte",
"svelte-check": "catalog:svelte",
Expand Down
24 changes: 24 additions & 0 deletions apps/desktop/src/lib/notifications/os.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
isPermissionGranted,
requestPermission,
sendNotification
} from '@tauri-apps/plugin-notification';

async function checkPermission() {
const permission = await isPermissionGranted();
if (!permission) {
const requestResponse = await requestPermission();
return requestResponse === 'granted';
}
return true;
}

export async function sendOSNotification(title: string, body: string) {
const canSendNotification = await checkPermission();
if (!canSendNotification) {
// Not an error, but maybe in the future we can log this?
return;
}

sendNotification({ title, body });
}
7 changes: 3 additions & 4 deletions crates/but-hunk-dependency/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::anyhow;
use but_core::TreeStatusKind;
use but_workspace::StackId;
use gix::bstr::BString;
Expand Down Expand Up @@ -50,9 +49,9 @@ pub struct InputDiffHunk {
impl InputDiffHunk {
/// Compute the amount of lines that are left when substracting old-lines from new-lines.
pub fn net_lines(&self) -> anyhow::Result<i32> {
self.new_lines
.checked_signed_diff(self.old_lines)
.ok_or(anyhow!("u32 -> i32 conversion overflow"))
let old_lines = i32::try_from(self.old_lines)?;
let new_lines = i32::try_from(self.new_lines)?;
Ok(new_lines - old_lines)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/but-hunk-dependency/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(unsigned_signed_diff)]
#![deny(missing_docs, rust_2018_idioms)]

//! ## Module Guidelines
Expand Down
18 changes: 9 additions & 9 deletions crates/but-hunk-dependency/tests/hunk_dependency/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn hunk_dependencies_json_sample() -> anyhow::Result<()> {
{
"diffs": [
[
3708607749576748282,
15989967088397270668,
[
{
"stackId": "stack_1",
Expand All @@ -18,7 +18,7 @@ fn hunk_dependencies_json_sample() -> anyhow::Result<()> {
]
],
[
2434601357784245452,
8240534308515296008,
[
{
"stackId": "stack_1",
Expand All @@ -35,7 +35,7 @@ fn hunk_dependencies_json_sample() -> anyhow::Result<()> {
]
],
[
16712260417274738957,
18120254504138851193,
[
{
"stackId": "stack_1",
Expand All @@ -58,7 +58,7 @@ fn complex_file_manipulation_with_uncommitted_changes() -> anyhow::Result<()> {
StableHunkDependencies {
diffs: [
(
15941114795339476802,
5660422847701176503,
[
HunkLock {
stack_id: stack_1,
Expand All @@ -67,7 +67,7 @@ fn complex_file_manipulation_with_uncommitted_changes() -> anyhow::Result<()> {
],
),
(
17676568081731369438,
6048968734524995517,
[
HunkLock {
stack_id: stack_1,
Expand All @@ -94,7 +94,7 @@ fn complex_file_manipulation_multiple_hunks_with_uncommitted_changes() -> anyhow
StableHunkDependencies {
diffs: [
(
2434601357784245452,
8240534308515296008,
[
HunkLock {
stack_id: stack_1,
Expand All @@ -111,7 +111,7 @@ fn complex_file_manipulation_multiple_hunks_with_uncommitted_changes() -> anyhow
],
),
(
3708607749576748282,
15989967088397270668,
[
HunkLock {
stack_id: stack_1,
Expand All @@ -120,7 +120,7 @@ fn complex_file_manipulation_multiple_hunks_with_uncommitted_changes() -> anyhow
],
),
(
16712260417274738957,
18120254504138851193,
[
HunkLock {
stack_id: stack_1,
Expand All @@ -142,7 +142,7 @@ fn dependencies_ignore_merge_commits() -> anyhow::Result<()> {
StableHunkDependencies {
diffs: [
(
12435379862484897562,
2654316029522724523,
[
HunkLock {
stack_id: stack_1,
Expand Down
1 change: 0 additions & 1 deletion crates/gitbutler-git/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![deny(missing_docs, unsafe_code)]
#![allow(async_fn_in_trait)]
#![allow(unknown_lints)]
#![cfg_attr(windows, feature(windows_by_handle))]

#[cfg(all(
not(debug_assertions),
Expand Down
6 changes: 3 additions & 3 deletions crates/gitbutler-hunk-dependency/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub struct InputDiff {

impl InputDiff {
pub fn net_lines(&self) -> anyhow::Result<i32> {
self.new_lines
.checked_signed_diff(self.old_lines)
.ok_or(anyhow!("u32 -> i32 conversion overflow"))
let old_lines = i32::try_from(self.old_lines)?;
let new_lines = i32::try_from(self.new_lines)?;
Ok(new_lines - old_lines)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/gitbutler-hunk-dependency/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(unsigned_signed_diff)]
pub(crate) mod hunk;
pub mod input;
pub mod locks;
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ but-core.workspace = true
but-hunk-dependency.workspace = true
open = "5"
url = "2.5.4"
tauri-plugin-notification = "2.2.1"

[target.'cfg(target_os = "macos")'.dependencies]
tauri-plugin-trafficlights-positioner = { git = "https://github.com/gitbutlerapp/tauri-plugin-trafficlights-positioner", branch = "v2"}
Expand Down
2 changes: 2 additions & 0 deletions crates/gitbutler-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"store:default",
"updater:default",
"http:allow-fetch",
"notification:allow-is-permission-granted",
"notification:default",
{
"identifier": "http:default",
"allow": [
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ fn main() {
.plugin(tauri_plugin_single_instance::init(|_, _, _| {}))
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_fs::init())
// .plugin(tauri_plugin_context_menu::init())
.plugin(tauri_plugin_store::Builder::default().build())
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2025-02-14"
channel = "stable"
components = [
"rustfmt",
"rustc-dev",
Expand Down
Loading