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" encoding does not work for Windows in non-UTF8 systems #1191

Closed
tsuchinaga opened this issue Jul 16, 2020 · 5 comments
Closed
Labels
bug Something isn't working OS:Windows Tickets affecting only Microsoft Windows question A question has been asked
Milestone

Comments

@tsuchinaga
Copy link

Describe the bug:

notification don't work if they contain multi byte strings.
default encoding for power shell on japanese windows is SJIS.
UTF8 used in ps1 file.

To Reproduce:

Steps to reproduce the behaviour:

  1. set multi byte strings to title and content
  2. call fyne.CurrentApp().SendNotification(fyne.NewNotification(title, content))

Example code:

func main() {
	a := app.New()
	a.Settings().SetTheme(&theme.MisakiTheme{})

	w := a.NewWindow("Fyne Learn")
	w.SetContent(fyne.NewContainerWithLayout(layout.NewCenterLayout(),
		widget.NewVBox(widget.NewButton("ですくとっぷつうち", func() {
			title := "Fyneの練習"
			content := "通知のテスト"
			fyne.CurrentApp().SendNotification(fyne.NewNotification(title, content))
		}))))

	w.ShowAndRun()
}

generated script(utf8)

$title = "Fyneの練習"
$content = "通知のテスト"

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text")[0].AppendChild($toastXml.CreateTextNode($title)) > $null
$toastXml.GetElementsByTagName("text")[1].AppendChild($toastXml.CreateTextNode($content)) > $null

$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("appID").Show($toast);

log

> PowerShell -ExecutionPolicy Bypass -File fyne--notify-1.ps1
発生場所 C:\Users\woocu\AppData\Local\Temp\fyne--notify-1.ps1:2 文字:13
+ $content = "騾夂衍縺ョ繝・せ繝・
+             ~~~~~~~~~~
式またはステートメントのトークン '騾夂衍縺ョ繝・せ繝・' を使用できません。
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Device

  • OS: Windows 10 64bit
  • Version: 19635.1
  • Go version: go version go1.14.4 windows/amd64
  • Fyne version: v1.3.2
  • Language: Japanese
@andydotxyz
Copy link
Member

Can you report whether this is fixed or not by adding the following line at thje top of the 'ps1' file?
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

I got this hint from: https://stackoverflow.com/questions/49476326/displaying-unicode-in-powershell
All of the input/output from Fyne apps should be UTF8 so the soltion seems to be to ask PowerShell to understand this format.

@andydotxyz andydotxyz added bug Something isn't working question A question has been asked labels Jul 17, 2020
@andydotxyz andydotxyz added this to the 1.3.x milestone Jul 17, 2020
@andydotxyz andydotxyz changed the title "Notification" encoding does not match "Notification" encoding does not work for Windows in non-UTF8 systems Jul 17, 2020
@andydotxyz andydotxyz added the OS:Windows Tickets affecting only Microsoft Windows label Jul 17, 2020
@tsuchinaga
Copy link
Author

thank you for replay

fyne--notify-1.ps1

$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

$title = "Fyneの練習"
$content = "通知のテスト"

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text")[0].AppendChild($toastXml.CreateTextNode($title)) > $null
$toastXml.GetElementsByTagName("text")[1].AppendChild($toastXml.CreateTextNode($content)) > $null

$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("appID").Show($toast);

did not work as expected.

>  PowerShell -ExecutionPolicy Bypass -File fyne--notify-1.ps1
At C:\Users\woocu\AppData\Local\Temp\fyne--notify-1.ps1:4 char:13
+ $content = "騾夂衍縺ョ繝・せ繝・
+             ~~~~~~~~~~
Unexpected token '騾夂衍縺ョ繝・せ繝・' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToke

@tsuchinaga
Copy link
Author

this worked

fyne--notify-1.ps1

$title = "Fyneの練習"
$content = "通知のテスト"
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text")[0].AppendChild($toastXml.CreateTextNode($title)) > $null
$toastXml.GetElementsByTagName("text")[1].AppendChild($toastXml.CreateTextNode($content)) > $null
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("appID").Show($toast);
> (Get-Content -Encoding UTF8 .\fyne--notify-1.ps1) | Invoke-Expression

@tsuchinaga
Copy link
Author

tsuchinaga commented Jul 18, 2020

execution fails if the script file contain utf8 string.
because it failed to read the script file.
not because it failed to run.
so I set the parameter arguments.

this worked

const notificationTemplate = `Param( $title, $content )

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text")[0].AppendChild($toastXml.CreateTextNode($title)) > $null
$toastXml.GetElementsByTagName("text")[1].AppendChild($toastXml.CreateTextNode($content)) > $null

$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("appID").Show($toast);`

script := notificationTemplate
err := ioutil.WriteFile(tmpFilePath, []byte(script), 0600)
if err != nil {
	log.Println(err)
	return
}
defer os.Remove(tmpFilePath)

title := "Fyneの練習"
content := "通知のテスト"
cmd := exec.Command("PowerShell", "-ExecutionPolicy", "Bypass", "-File", tmpFilePath, "-title", title, "-content", content)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
out, err := cmd.CombinedOutput()
if err != nil {
	log.Println(string(out), err)
}

please confirm.

andydotxyz added a commit that referenced this issue Jul 20, 2020
Go uses UTF8 for everything, Windows does not!
Fixes #1191
@andydotxyz
Copy link
Member

Many thanks for the hints. I had to use '-Raw' mode to avoid some errors in the processing but your suggestion was the key :)

Now on develop branch for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OS:Windows Tickets affecting only Microsoft Windows question A question has been asked
Projects
None yet
Development

No branches or pull requests

2 participants