From 7fa0c66ca1e37737ab9fd28c9b33b70aebfb4e93 Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Sat, 9 Mar 2019 09:20:37 -0600 Subject: [PATCH] Fixed some autostart issues #178 --- GBM/Forms/frmMain.vb | 58 +++++++++++++++++++--------- GBM/Forms/frmSettings.vb | 3 +- GBM/My Project/Resources.Designer.vb | 11 +++++- GBM/My Project/Resources.resx | 5 ++- 4 files changed, 54 insertions(+), 23 deletions(-) diff --git a/GBM/Forms/frmMain.vb b/GBM/Forms/frmMain.vb index 35af90f..c3094d9 100644 --- a/GBM/Forms/frmMain.vb +++ b/GBM/Forms/frmMain.vb @@ -1186,8 +1186,9 @@ Public Class frmMain 'Verify the "Start with Windows" setting If oSettings.StartWithWindows Then If mgrCommon.IsUnix Then - If Not VerifyAutoStartLinux() Then - UpdateLog(frmMain_ErrorLinuxAutoStartMissing, False, ToolTipIcon.Info) + Dim sVerifyError As String = String.Empty + If Not VerifyAutoStartLinux(sVerifyError) Then + UpdateLog(sVerifyError, False, ToolTipIcon.Info) End If Else If Not VerifyStartWithWindows() Then @@ -1746,29 +1747,48 @@ Public Class frmMain End If End Sub - Private Function VerifyAutoStartLinux() As Boolean + Private Function VerifyAutoStartLinux(ByRef sErrorMessage As String) As Boolean Dim oProcess As Process Dim sAutoStartFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & Path.DirectorySeparatorChar & ".config/autostart/" - If File.Exists(sAutoStartFolder & Path.DirectorySeparatorChar & "gbm.desktop") Then - Return True - Else - 'Create the autostart folder if it doesn't exist yet - If Not Directory.Exists(sAutoStartFolder) Then - Directory.CreateDirectory(sAutoStartFolder) + 'Check if the app is still properly installed + If File.Exists("/usr/share/applications/gbm.desktop") Then + If File.Exists(sAutoStartFolder & Path.DirectorySeparatorChar & "gbm.desktop") Then + Return True + Else + 'Create the autostart folder if it doesn't exist yet + If Not Directory.Exists(sAutoStartFolder) Then + Directory.CreateDirectory(sAutoStartFolder) + End If + 'Create link + Try + oProcess = New Process + oProcess.StartInfo.FileName = "/bin/ln" + oProcess.StartInfo.Arguments = "-s /usr/share/applications/gbm.desktop " & sAutoStartFolder + oProcess.StartInfo.UseShellExecute = False + oProcess.StartInfo.RedirectStandardOutput = True + oProcess.StartInfo.CreateNoWindow = True + oProcess.Start() + Catch ex As Exception + mgrCommon.ShowMessage(frmSettings_ErrorLinuxAutoStart, ex.Message, MsgBoxStyle.Exclamation) + End Try + + sErrorMessage = frmMain_ErrorLinuxAutoStartMissing + Return False End If - 'Create link + Else + 'If the app is no longer properly installed, disable autostart and the setting. Try - oProcess = New Process - oProcess.StartInfo.FileName = "/bin/ln" - oProcess.StartInfo.Arguments = "-s /usr/share/applications/gbm.desktop " & sAutoStartFolder - oProcess.StartInfo.UseShellExecute = False - oProcess.StartInfo.RedirectStandardOutput = True - oProcess.StartInfo.CreateNoWindow = True - oProcess.Start() + oSettings.StartWithWindows = False + oSettings.SaveSettings() + If File.Exists(sAutoStartFolder & Path.DirectorySeparatorChar & "gbm.desktop") Then + File.Delete(sAutoStartFolder & Path.DirectorySeparatorChar & "gbm.desktop") + End If Catch ex As Exception mgrCommon.ShowMessage(frmSettings_ErrorLinuxAutoStart, ex.Message, MsgBoxStyle.Exclamation) End Try + + sErrorMessage = frmMain_ErrorLinuxAutoStartLinkMissing Return False End If End Function @@ -2176,13 +2196,13 @@ Public Class frmMain If mgrCommon.IsUnix Then Me.MinimizeBox = True If oSettings.StartToTray Then - 'Window Managers and/or Mono will not trigger a minimize in the Load or Shown event. We need to delay it. + 'Window Managers and/or Mono will not trigger a minimize in the Load or Shown event. We need to delay it. tmMinimizeTimer.AutoReset = False tmMinimizeTimer.Interval = 1000 tmMinimizeTimer.Start() End If Else - Me.gMonTray.Visible = True + Me.gMonTray.Visible = True End If End If Catch ex As Exception diff --git a/GBM/Forms/frmSettings.vb b/GBM/Forms/frmSettings.vb index 16eaeb5..a9e4a0e 100644 --- a/GBM/Forms/frmSettings.vb +++ b/GBM/Forms/frmSettings.vb @@ -357,9 +357,8 @@ Public Class frmSettings chkDisableDiskSpaceCheck.Text = frmSettings_chkDisableDiskSpaceCheck If mgrCommon.IsUnix Then - 'Only enable these options on Linux if GBM was installed with an official method + 'Only enable this option on Linux if GBM was installed with an official method If Not File.Exists("/usr/share/applications/gbm.desktop") Then - chkStartMinimized.Enabled = False chkAutoStart.Enabled = False End If End If diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index e6b3f8a..442892c 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -3309,6 +3309,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to GBM is set to start automatically, but the desktop link is missing. Automatic start has been disabled, please re-install GBM using a package manager.. + ''' + Friend ReadOnly Property frmMain_ErrorLinuxAutoStartLinkMissing() As String + Get + Return ResourceManager.GetString("frmMain_ErrorLinuxAutoStartLinkMissing", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to GBM is set to start automatically, but the autostart link is missing. The autostart link has been re-created.. ''' @@ -4867,7 +4876,7 @@ Namespace My.Resources End Property ''' - ''' Looks up a localized string similar to An error occured while creating the autostart link:[BR][BR][PARAM]. + ''' Looks up a localized string similar to An error occured while configuring autostart:[BR][BR][PARAM]. ''' Friend ReadOnly Property frmSettings_ErrorLinuxAutoStart() As String Get diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 9fd943c..8317101 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -2345,7 +2345,7 @@ GBM is set to start automatically, but the autostart link is missing. The autostart link has been re-created. - An error occured while creating the autostart link:[BR][BR][PARAM] + An error occured while configuring autostart:[BR][BR][PARAM] [PARAM] stores saved games in the Windows registry, accessing the registry requires elevated permissions. Please restart GBM as Administrator to perform this backup. @@ -2368,4 +2368,7 @@ [PARAM] stores saved games in the Windows registry, accessing the registry requires elevated permissions. Please restart GBM as Administrator to restore this backup. + + GBM is set to start automatically, but the desktop link is missing. Automatic start has been disabled, please re-install GBM using a package manager. + \ No newline at end of file