1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00

[KOE-14] Secondary contacts are now displayed with the correct icon and start syncing. This means the restart is now less urgent, hence the warning has been modified. Also added a debug option to disable the warning. If the dialog is used to restart Outlook, it will now close any open KOE forms.

This commit is contained in:
Patrick Simpson 2017-02-27 16:04:42 +01:00
parent e98240ab47
commit ad03e67961
6 changed files with 92 additions and 47 deletions

View File

@ -79,7 +79,7 @@ namespace Acacia.Features.DebugSupport
{
timer.Stop();
dlg.Hide();
ThisAddIn.Instance.Quit();
ThisAddIn.Instance.Quit(false);
}
else
{

View File

@ -34,6 +34,19 @@ namespace Acacia.Features.SecondaryContacts
[AcaciaOption("Provides the possibility to synchronise multiple contacts folders to and from a Z-Push server.")]
public class FeatureSecondaryContacts : Feature
{
#region Debug options
[AcaciaOption("If set (the default), a warning will be shown when a secondary contact folder is discovered, " +
"which shows that Outlook must be restarted to add it to the proper list.")]
public bool WarnRestart
{
get { return GetOption(OPTION_WARN_RESTART); }
set { SetOption(OPTION_WARN_RESTART, value); }
}
private static readonly BoolOption OPTION_WARN_RESTART = new BoolOption("WarnRestart", true);
#endregion
private const string SUFFIX_CONTACTS = "\x200B";
private class FolderRegistrationSecondaryContacts : FolderRegistration
@ -71,7 +84,7 @@ namespace Acacia.Features.SecondaryContacts
{
Watcher.WatchFolder(new FolderRegistrationSecondaryContacts(this), OnUnpatchedFolderDiscovered);
}
private void OnUnpatchedFolderDiscovered(IFolder folder)
{
string strippedName = folder.Name.StripSuffix(SUFFIX_CONTACTS);
@ -84,10 +97,9 @@ namespace Acacia.Features.SecondaryContacts
// Note that the above steps need to be done in this order and individually for this to work.
//
// At some point after 2 we also need to restart Outlook to make it appear in the list of contact folders.
// So, when the folder is detected, we make it invisible and perform steps 1 and 2. We issue a warning
// that Outlook must be restarted. When the folder is detected again and is invisible, that means we've restarted
// At this point the name is patched and the folder is made visible.
if (!folder.AttrHidden)
// Somehow some properties fail if we do it in the event handler, post to ui thread
ThisAddIn.Instance.InUI(() =>
{
// Stage 1
@ -99,33 +111,37 @@ namespace Acacia.Features.SecondaryContacts
Logger.Instance.Trace(this, "Setting container class");
folder.SetProperty(OutlookConstants.PR_CONTAINER_CLASS, "IPF.Contact");
// Make it invisible.
folder.AttrHidden = true;
folder.Save();
Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName);
WarnRestart(folder);
}
// If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted.
else if (!_warnedFolders.Contains(folder.EntryID))
{
// Stage 2
// Update the icon.
using (IExplorer explorer = ThisAddIn.Instance.GetActiveExplorer())
using (ICommandBars cmdBars = explorer.GetCommandBars())
{
folder.SetCustomIcon(cmdBars.GetMso("ShowContactPage").GetPicture(new Size(16, 16)));
}
// Patch the name
Logger.Instance.Trace(this, "Patching name");
folder.Name = strippedName;
folder.ShowAsOutlookAB = true;
// Save the folder
folder.Save();
// Do another send receive to start syncing
ThisAddIn.Instance.SendReceive();
// Warn about a restart
DoWarnRestart(folder);
}, false);
// Show it
folder.AttrHidden = false;
Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName);
}
Logger.Instance.Debug(this, "Patching done: {0}: {1}", strippedName, folder.AttrHidden);
}
private DateTime? _lastWarning;
private void WarnRestart(IFolder folder)
private bool DoWarnRestart(IFolder folder)
{
if (!WarnRestart)
return false;
// Register and show a warning, if not already done.
// Note that patching may be done multiple times.
if (!_warnedFolders.Contains(folder.EntryID))
@ -139,13 +155,15 @@ namespace Acacia.Features.SecondaryContacts
if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", folder.Name),
StringUtil.GetResourceString("SecondaryContactsPatched_Title"),
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning
MessageBoxIcon.Information
) == DialogResult.Yes)
{
ThisAddIn.Instance.Restart();
ThisAddIn.Instance.Restart(true);
return true;
}
}
}
return false;
}
}
}

View File

@ -813,7 +813,7 @@ namespace Acacia.Properties {
}
/// <summary>
/// Looks up a localized string similar to To synchronise the contacts folder &apos;{0}&apos;, Outlook must be restarted. Click &apos;Yes&apos; to restart Outlook now, or &apos;No&apos; if you plan to restart Outlook later..
/// Looks up a localized string similar to The contacts folder &apos;{0}&apos; has been discovered. It is being synchronised, but will not show up in the list of contacts folders until Outlook is restarted. Click &apos;Yes&apos; to restart Outlook now, or &apos;No&apos; if you plan to restart Outlook later..
/// </summary>
internal static string SecondaryContactsPatched_Body {
get {

View File

@ -432,7 +432,7 @@
<value>Shows the about dialog, which contains licensing and version information.</value>
</data>
<data name="SecondaryContactsPatched_Body" xml:space="preserve">
<value>To synchronise the contacts folder '{0}', Outlook must be restarted. Click 'Yes' to restart Outlook now, or 'No' if you plan to restart Outlook later.</value>
<value>The contacts folder '{0}' has been discovered. It is being synchronised, but will not show up in the list of contacts folders until Outlook is restarted. Click 'Yes' to restart Outlook now, or 'No' if you plan to restart Outlook later.</value>
<comment>Shown when a secondary contact folder is detected, to inform the user that a restart is required</comment>
</data>
<data name="SecondaryContactsPatched_Title" xml:space="preserve">

View File

@ -65,8 +65,8 @@ namespace Acacia.Stubs
/// <summary>
/// Restarts the application
/// </summary>
void Restart();
void Quit();
void Restart(bool closeWindows);
void Quit(bool closeWindows);
void InvokeUI(Action action);
@ -89,7 +89,7 @@ namespace Acacia.Stubs
ISignatures GetSignatures();
void InUI(Action action);
void InUI(Action action, bool synchronous = true);
bool IsOffline { get; }
}

View File

@ -84,23 +84,40 @@ namespace Acacia.Stubs.OutlookWrappers
}
}
public void InUI(Action action)
public void InUI(Action action, bool synchronous = true)
{
Exception x = null;
_sync.Send((_) =>
if (synchronous)
{
try
Exception x = null;
_sync.Send((_) =>
{
action();
}
catch(Exception e)
{
x = e;
}
}, null);
try
{
action();
}
catch (Exception e)
{
x = e;
}
}, null);
if (x != null)
throw x;
if (x != null)
throw x;
}
else
{
_sync.Post((_) =>
{
try
{
action();
}
catch (Exception e)
{
Logger.Instance.Error(this, "Unhandled exception in UI post: {0}", e);
}
}, null);
}
}
public void SendReceive(IAccount account)
@ -122,7 +139,7 @@ namespace Acacia.Stubs.OutlookWrappers
_stores.Start();
}
public void Restart()
public void Restart(bool closeWindows)
{
// Can not use the assembly location, as that is in the GAC
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
@ -136,12 +153,22 @@ namespace Acacia.Stubs.OutlookWrappers
process.StartInfo = new ProcessStartInfo(path, Environment.CommandLine);
process.Start();
// And close us
_app.Quit();
// And close us and any other windows
Quit(closeWindows);
}
public void Quit()
public void Quit(bool closeWindows)
{
if (closeWindows)
{
List<Form> openForms = new List<Form>();
foreach (Form f in Application.OpenForms)
openForms.Add(f);
foreach (Form f in openForms)
f.Close();
}
_app.Quit();
}