Skip to content

Commit

Permalink
Integrate (Un)lock workspace into Quick Unlock
Browse files Browse the repository at this point in the history
Added the option to skip global unlock in Quick Unlock Form
  • Loading branch information
Rookiestyle committed Aug 31, 2021
1 parent 5ad20d6 commit 3389529
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 27 deletions.
17 changes: 10 additions & 7 deletions src/LockAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ private void OnKeyFormShown(object sender, EventArgs e)
{
Form f = sender as Form;
if (f == null) return;
if ((f is KeyPromptForm) && LockWorkspace.ShallStopGlobalUnlock())
if (LockAssistConfig.LW_Active)
{
GlobalWindowManager.RemoveWindow(sender as Form);
f.Close();
f.Dispose();
_lw.OnEnhancedWorkspaceLockUnlock(sender, null);
return;
if ((f is KeyPromptForm) && LockWorkspace.ShallStopGlobalUnlock())
{
GlobalWindowManager.RemoveWindow(sender as Form);
f.Close();
f.Dispose();
_lw.OnEnhancedWorkspaceLockUnlock(sender, null);
return;
}
LockWorkspace.OnKeyFormShown(f, e);
}
LockWorkspace.OnKeyFormShown(f, e);
QuickUnlock.OnKeyFormShown(f, false);
}

Expand Down
43 changes: 28 additions & 15 deletions src/LockWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace LockAssist
{
internal class LockWorkspace
{
internal const string c_LockAssistContinueUnlockWorkbench = "cbLockAssistContinueUnlockWorkbench";
internal static bool m_bContinueUnlock = false;
private const string c_LockAssistContinueUnlockWorkbench = "cbLockAssistContinueUnlockWorkbench";
private static bool m_bContinueUnlock = false;
private Dictionary<Component, EventHandlerList> m_EventHandlerList = new Dictionary<Component, EventHandlerList>();
private Dictionary<Component, EventHandlers> m_EventHandlers = new Dictionary<Component, EventHandlers>();
private static MethodInfo miIsCommandTypeInvokable = null;
Expand Down Expand Up @@ -100,30 +100,31 @@ private void Init()
if (LockAssistConfig.LW_Active) ActivateNewLockWorkspace(LockAssistConfig.LW_Active);
}

private static CheckBox m_cbContinueUnlock = null;
internal static void OnKeyFormShown(object sender, EventArgs e)
{
if (!LockAssistConfig.LW_Active) return;
if (!m_bContinueUnlock) return;

KeyPromptForm fKeyPromptForm = sender as KeyPromptForm;
if (fKeyPromptForm == null) return;

//Create checkbox to continue/stop global unlock
CheckBox cbContinueUnlock = new CheckBox();
cbContinueUnlock.AutoSize = true;
cbContinueUnlock.Text = KeePass.Resources.KPRes.LockMenuUnlock;
cbContinueUnlock.Checked = true;
cbContinueUnlock.Name = c_LockAssistContinueUnlockWorkbench;
cbContinueUnlock.CheckedChanged += (o1, e1) => { m_bContinueUnlock = cbContinueUnlock.Checked; };
cbContinueUnlock.Checked = cbContinueUnlock.Checked;
m_cbContinueUnlock = new CheckBox();
m_cbContinueUnlock.AutoSize = true;
m_cbContinueUnlock.Text = KeePass.Resources.KPRes.LockMenuUnlock;
m_cbContinueUnlock.Checked = true;
m_cbContinueUnlock.Name = c_LockAssistContinueUnlockWorkbench;
m_cbContinueUnlock.CheckedChanged += (o1, e1) => { SetContinueUnlock(m_cbContinueUnlock.Checked); };
m_cbContinueUnlock.Checked = m_cbContinueUnlock.Checked;

//calculate checkbox position
CheckBox m_cbKeyFile = (CheckBox)Tools.GetControl("m_cbKeyFile", fKeyPromptForm);
CheckBox cbAccount = (CheckBox)Tools.GetControl("m_cbUserAccount", fKeyPromptForm);
cbContinueUnlock.Left = cbAccount.Left;
m_cbContinueUnlock.Left = cbAccount.Left;
int iIncrement = cbAccount.Top - m_cbKeyFile.Top;
cbContinueUnlock.Top = cbAccount.Top + iIncrement;
cbContinueUnlock.TabIndex = cbAccount.TabIndex + 1;
m_cbContinueUnlock.Top = cbAccount.Top + iIncrement;
m_cbContinueUnlock.TabIndex = cbAccount.TabIndex + 1;

//Adjust position of all relevent controls
cbAccount.Parent.Height += iIncrement;
Expand All @@ -133,10 +134,10 @@ internal static void OnKeyFormShown(object sender, EventArgs e)
c.Top += iIncrement;
c.TabIndex++;
}
cbAccount.Parent.Controls.Add(cbContinueUnlock);
cbAccount.Parent.Controls.Add(m_cbContinueUnlock);
}

internal void Clear()
internal void Clear()
{
ActivateNewLockWorkspace(false);
}
Expand Down Expand Up @@ -287,6 +288,18 @@ internal static bool ShallStopGlobalUnlock()
PluginDebug.AddInfo("StopGlobalUnlock", 0, lMethods.ToArray());
return bStop;
}

internal static void SetContinueUnlock(bool bContinue)
{
if (m_bContinueUnlock == bContinue) return;
m_bContinueUnlock = bContinue;
if (m_cbContinueUnlock != null) m_cbContinueUnlock.Checked = bContinue;
}

internal static bool GetContinueUnlock()
{
return LockAssistConfig.LW_Active && m_bContinueUnlock;
}
}


Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1")]
[assembly: AssemblyFileVersion("2.1")]
[assembly: AssemblyVersion("2.2")]
[assembly: AssemblyFileVersion("2.2")]
16 changes: 15 additions & 1 deletion src/UnlockForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/UnlockForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public UnlockForm()
KeePass.UI.SecureTextBoxEx.InitEx(ref stbPIN);
cbTogglePin.Checked = true;
stbPIN.EnableProtection(cbTogglePin.Checked);

cbContinueUnlock.Text = KeePass.Resources.KPRes.LockMenuUnlock;
cbContinueUnlock.Visible = cbContinueUnlock.Checked = LockWorkspace.GetContinueUnlock();
}

public ProtectedString QuickUnlockKey
Expand All @@ -40,5 +43,10 @@ private void togglePIN_CheckedChanged(object sender, System.EventArgs e)
{
stbPIN.EnableProtection(cbTogglePin.Checked);
}
}

private void cbContinueUnlock_CheckedChanged(object sender, System.EventArgs e)
{
LockWorkspace.SetContinueUnlock(cbContinueUnlock.Checked);
}
}
}
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:
LockAssist:2.1
LockAssist:2.2
LockAssist!de:3
:

0 comments on commit 3389529

Please sign in to comment.