Uniface User Forum

 View Only
Expand all | Collapse all

Accessing the windows notifications.

  • 1.  Accessing the windows notifications.

    PARTNER
    Posted 03-25-2022 08:47
    Is there a hidden method and/or something on the shared GIT stuff which would allow a uniface component to send a message to the windows notification tray. 
    We did write a VB dll to access the NotifyIcon class, but access to this has stopped working and my VB expert is on maternity leave. 
    If there were a standard method, that would be lovely. 

    Regards, 
    Iain

    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------


  • 2.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-28-2022 09:29
    Well, I don't know at all if this will work in an Uniface HTML widget, and there's a good chance I'm gonna make a fool of myself, but what about using the javascript notification API ?

    ------------------------------
    Jean-Marc Salis
    Mp Services
    Montauban Cedex FR
    ------------------------------



  • 3.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-30-2022 05:00
    I looked at that, but I think that puts a notification up over the HTML displayed widget, and if the application is out of focus behind something else, or minimised then it won't show. (Assuming we mean 'alert').
    I'm looking for something which could be used to alert the user to look at the Uniface app even if they are not currently, and which doesn't require clicking on to move on with the uniface code (so, exactly like the 'new mail' popup in the bottom right of the windows screen (task bar "NotifyIcon" functionality). 
    If there's javascript which can trigger this popup, my google fu is inadequate to the task of finding it.

    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------



  • 4.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-30-2022 05:24
    I was more thinking of something like that :

    https://www.javascripttutorial.net/web-apis/javascript-notification/

    With it, in a browser (and with the authorization) you can trigger OS notifications (tried it on Debian/GNOME and Windows). Depending on the possibilities of the browser/widget, you can also add an icon.

    But it will be very dependant on the widget, and I'm not even sure it's possible :-)

    (My Uniface HTML widget fu are very low)

    ------------------------------
    Jean-Marc Salis
    Mp Services
    Montauban Cedex FR
    ------------------------------



  • 5.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-31-2022 05:53
    Yeah, I've used the sample URL from that website in an HTMP widget, and it has no effect. I've made sure "Enable javascript" is turned on in the HTML widget, but (aside from the header text being displayed) nothing happens. 
    https://www.javascripttutorial.net/sample/webapis/notification/

    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------



  • 6.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-30-2022 05:58
    Hi,
    VB script can be replaced by powershell command, and you can find on google many examples like :
    powershell -Command "Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \"Attention $Env:USERNAME\" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)"​
    You can run this by spawn or oscommand ... it's a bit longer but it works...
    ATTENTION : Do not use powershell script, it's block by Windows security...

    Gilles .

    ------------------------------
    Hortion Gilles
    Agfa-Gevaert NV
    ------------------------------



  • 7.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-30-2022 07:19
    Hmm, I put this in the following code into my test form (single command button). 

    trigger detail
    variables
    	string v_sql, v_line
    endvariables
    
    debug
    v_sql = "powershell -Command %%"Add-Type -AssemblyName System.Windows.Forms ;"
    v_sql = $concat(v_sql," $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;")
    v_sql = $concat(v_sql," $path = (Get-Process -id $pid).Path;")
    v_sql = $concat(v_sql,"$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;")
    v_sql = $concat(v_sql,"$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;")
    v_sql = $concat(v_sql,"$balloon.BalloonTipText = 'What do you think of this balloon tip?';")
    v_sql = $concat(v_sql,"$balloon.BalloonTipTitle = 'Attention $Env:USERNAME' ;")
    v_sql = $concat(v_sql,"$balloon.Visible = $true ;")
    v_sql = $concat(v_sql,"$balloon.ShowBalloonTip(5000)%%"")
    activate "SYS_OSCOMMAND".COMMANDOUT(v_sql, v_line)​


    Which sets v_sql = 
    powershell -Command "Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ; $path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = 'Attention $Env:USERNAME' ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)"​

    Running this from the command prompt does the popup. Running it from the OSCOMMAND signature, does nothing, and returns $status=0 and nothing in v_line)



    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------



  • 8.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-30-2022 07:41
    Edited by Hortion Gilles 03-30-2022 07:41
    Hi,

    spawn "powershell -Command %%"Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \%%"Attention $Env:USERNAME\%%" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)%%""​


    Work also with oscommand  by adding cmd /c :

    activate "OSCOMMAND".command("cmd /c powershell -Command %%"Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \%%"Attention $Env:USERNAME\%%" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)%%"")





    ------------------------------
    Hortion Gilles
    Agfa-Gevaert NV
    ------------------------------



  • 9.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-30-2022 07:53
    Yup, they are working, but they both show big black windows due to the cmd. I've tried /q but I can't see a cmd switch which prevents the window. 
    Haven't tried the javascript above yet though (more complex setup).

    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------



  • 10.  RE: Accessing the windows notifications.
    Best Answer

    PARTNER
    Posted 03-30-2022 09:03
    well,

    create a notification.bat  :
    powershell -windowstyle hidden -Command "Add-Type -AssemblyName System.Windows.Forms ; $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;$path = (Get-Process -id $pid).Path;$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning ;$balloon.BalloonTipText = 'What do you think of this balloon tip?';$balloon.BalloonTipTitle = \"Attention $Env:USERNAME\" ;$balloon.Visible = $true ;$balloon.ShowBalloonTip(5000)"​

    create a notification.vbs file that calls the notification.bat file:

    Set WinScriptHost = CreateObject("WScript.Shell")
    WinScriptHost.Run Chr(34) & "notification.bat" & Chr(34), 0
    Set WinScriptHost = Nothing


    then call  notification.vbs:

    spawn "notification.vbs"





    ------------------------------
    Hortion Gilles
    Agfa-Gevaert NV
    ------------------------------



  • 11.  RE: Accessing the windows notifications.

    PARTNER
    Posted 03-31-2022 09:04
    Hi, 
    So I did some playing around, and there are a couple of things I thought would be useful to add to the code above. 

    params
    	numeric p_delay : IN
        string p_heading : IN
        string p_message : IN
    	string p_icon : IN
    endparams
    
    variables
    	string v_sql, v_line
    	numeric v_status
    	handle v_shell
    endvariables
    
    if(p_delay = "" | p_delay = 0)
    	p_delay = 5000
    else
    	p_delay = p_delay*1000
    endif
    v_sql = "powershell -windowstyle hidden -Command %%"Add-Type -AssemblyName System.Windows.Forms ;"
    v_sql = $concat(v_sql," $global:balloon = New-Object System.Windows.Forms.NotifyIcon ;")
    v_sql = $concat(v_sql," $path = (Get-Process -id $pid).Path;")
    v_sql = $concat(v_sql," $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) ;")
    v_sql = $concat(v_sql," $balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::None ;")
    v_sql = $concat(v_sql," $balloon.BalloonTipText = '",$replace(p_message,1,"'","\'",-1),"';")
    v_sql = $concat(v_sql," $balloon.BalloonTipTitle = '",p_heading,"' ;")
    v_sql = $concat(v_sql," $balloon.Visible = $true ;")
    v_sql = $concat(v_sql," $balloon.ShowBalloonTip(",p_delay,");")
    v_sql = $concat(v_sql," Start-Sleep -Milliseconds ",p_delay,";")
    v_sql = $concat(v_sql," $global:balloon.Dispose();%%"")
    newinstance "WSH_WSHSHELL",v_shell
    v_shell->run(v_status,v_sql,0,0)
    deleteinstance v_shell​

    Notes:-
    • It seems the variable delay for notifications is deprecated, and now based on system accessibility settings. So all the p_delay in here is (basically) pointless. 
    • The code above left an icon in the system tray, which vanished on mouse over, but it was stacking icons up if left to run several times. So I instituted the $global:balloon.Dispose() to clear it. However, this seems to get rid of the resources before it can display the icon for the application, so I put in the Sleep command to keep the NotifyIcon around long enough to display the tooltip properly. 
    • Finally, I remembered we'd implemented the shell dll as a signature I could use the Wshell.run command rather than using files. 
      • This was to cope with the fact that I wanted to remove the files after use, and couldn't get it to delete itself, and/or get the timing right on deleting them from the app. 

    This is now working, as required, thank you. 
    Iain

    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------