hlaueriksson / GEmojiSharp

:octocat: GitHub Emoji for C#, ASP.NET Core and Blazor, dotnet tool for the terminal and PowerToys Run plugin
https://hlaueriksson.github.io/GEmojiSharp/
MIT License
116 stars 8 forks source link

Crash in PowerToys #23

Closed pilgrimlyieu closed 1 year ago

pilgrimlyieu commented 1 year ago

Hello, I met an issue recently. When I use Alt + Space to open the Run window, type something like emoji laugh, select one of emojis and press Enter or Ctrl + C, an error will be thrown like below.

The version of GEmojiSharp is 3.1.0, latest in release. The version of PowerToys is 0.74.0, also the latest.

Version: 0.74.0.0
OS Version: Microsoft Windows NT 10.0.22631.0
IntPtr Length: 8
x64: True
Date: 2023/10/03 11:01:59
Exception:
System.Runtime.InteropServices.COMException (0x800401D0): OpenClipboard 失败 (0x800401D0 (CLIPBRD_E_CANT_OPEN))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
   at System.Windows.Clipboard.Flush()
   at GEmojiSharp.PowerToysRun.Main.CopyToClipboard(String value)
   at GEmojiSharp.PowerToysRun.Main.<>c__DisplayClass16_3.<Query>b__6(ActionContext _)
   at PowerLauncher.ViewModel.MainViewModel.<>c__DisplayClass30_0.<OpenResultsEvent>b__0()
   at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke(Action callback)
   at PowerLauncher.ViewModel.MainViewModel.OpenResultsEvent(Object index, Boolean isMouseClick)
   at PowerLauncher.ViewModel.MainViewModel.<InitializeKeyCommands>b__31_10(Object index)
   at PowerLauncher.ViewModel.RelayCommand.Execute(Object parameter)
   at System.Windows.Input.CommandManager.TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
   at System.Windows.UIElement.OnKeyDownThunk(Object sender, KeyEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Since other Run plugin works normal, I'm wondering that if I've done something wrong on this plugin or I've missed something. I couldn't find similar cases and solution in internet so I open an issue for help.

If I've done something wrong, please inform me! Thanks for your wonderful plugin!

hlaueriksson commented 1 year ago

@pilgrimlyieu thanks for reporting this issue!

Maybe I need to access the clipboard from a new thread, like the UnitConverter plugin.

Can you give examples of out of the box plugins where copy to clipboard works?

pilgrimlyieu commented 1 year ago

Can you give examples of out of the box plugins where copy to clipboard works?

PowerTranslator & EverythingPowerToys seem to work.


Although the crash will occur, the emoji could still be copied to clipboard correctly.

hlaueriksson commented 1 year ago

So both PowerTranslator and EverythingPowerToys use Clipboard.SetDataObject instead of Clipboard.SetText.

I will make this change in GEmojiSharp.PowerToysRun when I get the time. Or if you want to contribute, please submit a PR.

pilgrimlyieu commented 1 year ago

I will make this change in GEmojiSharp.PowerToysRun when I get the time. Or if you want to contribute, please submit a PR.

I would like to but I'm a student learning C at first and I have no idea with C#. I can wait and keep this issue opened until you get the time. Or if the change is minor, could you so please give me some guidance?

I opened a PR in #24.

hlaueriksson commented 1 year ago

@pilgrimlyieu thanks for the PR! I'll create a new release with the fix included.

hlaueriksson commented 1 year ago

You can try out your fix in version 3.1.1 of GEmojiSharp.PowerToysRun

Download and install; https://github.com/hlaueriksson/GEmojiSharp/releases/tag/v3.1.1

pilgrimlyieu commented 1 year ago

Works normally now. Thanks for your awesome plugin!

Should I close this issue now?

hlaueriksson commented 1 year ago

That's great to hear that it works. Thanks for your contribution to the project!