@@ -815,7 +815,7 @@ function installAppMenu(): void {
815815 {
816816 label : 'Check for Updates…' ,
817817 click : ( ) => {
818- void checkForAppUpdates ( )
818+ void runMenuUpdateCheck ( )
819819 }
820820 } ,
821821 { type : 'separator' } ,
@@ -878,6 +878,86 @@ function installAppMenu(): void {
878878 Menu . setApplicationMenu ( Menu . buildFromTemplate ( template ) )
879879}
880880
881+ async function runMenuUpdateCheck ( ) : Promise < void > {
882+ const parent = BrowserWindow . getFocusedWindow ( ) ?? mainWindow ?? undefined
883+ const showDialog = async (
884+ options : Electron . MessageBoxOptions
885+ ) : Promise < Electron . MessageBoxReturnValue > => {
886+ return parent
887+ ? await dialog . showMessageBox ( parent , options )
888+ : await dialog . showMessageBox ( options )
889+ }
890+ const state = await checkForAppUpdates ( )
891+
892+ if ( state . phase === 'available' ) {
893+ const { response } = await showDialog ( {
894+ type : 'info' ,
895+ buttons : [ 'Download Update' , 'Later' ] ,
896+ defaultId : 0 ,
897+ cancelId : 1 ,
898+ title : 'ZenNotes Update Available' ,
899+ message : `ZenNotes ${ state . availableVersion ?? '' } is available.` ,
900+ detail : state . message
901+ } )
902+ if ( response === 0 ) {
903+ void downloadAppUpdate ( )
904+ await showDialog ( {
905+ type : 'info' ,
906+ buttons : [ 'OK' ] ,
907+ defaultId : 0 ,
908+ title : 'Downloading Update' ,
909+ message : `ZenNotes ${ state . availableVersion ?? '' } is downloading in the background.` ,
910+ detail : 'Open Settings → About to track progress and install when the download finishes.'
911+ } )
912+ }
913+ return
914+ }
915+
916+ if ( state . phase === 'downloaded' ) {
917+ const { response } = await showDialog ( {
918+ type : 'info' ,
919+ buttons : [ 'Install and Relaunch' , 'Later' ] ,
920+ defaultId : 0 ,
921+ cancelId : 1 ,
922+ title : 'ZenNotes Update Ready' ,
923+ message : `ZenNotes ${ state . availableVersion ?? '' } is ready to install.` ,
924+ detail : state . message
925+ } )
926+ if ( response === 0 ) {
927+ installAppUpdate ( )
928+ }
929+ return
930+ }
931+
932+ if ( state . phase === 'downloading' || state . phase === 'checking' ) {
933+ await showDialog ( {
934+ type : 'info' ,
935+ buttons : [ 'OK' ] ,
936+ defaultId : 0 ,
937+ title : 'ZenNotes Updates' ,
938+ message : state . phase === 'checking' ? 'Checking for updates…' : 'Downloading update…' ,
939+ detail : state . message
940+ } )
941+ return
942+ }
943+
944+ await showDialog ( {
945+ type : state . phase === 'error' ? 'warning' : 'info' ,
946+ buttons : [ 'OK' ] ,
947+ defaultId : 0 ,
948+ title : 'ZenNotes Updates' ,
949+ message :
950+ state . phase === 'not-available'
951+ ? 'ZenNotes is up to date.'
952+ : state . phase === 'unsupported'
953+ ? 'Update checks are unavailable.'
954+ : state . phase === 'error'
955+ ? 'Could not check for updates.'
956+ : 'ZenNotes Updates' ,
957+ detail : state . message
958+ } )
959+ }
960+
881961app . whenReady ( ) . then ( async ( ) => {
882962 protocol . handle ( LOCAL_ASSET_SCHEME , async ( request ) => {
883963 const abs = decodeLocalAssetRequestPath ( request . url )
0 commit comments