|
using System;
using System.Windows.Forms;
using KeePass.Plugins;
namespace MinLock
{
public sealed class MinLockExt : Plugin
{
IPluginHost m_Host;
Timer m_Timer;
public override bool Initialize(IPluginHost host)
{
m_Host = host;
// Upon unlocking, the database is opened and this event fires;
// it likely fires other times too (e.g. opening db from menu).
m_Host.MainWindow.FileOpened += MainWindow_FileOpened;
return base.Initialize(host);
}
public override void Terminate()
{
KillTimer();
base.Terminate();
}
void KillTimer()
{
if (m_Timer != null)
{
m_Timer.Dispose();
m_Timer = null;
}
}
void MainWindow_FileOpened(object sender, KeePass.Forms.FileOpenedEventArgs e)
{
if (m_Timer == null && m_Host.MainWindow.WindowState == FormWindowState.Minimized)
{
// Start a Windows.Forms.Timer, because it's based on the event loop it
// can't interrupt current calls, though calls to Application.DoEvents
// could wreak havoc, but that doesn't appear to be a problem here.
m_Timer = new Timer();
m_Timer.Interval = 1;
m_Timer.Tick += Timer_Tick;
m_Timer.Start();
}
}
void Timer_Tick(object sender, EventArgs e)
{
KillTimer();
if (m_Host.MainWindow.WindowState == FormWindowState.Minimized &&
m_Host.MainWindow.IsAtLeastOneFileOpen())
{
m_Host.MainWindow.LockAllDocuments();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.