Sign in to follow this  
Followers 0
Fran

tray icon to 'pause' install script

3 posts in this topic

#1 ·  Posted (edited)

Hi there!

I have a script that checks once a week for an update.

If an update is available, the tray icon flashes and an traytip is displayed.

When the user clicks on the tray icon, the gui starts up.

All works perfectly.

until......

When the user clicks cancel button or $GUI_EVENT_CLOSE I want the gui to exit, but still keep the tray icon visible, so they can just click on it again if they want to install the available update... and obviously if they click it again it should run the gui again to initiate installation.

I hope I'm explaining myself correctly.

My script is below.... (hope you don't have to comment out too much to run the script - i've cleaned it up as much as i could)

;Hide gui, but keep showing tray icon, so if the user clicks on the tray icon, function _Main() will be called again... or something like that.

I've tried various things, but no matter what I do I can't get the gui up again. If I click on the tray icon after quitting, the "Script Paused | Exit" options show up.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=images\App.ico
#AutoIt3Wrapper_Outfile=updater.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         Francisca Carstens

    Script Function:
    Check if RapidStudio Windows Client installed version corresponds to newest upgrade available on www.rapidstudio.co.za
    If newer version available, download and prompt install

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#Region -> Includes
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <Timers.au3>
#include <GuiButton.au3>
#EndRegion -> Includes

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt("TrayOnEventMode", 1)
#EndRegion -> Options
#Region -> Declarations
$instProgram = 'RapidStudio Software Updater'
$instLicense = FileRead(@ScriptDir & "\resources\license.txt")
Local $appath, $verl, $verr, $App = 'RapidStudio'
Local $vStatus ; Version Status... 1=up to date, 2=not newest, 3=version 5 (not upgradable)
Local $message
Local $goto = 2, $backto, $finish = 0, $downloadfinish = 0
Local $StatusBar, $hDownload, $nBytes, $nRead, $nSize, $calc, $file = @TempDir & '\RapidStudio_rsupdate', $url = 'http://update.rapidstudio.co.za'
Local $starttime, $speed
Local $prog = 0
Local $stop = 0
Global $silent = 1
;~ ShellExecuteWait (@scriptdir & "\test.exe",$silent) ; to execute upgrade in silent mode
#EndRegion -> Declarations

#Region -> GUI Items
$gui = GUICreate($instProgram, 500, 361, -1, -1, $GUI_SS_DEFAULT_GUI, $WS_EX_TOPMOST)
GUISetFont("", 400, "", "Tahoma", "", 5)

#Region -> Screen 1: Welcome Screen
$bkg1 = GUICtrlCreateGraphic(0, 0, 500, 314)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$pic1 = GUICtrlCreatePic(@ScriptDir & "\images\setup_leftpic1.jpg", 0, 0, 163, 314)
$tWelcomeHead = GUICtrlCreateLabel("Welcome to the " & $instProgram & " Wizard", 180, 18, 300, 50)
GUICtrlSetFont(-1, 13.2, 700, "", "Arial", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$tWelcomeBody = GUICtrlCreateLabel("This wizard will guide you through the download and installation of the newest RapidStudio software update available." & @LF & @LF & "It is recommended that you close all other applications before you continue. This will make it possible to update relevant system files without having to reboot your computer." & @LF & @LF & "Click Next to continue.", 180, 68, 300, 200)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$but1 = GUICtrlCreateButton("&Next >", 326, 325, 74, 23, $BS_DEFPUSHBUTTON)
$but2 = GUICtrlCreateButton("&Cancel", 412, 325, 74, 23)
$divBottom1 = GUICtrlCreateGraphic(0, 314, 510, 1, $SS_ETCHEDHORZ)
$but3 = GUICtrlCreateButton("< &Back", 326 - 74 - 2, 325, 74, 23)
GUICtrlSetState(-1, $GUI_HIDE)
#EndRegion -> Screen 1: Welcome Screen
#Region -> Screen 2: Download
$bkg2 = GUICtrlCreateGraphic(0, 0, 500, 60)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_HIDE)
$divTop = GUICtrlCreateGraphic(0, 60, 500, 1, $SS_GRAYFRAME)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadHead = GUICtrlCreateLabel("Download " & $App & " " & $verr & ".", 15, 10, 300, 20)
GUICtrlSetFont(-1, 8.5, 800, "", "Tahoma")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadHead2 = GUICtrlCreateLabel("", 25, 30, 450, 20)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 8.5, 400, "", "Tahoma")
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadBody1 = GUICtrlCreateLabel("", 25, 75, 450, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadBody2 = GUICtrlCreateLabel("", 25, 260, 450, 30)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadStatus = GUICtrlCreateLabel("", 25, 110, 450, 30)
GUICtrlSetState(-1, $GUI_HIDE)
$divBottom2 = GUICtrlCreateGraphic(10, 314, 480, 1, $SS_ETCHEDHORZ)
GUICtrlSetState(-1, $GUI_HIDE)
$ProgressDownload = GUICtrlCreateProgress(25, 90, 450, 20, $PBS_SMOOTH)
GUICtrlSetState(-1, $GUI_HIDE)
#EndRegion -> Screen 2: Download
#EndRegion -> GUI Items


#Region -> Pre GUI checks
$verl = '6.0.1.53'
$useremail = RegRead("HKEY_CURRENT_USER\Software\RapidStudio_Updater\", "Email")
Ping('www.google.com')
If @error Then Ping('www.google.com')
If @error Then
    MsgBox(0, '', 'You are not connected to the internet!') ;for testing
    Exit
EndIf
$verr = '6.0.1.58'
$releasedate = 'Nov 2010'
ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
_CheckVersion($verl, $verr)
If $vStatus = 1 Then
    MsgBox(0, "", "Your version is up to date") ;for testing
    Exit
EndIf

If $vStatus = 3 Then
    MsgBox(0, "", "Your version is too old to upgrade") ;for testing
    Exit
EndIf
#EndRegion -> Pre GUI checks


TrayTip("RapidStudio Updater", "New update available for RapidStudio.", 5, 1)
TraySetToolTip("RapidStudio - Updater")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "_Main")
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_Main")
TraySetState(4)

While 1
    Sleep(10) ; Idle loop
WEnd

_Main()

Func _Main()
    TraySetState(8)



    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $but2
                If $finish = 0 Then
                    If $goto = 2.5 Then
                        _Exit()
                    Else
                        If MsgBox(52 + 4096, $instProgram, "Are you sure you want to quit " & $instProgram & "?") = 6 Then
                        ;Hide gui, but keep showing tray icon, so if the user clicks on the tray icon, function _Main() will be called again... or something like that.

                        EndIf
                    EndIf
                Else
                    Exit
                EndIf

            Case $but1
                If $goto = 2 Then ;goto Stage 2: Prepare to Download Upgrade
                    GUICtrlSetState($bkg1, $GUI_HIDE)
                    GUICtrlSetState($pic1, $GUI_HIDE)
                    GUICtrlSetState($tWelcomeHead, $GUI_HIDE)
                    GUICtrlSetState($tWelcomeBody, $GUI_HIDE)
                    GUICtrlSetState($divBottom1, $GUI_HIDE)

                    GUICtrlSetData($tDownloadHead, "Download " & $App & " " & $verr & " Upgrade.")
                    GUICtrlSetData($tDownloadHead2, "Download the newest version of " & $App & ".")
                    GUICtrlSetData($tDownloadBody1, "Click Download to start the download for " & $App & " " & $verr & " Upgrade.")
                    GUICtrlSetState($bkg2, $GUI_SHOW)
                    GUICtrlSetState($divTop, $GUI_SHOW)
                    GUICtrlSetState($divBottom2, $GUI_SHOW)
                    GUICtrlSetState($tDownloadBody1, $GUI_SHOW)
                    GUICtrlSetState($tDownloadBody2, $GUI_SHOW)
                    GUICtrlSetState($tDownloadHead, $GUI_SHOW)
                    GUICtrlSetState($tDownloadHead2, $GUI_SHOW)
                    GUICtrlSetState($ProgressDownload, $GUI_SHOW)
                    GUICtrlSetData($but1, '&Download >')
                    GUICtrlSetState($but3, $GUI_SHOW)
                    $backto = 1
                    $goto = 2.5
                ElseIf $goto = 2.5 Then ;goto Stage 2.5: Download Upgrade
                    GUICtrlSetState($but1, $GUI_DISABLE)
                    GUICtrlSetState($but2, $GUI_DISABLE)
                    GUICtrlSetState($but3, $GUI_DISABLE)
                    Sleep(100)
                    GUICtrlSetState($but1, $GUI_HIDE)
                    GUICtrlSetState($but2, $GUI_HIDE)
                    GUICtrlSetState($but3, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    Sleep(100)
                    GUICtrlSetData($tDownloadBody1, "Downloading...")
                    DirCreate($file)
                    $StatusBar = _GUICtrlStatusBar_Create($gui)
                    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
                    Start_DL($url, $file)


                ElseIf $goto = 3 Then ;goto Stage 3: Launch upgrade.exe
                    GUICtrlSetState($but1, $GUI_SHOW)
                    GUICtrlSetData($but1, '&Install >')
                    GUICtrlSetState($but2, $GUI_SHOW)

                    GUICtrlSetState($but3, $GUI_SHOW)
                    Sleep(100)
                    GUICtrlSetState($but1, $GUI_ENABLE)
                    GUICtrlSetState($but1, $GUI_FOCUS)
                    GUICtrlSetState($but2, $GUI_ENABLE)
                    GUICtrlSetState($divBottom2, $GUI_SHOW)

                    GUICtrlSetState($tDownloadBody1, $GUI_HIDE)
                    GUICtrlSetState($tDownloadBody2, $GUI_HIDE)
                    GUICtrlSetState($tDownloadHead, $GUI_HIDE)
                    GUICtrlSetState($tDownloadHead2, $GUI_HIDE)
                    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
                    $goto = 4
                    $backto = 3

                EndIf


        EndSwitch
    WEnd



    _CheckProcess("AlbumMaker.exe", "RapidStudio")
    _KillProcess("AlbumFTPUploader.exe")
EndFunc   ;==>_Main

#Region -> Functions
Func _RegRead()
    RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "")
    If @error > 0 Then
        ;Key does not exist
        MsgBox(16, "RapidStudio Updater Message", "RapidStudio is not installed on this computer." & @CRLF & "Please call support on 011 225 0522 if you require assistance.", 5000)
        RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
        Exit
    Else
        ;Key does exist
        $appath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppFolder")
;~      MsgBox(4096, "Success", "RapidStudio is installed in the following directory:" & @CRLF & $appath) ; for testing
    EndIf
EndFunc   ;==>_RegRead

Func _CheckProcess($Process, $App)
    While ProcessExists($Process)
        If MsgBox(270389, "Error", "Please exit " & $App & " and try again.") = 2 Then
            If MsgBox(8196, "Cancel update", "Are you sure you want to cancel this update?") = 6 Then Exit
        EndIf
    WEnd
EndFunc   ;==>_CheckProcess

Func _KillProcess($Process)
    If ProcessExists($Process) Then
        ProcessClose($Process)
        ProcessWaitClose($Process)
    EndIf
EndFunc   ;==>_KillProcess

Func _CheckVersion($verl, $verr)
    $averl = StringSplit($verl, ".")
    $averr = StringSplit($verr, ".")
    If $verl = $verr Then
        $vStatus = 1
    ElseIf ($averl[1] < $averr[1]) Then
        $vStatus = 3
    ElseIf ($verl < $verr) Then
        $vStatus = 2
    EndIf
EndFunc   ;==>_CheckVersion


Func Start_DL($url, $file)
    If $url <> "" And $file <> "" Then
;~      $file &= "\" & "RapidStudio Upgrade.exe"
;~      $file &= "\" & "RapidStudio QuickSupport.exe"
        $file &= "\" & "RapidStudio testfile.exe"
        $nSize = InetGetSize($url)
        $hDownload = InetGet($url, $file, 1, 1)
        AdlibRegister("DL_Check", 50)
        $starttime = TimerInit()
    EndIf
EndFunc   ;==>Start_DL

Func DL_Check()
    If InetGetInfo($hDownload, 2) Then
        InetClose($hDownload)
        $nRead = $nSize
        $calc = Int(100 * $nRead / $nSize)
        GUICtrlSetData($ProgressDownload, $calc)
        _GUICtrlStatusBar_SetText($StatusBar, Round($nSize / 1024 / 1024, 2) & " MB" & @TAB & "100 %" & @TAB & $speed & " KBs / second")
        Sleep(2000)
        _GUICtrlStatusBar_Destroy($StatusBar)
        $goto = 3
        _GUICtrlButton_Click($but1)

    ElseIf $stop Then
        InetClose($hDownload)
;~      GUICtrlSetState($Start_DL, $GUI_ENABLE)
;~      GUICtrlSetState($Stop_DL, $GUI_DISABLE)
        GUICtrlSetData($ProgressDownload, 0)
        _GUICtrlStatusBar_SetText($StatusBar, "Ready")
        FileDelete($file)
        $stop = 0
        AdlibUnRegister("DL_Check")
    Else
        $nRead = InetGetInfo($hDownload, 0)
        $calc = Int(100 * $nRead / $nSize)
        GUICtrlSetData($ProgressDownload, $calc)
        $speed = Round(($nRead / 1024) / (_Timer_Diff($starttime) / 1000))
        _GUICtrlStatusBar_SetText($StatusBar, Round($nRead / 1024 / 1024, 2) & " / " & Round($nSize / 1024 / 1024, 2) & " MB" & @TAB & $calc & " %" & @TAB & $speed & " KBs / second")

    EndIf
EndFunc   ;==>DL_Check

Func Stop_DL()
    If MsgBox(8196, "Cancel", "Are you sure you want to cancel the download?") = 6 Then $stop = 1
EndFunc   ;==>Stop_DL

Func _Exit()
    If $nRead < $nSize Then
        If MsgBox(8196, "Exit", "The download is not complete. Are you sure you want to exit?") = 6 Then
            InetClose($hDownload)
            FileDelete($file)
            Exit
        EndIf
    Else
        Exit
    EndIf
EndFunc   ;==>_Exit

#EndRegion -> Functions
Edited by Fran

Share this post


Link to post
Share on other sites



Fran,

I think this does what you want: :graduated:

#include <GUIConstantsEx.au3>
#include <Constants.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

; Create a way to exit the script
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_On_Exit")
; St left click to reopen GUI
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_On_Tray_Show")
; Tray context menu can be opened by right click only
TraySetClick(16)

$hGUI = GUICreate("Test", 500, 500)

$hCancel_Button = GUICtrlCreateButton("Cancel", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        ; Either the [X] or the Cancel button hide the GUI
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

Func _On_Tray_Show()
    ; Left clicking the tray icon shows the GUI
    GUISetState(@SW_SHOW)
EndFunc

Func _On_Exit()
    ; Exit the script
    Exit
EndFunc

Are the comments clear enough? :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Perfect every time :(

Thanks a lot! I think I've got it now. :graduated:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0