Skip to content
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

Notification does not works #917

Closed
TobiasTao opened this issue Aug 2, 2020 · 11 comments
Closed

Notification does not works #917

TobiasTao opened this issue Aug 2, 2020 · 11 comments

Comments

@TobiasTao
Copy link

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

  1. 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

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
Copy link

zicklag commented Aug 9, 2020

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

window.Notification.requestPermission()

@TobiasTao
Copy link
Author

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
Copy link

zicklag commented Aug 10, 2020

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

@TobiasTao
Copy link
Author

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

@AlexanderShvaykin
Copy link

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

@lemarier
Copy link
Member

Related to #1570

@dibadibadiudiu
Copy link

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

@lucasfernog
Copy link
Member

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

@kmcluckie
Copy link

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
Copy link
Member

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

@mzy2240
Copy link

mzy2240 commented Nov 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants