tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
84.09k stars 2.53k forks source link

Notification does not works #917

Closed TobiasTao closed 3 years ago

TobiasTao commented 4 years ago

Describe the bug I tried two methods to send a notification:

  1. via js

    showNotification(): void {
    const notification = new Notification('Hi there!');
    }

    result: nothing happened: no notificaions and no errors

  2. via rust:

    
    event::listen(String::from("notification"), move |msg| {
        println!("got notification with message '{:?}'", msg);
        let res = Notification::new()
          .title("New message")
          .body("You've got a new message.")
          .show();
    
        match res {
          Err(e) => {},
          Ok(_) => println!("notification success")
        }
      })
 app crashed with errors:

Finished dev [unoptimized + debuginfo] target(s) in 3.01s Running target\debug\tauri-api-demos.exe got notification with message 'Some("notification data")' thread 'main' panicked at 'failed to call RoInitialize: error -2147417850', C:\Users\tobiastao.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rust lib/src/rust\src\libstd\macros.rs:16:9 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace error: process didn't exit successfully: target\debug\tauri-api-demos.exe (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

app:spawn Command "cargo" failed with exit code: 3221226505 +0ms

app:tauri (runner) ⚠️ [FAIL] Cargo CLI has failed +2ms

app:tauri Shutting down tauri process... +1ms error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


**To Reproduce**
Steps to reproduce the behavior:
1. clone the repo: git@github.com:TobiasTao/tauri-api-demos.git
2. yarn
3. yarn fe:dev
4. yarn be:dev

then click buttons:
![image](https://user-images.githubusercontent.com/37654563/89121735-0b9a6d00-d4f4-11ea-8739-e908d409c1c3.png)

**Platform and Versions (please complete the following information):**

[tauri]: running info

Operating System - Windows_NT(10.0.18363) - win32/x64 Microsoft Edge - 44.18362.449.0_neutral__8wekyb3d8bbwe

Node.js environment Node.js - 12.18.3 tauri.js - 0.11.0

Rust environment rustc - 1.45.0 cargo - 1.45.0 tauri-bundler - 0.9.1

Global packages NPM - 6.14.6 yarn - 1.22.4

App directory structure /.git /.idea /.vscode /dist /e2e /node_modules /src /src-tauri

App tauri.rs - 0.9.0 mode - embedded-server build-type - bundle CSP - default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline' distDir - ../dist/tauri-api-demos devPath - http://localhost:4200

zicklag commented 4 years ago

Did you request permissions to show notifications first? For example:

window.Notification.requestPermission()
TobiasTao commented 4 years ago

i tried it:

    Notification.requestPermission().then(status => {
      console.log(status); 
      const n = new Notification('title', {body: 'notification body'}); 
    });

but permission is 'denied': image

how can i change it?

zicklag commented 4 years ago

Oh, do you have notifications enabled in your tauri.conf.json?

TobiasTao commented 4 years ago

I have enabled all API features: https://github.com/TobiasTao/tauri-api-demos/blob/master/src-tauri/tauri.conf.json#L41

AlexanderShvaykin commented 3 years ago

I have the same problem. The notification doesn't work in the osx build, but it works in dev mode.

lemarier commented 3 years ago

Related to https://github.com/tauri-apps/tauri/issues/1570

dibadibadiudiu commented 3 years ago

@AlexanderShvaykin I have the same problem. Will you consider repairing this problem? It works on MAC, but it doesn't work on windows.

lucasfernog commented 3 years ago

Unfortunately we need better info to reproduce the error. Seems like it only happens on some specific setups.

kmcluckie commented 3 years ago

This is happening to me also:

thread 'main' panicked at 'failed to call RoInitialize: error -2147417850', C:\.....\winrt-0.4.0\src\rt\mod.rs:729:9

I am not a desktop developer, but my uneducated investigation shows this has to do with initialising the Window Runtime, and mod.rs specifies RO_INIT_MULTITHREADED. The error code returned leads me to search results with the error message "Cannot change thread mode after it is set". So perhaps we are trying to reinitialise WinRT in a multithreaded mode, whereas it was initialised as singlethreaded already?

This is absolutely uneducated tinkering, but I would like to assist to clear this up as it is preventing me moving forward. Any direction from the Rust and Windows experts is welcome.

lucasfernog commented 3 years ago

I have a fix for this, I'll push it tonight.

mzy2240 commented 2 years ago

When working with Push.js(https://pushjs.org/docs/introduction), the desktop notification will pop up but then in less than one second the window (both dev and prod) will crash.