From 1fc6c8ed3b1a94a2e4619312e20373748771ba24 Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Thu, 28 Feb 2019 10:58:22 -0600 Subject: [PATCH] Resolves #178 --- GBM/Forms/frmMain.vb | 52 ++++++++++++++++++++++++--- GBM/Forms/frmSettings.vb | 53 +++++++++++++++++++++------- GBM/My Project/Resources.Designer.vb | 18 ++++++++++ GBM/My Project/Resources.resx | 6 ++++ 4 files changed, 113 insertions(+), 16 deletions(-) diff --git a/GBM/Forms/frmMain.vb b/GBM/Forms/frmMain.vb index 0403a90..f17c515 100644 --- a/GBM/Forms/frmMain.vb +++ b/GBM/Forms/frmMain.vb @@ -53,6 +53,7 @@ Public Class frmMain WithEvents tmScanTimer As New Timer WithEvents tmRestoreCheck As New System.Timers.Timer WithEvents tmFileWatcherQueue As New System.Timers.Timer + WithEvents tmMinimizeTimer As New System.Timers.Timer Public WithEvents oProcess As New mgrProcessDetection Public WithEvents oBackup As New mgrBackup @@ -1180,8 +1181,14 @@ Public Class frmMain 'Verify the "Start with Windows" setting If oSettings.StartWithWindows Then - If Not VerifyStartWithWindows() Then - UpdateLog(frmMain_ErrorAppLocationChanged, False, ToolTipIcon.Info) + If mgrCommon.IsUnix Then + If Not VerifyAutoStartLinux() Then + UpdateLog(frmMain_ErrorLinuxAutoStartMissing, False, ToolTipIcon.Info) + End If + Else + If Not VerifyStartWithWindows() Then + UpdateLog(frmMain_ErrorAppLocationChanged, False, ToolTipIcon.Info) + End If End If End If @@ -1735,6 +1742,33 @@ Public Class frmMain End If End Sub + Private Function VerifyAutoStartLinux() 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) + 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 + Return False + End If + End Function + Private Function VerifyStartWithWindows() As Boolean Dim oKey As Microsoft.Win32.RegistryKey Dim sAppName As String = Application.ProductName @@ -1944,6 +1978,10 @@ Public Class frmMain End Sub + Private Sub HandleMinimizeTimer() Handles tmMinimizeTimer.Elapsed + Me.WindowState = FormWindowState.Minimized + End Sub + Private Sub AutoRestoreEventProcessor(myObject As Object, ByVal myEventArgs As EventArgs) Handles tmRestoreCheck.Elapsed If eCurrentStatus <> eStatus.Paused Then AutoRestoreCheck() @@ -2133,12 +2171,18 @@ Public Class frmMain 'Unix Handler 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. + 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 - If mgrCommon.ShowMessage(frmMain_ErrorInitFailure, ex.Message, MsgBoxStyle.YesNo) = MsgBoxResult.No Then + If mgrCommon.ShowMessage(frmMain_ErrorInitFailure, ex.Message & vbCrLf & ex.StackTrace, MsgBoxStyle.YesNo) = MsgBoxResult.No Then bInitFail = True End If End Try diff --git a/GBM/Forms/frmSettings.vb b/GBM/Forms/frmSettings.vb index f2cd1a4..16eaeb5 100644 --- a/GBM/Forms/frmSettings.vb +++ b/GBM/Forms/frmSettings.vb @@ -16,6 +16,35 @@ Public Class frmSettings End Set End Property + Private Sub HandleLinuxAutoStart(ByVal bToggle As Boolean) + Dim oProcess As Process + Dim sAutoStartFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & Path.DirectorySeparatorChar & ".config/autostart/" + + If bToggle Then + '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 + Else + 'Delete link + If File.Exists(sAutoStartFolder & Path.DirectorySeparatorChar & "gbm.desktop") Then + File.Delete(sAutoStartFolder & Path.DirectorySeparatorChar & "gbm.desktop") + End If + End If + End Sub + Private Sub HandleRegistryUpdate(ByVal bToggle As Boolean) Dim oKey As Microsoft.Win32.RegistryKey Dim sAppName As String = Application.ProductName @@ -35,13 +64,17 @@ Public Class frmSettings Private Function ValidateSettings() As Boolean 'Show Start with Windows warning if running as admin - If chkAutoStart.Checked And mgrCommon.IsElevated Then + If Not mgrCommon.IsUnix And chkAutoStart.Checked And mgrCommon.IsElevated Then mgrCommon.ShowMessage(frmSettings_WarningAdminStart, MsgBoxStyle.Exclamation) End If - 'Only modify registry key when the value changed + 'Only modify when the value changed If chkAutoStart.Checked <> oSettings.StartWithWindows Then - HandleRegistryUpdate(chkAutoStart.Checked) + If mgrCommon.IsUnix Then + HandleLinuxAutoStart(chkAutoStart.Checked) + Else + HandleRegistryUpdate(chkAutoStart.Checked) + End If End If oSettings.StartWithWindows = chkAutoStart.Checked @@ -201,12 +234,6 @@ Public Class frmSettings txt7zLocation.Text = oSettings.Custom7zLocation eCurrentSyncFields = oSettings.SyncFields - 'Unix Handler - If mgrCommon.IsUnix Then - chkStartMinimized.Checked = False - chkAutoStart.Checked = False - End If - 'Retrieve 7z Info GetUtilityInfo(oSettings.Custom7zLocation) @@ -329,10 +356,12 @@ Public Class frmSettings chkShowResolvedPaths.Text = frmSettings_chkShowResolvedPaths chkDisableDiskSpaceCheck.Text = frmSettings_chkDisableDiskSpaceCheck - 'Unix Handler If mgrCommon.IsUnix Then - chkStartMinimized.Enabled = False - chkAutoStart.Enabled = False + 'Only enable these options 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 'Handle Panels diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index 23073a1..b39afad 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 autostart link is missing. The autostart link has been re-created.. + ''' + Friend ReadOnly Property frmMain_ErrorLinuxAutoStartMissing() As String + Get + Return ResourceManager.GetString("frmMain_ErrorLinuxAutoStartMissing", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to The command [PARAM] requires more parameters.. ''' @@ -4857,6 +4866,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to An error occured while creating the autostart link:[BR][BR][PARAM]. + ''' + Friend ReadOnly Property frmSettings_ErrorLinuxAutoStart() As String + Get + Return ResourceManager.GetString("frmSettings_ErrorLinuxAutoStart", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to The custom 7-Zip location [PARAM] does not exist.. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 5681985..0ce53fa 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -2341,4 +2341,10 @@ Disable disk space check prior to backup + + 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] + \ No newline at end of file