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

Desktop support (Linux, Windows) #746

Open
1 of 2 tasks
proninyaroslav opened this issue Aug 7, 2020 · 66 comments
Open
1 of 2 tasks

Desktop support (Linux, Windows) #746

proninyaroslav opened this issue Aug 7, 2020 · 66 comments
Labels
help wanted Extra attention is needed

Comments

@proninyaroslav
Copy link
Contributor

proninyaroslav commented Aug 7, 2020

I see that you are trying to implement macOS support and it would be appropriate to add Windows and Linux as well. Windows has a native Win32 API, while Linux uses libnotify library, which covers cases for different desktop environments.

  • Linux
  • Windows
@MaikuB
Copy link
Owner

MaikuB commented Aug 7, 2020

As the plugin implements a federated plugin structure, the ability to add support for other platforms is open to the community to do so. It sounds like you're interested in leveraging that work, if so then I would suggest you contribute back by adding support for the other platforms.

@proninyaroslav
Copy link
Contributor Author

Yes, I'll try to help you as soon as I get free time.

@MaikuB
Copy link
Owner

MaikuB commented Aug 7, 2020

Note that I'm not familiar with either Win32 or Linux. As far as I know, they require using C++, which I'm not particularly familiar with so I'm not well-positioned to implement this myself, though I could probably scrap bits of knowledge here and there to review code if needed

@proninyaroslav
Copy link
Contributor Author

In general, any language that supports FFI can be used. But C++ is probably the easiest option.

@proninyaroslav
Copy link
Contributor Author

proninyaroslav commented Aug 7, 2020

Although it might be worth using Dart + FFI (but it still beta).

@MaikuB MaikuB added the help wanted Extra attention is needed label Aug 8, 2020
@artemsivcev
Copy link

artemsivcev commented Nov 6, 2020

Hi! Our team want to help with this issue (windows part of it). Is there any new information about this feature?

@MaikuB
Copy link
Owner

MaikuB commented Nov 7, 2020

If you want to help then the best way is to submit a PR. There's a draft one for Linux support #888 that you help the author with, help test out etc

@MaximRyabovol
Copy link

We have some decision for windows notifications. It uses a process_run plugin and powershell commands. It works perfectly in debug, but in realise version of the app there are some problems. If you interesting you can find our variant here.

@HrX03
Copy link

HrX03 commented Jan 20, 2021

For linux i found a lib using gnome/gtk notification model https://github.com/canonical/desktop_notifications.dart, might want to take a peek. Saw a pr that already tried to use this model but had some issues iirc, maybe this one could work better.

@lucasjinreal
Copy link

lucasjinreal commented May 31, 2021

This still an issue!!

@MaikuB
Copy link
Owner

MaikuB commented May 31, 2021

@jinfagang this wasn't closed and has a needs help label even so as mentioned before in #1183, support for this would need a PRs/contributions from the community

@Sunbreak
Copy link

A PoC of notification plugin on Android/iOS/Windows/Linux/macOS: https://github.com/woodemi/quick_notify

@proninyaroslav
Copy link
Contributor Author

I'll be taking over Linux (and possibly Windows) support shortly. Thanks @Sunbreak, I will use your example implementation as a starting point to adapt the flutter_local_notifications API.

@proninyaroslav
Copy link
Contributor Author

proninyaroslav commented Jun 25, 2021

Started on working #1208

@proninyaroslav
Copy link
Contributor Author

Duplicated from #1208 (comment):

At the moment I'm planning on using libnotify and C++. But there is an option to use DBus package, as is done in this project: https://github.com/canonical/desktop_notifications.dart. This will allow to write the Linux part entirely in Dart. What do you think about it?
Similarly, we can use win32 package for notifications, without using native C++ code, only Dart.

@Sunbreak
Copy link

At the moment I'm planning on using libnotify and C++. But there is an option to use DBus package, as is done in this project: https://github.com/canonical/desktop_notifications.dart. This will allow to write the Linux part entirely in Dart. What do you think about it?

https://github.com/canonical/desktop_notifications.dart is great and it is maintained by Canonical, the company of Ubuntu

Similarly, we can use win32 package for notifications, without using native C++ code, only Dart.

There're still something to implement within win32 in order to call ToastNotificationManager: halildurmus/win32#246

@proninyaroslav
Copy link
Contributor Author

proninyaroslav commented Jun 26, 2021

@Sunbreak

https://github.com/canonical/desktop_notifications.dart is great and it is maintained by Canonical, the company of Ubuntu

Do you mean to use it inside flutter_local_notifications? Or just use DBus, instead of libnotify?

@Sunbreak
Copy link

@proninyaroslav you could take advantage of desktop_notifications to implement flutter_local_notifications

@proninyaroslav
Copy link
Contributor Author

@Sunbreak
I don't think this is a good idea as flutter_local_notifications tries to avoid external dependencies. It might be worth considering dbus package, or implementing DBus calls in native code if dbus package is not suitable in this case. @MaikuB what do you think about this?

@MaikuB
Copy link
Owner

MaikuB commented Jun 28, 2021

@proninyaroslav agreed, the only dependency this plugin should take is to use dbus to make calls to show notifications or consume a plugin that implements Linux support by implementing the platform interface. Using desktop_notifications would make maintenance more difficult

@proninyaroslav
Copy link
Contributor Author

Linux support implementation is ready, I invite everyone to take part in the review and testing #1208

@12people
Copy link
Contributor

The Linux implementation was swiftly removed again in v 7.0 because of a conflict with the web builds.

Is this going to be a trivial issue to fix or should I not expect Linux notification support anytime soon?

@MaikuB
Copy link
Owner

MaikuB commented Aug 1, 2021

There's an open PR on this already #1249.

Once that is merged in though, I'm going to look to have Linux support be in a pre-release instead to be safe given how it went last time and to let it "bake" for bit longer

@kennethnym
Copy link

kennethnym commented Aug 1, 2021

I'm currently taking a crack at Windows implementation, however I am struggling with calling WinRT API in a win32 context. Calls to WinRT APIs always throws hresult_from_win32(ERROR_NOT_FOUND, which after days of extensive research seems to indicate that the WinRT projection is not properly integrated (I think the program has to be bundled into an appx bundle). I would appreciate it if anyone can offer some guidance.

What I've done

I have followed this page to enable calling WinRT API from win32 programs, by making the following changes in CMakeLists.txt:

  • Installing the WinRT/C++ nuget package:
set(NUGET_PACKAGES_PATH "${CMAKE_BINARY_DIR_WIN_STYLE_PATH}\\packages")

function(install_nuget_package pkg ver)
	exec_program(${NUGET}
		ARGS install ${pkg}
			-ExcludeVersion
			-Version ${ver}
			-Source "https://api.nuget.org/v3/index.json"
			-OutputDirectory ${NUGET_PACKAGES_PATH})
	target_link_libraries(${PLUGIN_NAME} PRIVATE "${NUGET_PACKAGES_PATH}\\${pkg}\\build\\native\\${pkg}.targets")
endfunction()

install_nuget_package("Microsoft.Windows.CppWinRT" 2.0.210722.2)
  • Setting the following target properties:
set_target_properties(${PLUGIN_NAME} PROPERTIES
  CXX_VISIBILITY_PRESET     hidden
  VS_GLOBAL_TargetFramework "net5.0-windows10.0.17763.0"
  VS_GLOBAL_CppWinRTPath    "${NUGET_PACKAGES_PATH}\\Microsoft.Windows.CppWinRT\\bin\\"
)
  • Enabling these compile options:
target_compile_options(${PLUGIN_NAME} PRIVATE /bigobj /await)

Related issues:
microsoft/microsoft-ui-xaml#2773

@Sunbreak
Copy link

Sunbreak commented Aug 1, 2021

I would appreciate it if anyone can offer some guidance.

Commented at #746 (comment)

@kennethnym
Copy link

I set VS_PROJECT_IMPORT as well and I am still having issue.

@azchohfi
Copy link

azchohfi commented Feb 7, 2022

@kennethnym Alright! Let me know how I can help you. I want to see this landing as soon as possible. This is one of the most used Flutter dependencies, and I know that many apps would be unblocked by this work.

@MaikuB
Copy link
Owner

MaikuB commented Feb 8, 2022

If it uses something official then sure. As an example, the Linux implementation uses the dbus package maintained by Canonical

@lucasjinreal
Copy link

Does windows notification avaiable now?

@kennethnym
Copy link

Not yet, still a WIP

@Sunbreak
Copy link

Sunbreak commented Feb 8, 2022

@kennethnym #746 (comment)

set_target_properties(${PLUGIN_NAME} PROPERTIES
  CXX_VISIBILITY_PRESET     hidden
  VS_GLOBAL_TargetFramework "net5.0-windows10.0.17763.0"
  VS_GLOBAL_CppWinRTPath    "${NUGET_PACKAGES_PATH}\\Microsoft.Windows.CppWinRT\\bin\\"
)

Not sure what is your blocking issue. But net5.0 is not necessary

BTW WinRT Notification is not available on Windows 7 if I record correctly

@kennethnym
Copy link

My visual studio install broke recently. I am trying to get it fixed.

@kennethnym
Copy link

kennethnym commented Feb 8, 2022

Quick update: Flutter now bundles winrt so I no longer need to pull the winrt package manually from nuget. However, the bundled winrt seems to behave differently. I was able to send notifications successfully with the nuget version of winrt. WIth the bundled version of winrt, Windows shows "New notifications" as the content of the notification, instead of the body that I passed to it. I need to investigate further.

Edit: for context i am using VS 2022 with Windows 11.

@azchohfi
Copy link

azchohfi commented Feb 9, 2022

I believe it is not Flutter that does this, but the Windows SDK itself. There is a C++/WinRT version there, but you should always use the latest from nuget.org. I have a snippet that helps installing it on cmake:
https://github.com/Baseflow/flutter-geolocator/blob/726f928ac7662f417c69bb1958e4456afd173929/geolocator_windows/windows/CMakeLists.txt#L15-L45
You will probably also need these two compiler changes (to call async code, which most of the WinRT APIs do):
https://github.com/Baseflow/flutter-geolocator/blob/726f928ac7662f417c69bb1958e4456afd173929/geolocator_windows/windows/CMakeLists.txt#L54-L55
You might also need to link to the windowsapp lib, if you call any API from it:
target_link_libraries(${PLUGIN_NAME} PRIVATE windowsapp)

Let me know if this helps you.

@kennethnym
Copy link

That is very helpful. Thanks for the info!

@kennethnym
Copy link

Unfortunately, I am still having the same issue. If I use XML template to show notification, nothing would happen; if I use one of the default templates, only "New notifications" would appear.

@azchohfi
Copy link

azchohfi commented Feb 9, 2022

Could you share the code so I can take a look?

@kennethnym
Copy link

I will make a draft PR.

@c0c4i
Copy link

c0c4i commented Mar 2, 2022

Is it coming soon?

@kennethnym
Copy link

It will still take a while. Appreciate your patience!

@Fraa-124
Copy link

Hello, what is the state of this issue? With full support for desktop, this library is now a must for a lot of apps.

@kennethnym
Copy link

kennethnym commented May 27, 2022

Hello, I'd love to close this as soon as possible, but I am still currently stuck at some issues (more in #1473 ). If someone could step in and help that would be great.

@ollyde
Copy link

ollyde commented May 28, 2022

Looking forwards to the implementation.

@rekire
Copy link

rekire commented Oct 9, 2022

What is the current status for the Windows support? What is still a problem which needs to be fixed?

@kmoreau
Copy link

kmoreau commented Feb 23, 2023

Hello,
Is it possible to ask for the current status of the notifications on Windows? thanks :)

@prinkeeras
Copy link

Any updates on windows implementation?

@mattsrobot
Copy link

I would love to see Windows support!!

@realrk95
Copy link

Any updates on Windows?

@kennethnym
Copy link

sorry, i haven't worked with flutter in a long while, but anyone is free to pick up where i left off :)

@Levi-Lesches
Copy link

Thanks to @kennethnym and @lightrabbit, I'm currently working on #2349. Aiming to finish sometime this or next week.

@Levi-Lesches
Copy link

Levi-Lesches commented Jun 26, 2024

Update: Going really well so far. I've decided to support raw XML and Dart-based enums and classes for further support. Example in progress:

final action = WindowsNotificationAction(
  content: "Submit", 
  arguments: "submit_picture",
);
final details = WindowsNotificationDetails(actions: [action]);
await plugin.show(_id++, "Title", "Body", notificationDetails: details);

image

Clicking the button sends the string submit_picture back to Dart the usual way

@Levi-Lesches
Copy link

Levi-Lesches commented Jun 26, 2024

Update: I've transcribed the entirety of the Windows Toast Notification API to Flutter. Here's a more complex example:

    final profilePic = WindowsImage(
      source: File(r"C:\Users\KDAB\Downloads\image1.jpg"),
      altText: "The first image",
      crop: WindowsImageCrop.circle,
      placement: WindowsImagePlacement.appLogoOverride,
    );
    final bigImage = WindowsImage(
      source: File(r"C:\Users\KDAB\Downloads\image2.jpg"),
      altText: "The second image",
    );
    final likeButton = WindowsAction(
      content: "Like",
      arguments: "like_post|post_id",
    );
    final commentButton = WindowsAction(
      content: "View Comments",
      arguments: "comment_on_post|post_id",
    );
    const input = WindowsTextInput(
      id: "input-id",
      hintText: "Send a reply",
    );
    final sendButton = WindowsAction(
      content: "Send",
      arguments: "send_reply|post_id",
      inputId: "input-id",
    );
    final progress = WindowsProgressBar(status: "Syncing...", value: 0.75);
    final details = WindowsNotificationDetails(
      actions: [likeButton, commentButton, sendButton],
      images: [bigImage, profilePic],
      inputs: [input],
      progressBars: [progress],
    );
    await plugin.show(
      _id++,
      "Adam Wilson tagged you in a photo",
      "Isn't it great?",
      notificationDetails: details,
    );

image

Raw XML is also supported. I've updated #2349 and marked it as ready for review. It's not 100% ready yet, and there's a TODO on the PR, but if you'd like to use it temporarily, you can put this in for now and remove it once everything is finished:

dependency_overrides: 
  flutter_local_notifications: 
    git: 
      url: https://github.com/Levi-Lesches/flutter_local_notifications.git
      ref: windows-impl

@Levi-Lesches
Copy link

Levi-Lesches commented Jun 28, 2024

Update: My branch is ready for use. Can't guarantee I won't break anything yet, but you can try out the example/main.dart file for yourself. That file has all the shared implementations, and then the windows-only stuff is in example/windows.dart.

On a non-MSIX, you can't search for or cancel specific notifications, and Windows doesn't support repeating notifications at all, but everything else (and a lot more) has been implemented in the example.

If you want to guarantee not being broken until the feature is officially ready to release, change the ref parameter from my previous comment to a full commit hash instead of just the branch name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests