Skip to content

Commit

Permalink
- Added SMA Setup screen
Browse files Browse the repository at this point in the history
- Added Pugin Setup
- Added License agreement
- Plugin Manager is now initialized on startup (but plugins are still run after SM has started)
- Plugin enabled/Disabled is temporarily hidden
- Remove Hint Pattern from the option UI
- Added SMA update notifications
- Improved Documentation
- Several other fixes & additions
  • Loading branch information
alexis- committed Mar 12, 2020
1 parent 51146a4 commit 48e2176
Show file tree
Hide file tree
Showing 68 changed files with 3,563 additions and 904 deletions.
194 changes: 183 additions & 11 deletions SuperMemoAssistant.sln

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions SuperMemoAssistant.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,11 @@ public static $name$ Instance { get; } = new $name$();</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Anotar/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Behaviours/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cloze/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=functionalities/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hkcu/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=homonymous/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hotkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ISMA/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=marshalled/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mems/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Metadatas/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -765,4 +767,5 @@ public static $name$ Instance { get; } = new $name$();</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prerelease/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=quotify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=showlogs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unfocusable/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion libs/MSBuild.Tools
2 changes: 1 addition & 1 deletion libs/Squirrel.Windows
9 changes: 5 additions & 4 deletions src/AppHosts/SuperMemoAssistant/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

<ResourceDictionary Source="pack://application:,,,/SuperMemoAssistant.Core;component/SMA/UI/DataTemplates/PluginInstanceDataTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type ListBoxItem}">

<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource MetroListBoxItem}">
<Setter Property="mah:ItemHelper.ActiveSelectionBackgroundBrush" Value="{DynamicResource AccentColorBrush3}" />
<Setter Property="mah:ItemHelper.HoverBackgroundBrush" Value="{DynamicResource AccentColorBrush4}" />
<Setter Property="Focusable" Value="True" />
</Style>
<Style x:Key="UnfocusableListBoxItem" TargetType="{x:Type ListBoxItem}">

<Style x:Key="UnfocusableListBoxItem" TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource MetroListBoxItem}">
<Setter Property="mah:ItemHelper.ActiveSelectionBackgroundBrush" Value="{DynamicResource AccentColorBrush3}" />
<Setter Property="mah:ItemHelper.HoverBackgroundBrush" Value="{DynamicResource AccentColorBrush4}" />
<Setter Property="Focusable" Value="False" />
Expand All @@ -36,6 +36,7 @@
<Style x:Key="SMAButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MetroButton}">
<Setter Property="FontSize" Value="13" />
<Setter Property="FontWeight" Value="DemiBold" />
<Setter Property="Padding" Value="16 8 16 8" />
</Style>

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource SMAButton}">
Expand Down
28 changes: 14 additions & 14 deletions src/AppHosts/SuperMemoAssistant/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
using SuperMemoAssistant.Models;
using SuperMemoAssistant.Services.UI.Extensions;
using SuperMemoAssistant.Setup;
using SuperMemoAssistant.SMA.UI.DataTemplates;
using SuperMemoAssistant.SMA.Utils;
using SuperMemoAssistant.Sys.Windows;
using SuperMemoAssistant.UI;

namespace SuperMemoAssistant
Expand Down Expand Up @@ -99,7 +99,7 @@ private async Task LoadApp(SMAParameters args)
if (SMAInstaller.HandleEvent(args, out var firstRun))
{
if (firstRun)
await "SuperMemo Assistant has been successfully installed.".MsgBox("Installation");
MessageBox.Show("SuperMemo Assistant has been successfully installed.", "Installation success");

Shutdown();
return;
Expand Down Expand Up @@ -128,21 +128,22 @@ private async Task LoadApp(SMAParameters args)
Shutdown(SMAExitCodes.ExitCodeConfigError);
return;
}

SMA.Core.CoreConfig = coreCfg;

//
// Make sure SuperMemo exe path is correct. Prompt user to input the path otherwise.
if (SMASetup.ShouldFindSuperMemo(coreCfg, nativeDataCfg))
{
var smFinder = new Setup.SuperMemoFinder(nativeDataCfg, coreCfg);
smFinder.ShowDialog();
// Setup toast notifications (TODO: setup ToastActivatorCLSID on shortcut https://github.com/WindowsNotifications/desktop-toasts/blob/472a3f9f5849fbc62bf5cad769421d4299c47f51/CS/DesktopToastsSetupProject/Product.wxs)
DesktopNotificationManager.RegisterAumidAndComServer<SMANotificationActivator>("SuperMemoAssistant");
DesktopNotificationManager.RegisterActivator<SMANotificationActivator>();

if (smFinder.DialogResult == null || smFinder.DialogResult == false)
{
LogTo.Warning(errMsg);
//
// Check if SMA is setup, and run the setup wizard if it isn't
if (SMASetup.Run(nativeDataCfg, coreCfg) == false)
{
LogTo.Warning("SMA Setup canceled. Exiting.");

Shutdown(SMAExitCodes.ExitCodeSMExeError);
return;
}
Shutdown(SMAExitCodes.ExitCodeSMASetupError);
return;
}

//
Expand Down Expand Up @@ -177,7 +178,6 @@ private async Task LoadApp(SMAParameters args)
if (smCollection != null)
{
SMA.Core.SMA.OnSMStoppedEvent += OnSMStoppedEvent;
SMA.Core.CoreConfig = coreCfg;

if (await SMA.Core.SMA.Start(nativeDataCfg, smCollection).ConfigureAwait(true) == false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AppHosts/SuperMemoAssistant/FodyWeavers.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ModuleInit" minOccurs="0" maxOccurs="1" type="xs:anyType" />
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
Expand Down Expand Up @@ -35,6 +34,7 @@
</xs:complexType>
</xs:element>
<xs:element name="Anotar.Serilog" minOccurs="0" maxOccurs="1" type="xs:anyType" />
<xs:element name="ModuleInit" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
Expand Down
61 changes: 60 additions & 1 deletion src/AppHosts/SuperMemoAssistant/Installer/SMAInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Anotar.Serilog;
using Microsoft.Toolkit.Uwp.Notifications;
using Nito.AsyncEx;
using Serilog;
using Squirrel;
using SuperMemoAssistant.Extensions;
using SuperMemoAssistant.Interop;
using SuperMemoAssistant.Models;
using SuperMemoAssistant.Services.IO.Logger;
using SuperMemoAssistant.Sys.Windows;
using SuperMemoAssistant.Sys.Windows.Net;

namespace SuperMemoAssistant.Installer
Expand All @@ -51,7 +56,7 @@ public sealed class SMAInstaller
public static SMAInstaller Instance { get; } = new SMAInstaller();

public static bool UpdateEnabled => SuperMemoAssistant.SMA.Core.CoreConfig.Updates.EnableCoreUpdates;
public static string UpdateUrl => SuperMemoAssistant.SMA.Core.CoreConfig.Updates.CoreUpdateUrl;
public static string UpdateUrl => SuperMemoAssistant.SMA.Core.CoreConfig?.Updates.CoreUpdateUrl;

#endregion

Expand Down Expand Up @@ -134,6 +139,8 @@ public async Task Update()
if (UpdateEnabled == false)
return;

ReleaseEntry updateVersion = null;

try
{
if (Wininet.HasNetworking() == false)
Expand Down Expand Up @@ -161,6 +168,8 @@ public async Task Update()
return;
}

updateVersion = updateInfo.FutureReleaseEntry;

State = SMAUpdateState.Downloading;

await updateMgr.DownloadReleases(updateInfo.ReleasesToApply, progress => ProgressPct = progress);
Expand All @@ -185,9 +194,59 @@ public async Task Update()
finally
{
_semaphore.Release();

if (updateVersion != null)
NotifyUpdateResult(updateVersion);
}
}

private void NotifyUpdateResult(ReleaseEntry updateVersion)
{
var msg = State == SMAUpdateState.Updated
? $"SMA has been updated to version {updateVersion.Version}. Restart SMA to use the new version."
: $"An error occured while updating SMA to version {updateVersion.Version}. Check the logs for more information.";

ToastContent toastContent = new ToastContent
{
Visual = new ToastVisual
{
BindingGeneric = new ToastBindingGeneric
{
Children =
{
new AdaptiveText
{
Text = msg
}
}
}
}
};

if (State == SMAUpdateState.Error)
{
toastContent.Actions = new ToastActionsCustom
{
Buttons =
{
new ToastButton("Open the logs folder", SMAFileSystem.LogDir.FullPathWin)
{
ActivationType = ToastActivationType.Protocol
}
}
};
}

var doc = new XmlDocument();
doc.LoadXml(toastContent.GetContent());

// And create the toast notification
var toast = new ToastNotification(doc);

// And then show it
DesktopNotificationManager.CreateToastNotifier().Show(toast);
}

#endregion
}

Expand Down
5 changes: 2 additions & 3 deletions src/AppHosts/SuperMemoAssistant/Models/SMAExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// DEALINGS IN THE SOFTWARE.
//
//
// Created On: 2020/02/12 22:53
// Modified On: 2020/02/12 22:56
// Modified On: 2020/03/11 00:41
// Modified By: Alexis

#endregion
Expand All @@ -39,7 +38,7 @@ public static class SMAExitCodes
public const int ExitCodeParametersError = 1;
public const int ExitCodeDependencyError = 2;
public const int ExitCodeConfigError = 3;
public const int ExitCodeSMExeError = 4;
public const int ExitCodeSMASetupError = 4;
public const int ExitCodeSMAStartupError = 5;

#endregion
Expand Down
Binary file removed src/AppHosts/SuperMemoAssistant/PluginHost.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions src/AppHosts/SuperMemoAssistant/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.3.192")]
[assembly: AssemblyFileVersion("2.0.3.192")]
[assembly: AssemblyVersion("2.0.3.309")]
[assembly: AssemblyFileVersion("2.0.3.309")]

[assembly: AssemblyInformationalVersion("2.0.3")]
70 changes: 70 additions & 0 deletions src/AppHosts/SuperMemoAssistant/SMANotificationActivator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#region License & Metadata

// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
//
// Modified On: 2020/03/11 18:37
// Modified By: Alexis

#endregion




using System.Runtime.InteropServices;
using System.Windows;
using Anotar.Serilog;
using Microsoft.QueryStringDotNET;
using SuperMemoAssistant.Sys.Windows;

namespace SuperMemoAssistant
{
/// <summary>Handles user actions from Windows Toast Desktop notifications</summary>
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(INotificationActivationCallback))]
[Guid("85DE7F06-9588-4EE6-ABB0-F212B01647FE")]
[ComVisible(true)]
public class SMANotificationActivator : NotificationActivator
{
#region Methods Impl

/// <inheritdoc />
public override void OnActivated(string arguments, NotificationUserInput userInput, string appUserModelId)
{
Application.Current.Dispatcher.Invoke(delegate
{
if (arguments.Length == 0)
return;

QueryString args = QueryString.Parse(arguments);

switch (args["action"])
{
default:
LogTo.Debug($"Unknown notification action {args["action"]}");
break;
}
});
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,40 @@
// DEALINGS IN THE SOFTWARE.
//
//
// Created On: 2020/02/12 22:20
// Modified On: 2020/02/12 22:21
// Modified On: 2020/03/11 12:31
// Modified By: Alexis

#endregion




using SuperMemoAssistant.SMA.Configs;
using SuperMemoFinderUtil = SuperMemoAssistant.SMA.Utils.SuperMemoFinder;
using System.ComponentModel;

namespace SuperMemoAssistant.Setup
{
public static class SMASetup
/// <summary>Contract interface for setup screens</summary>
public interface ISMASetupScreen : INotifyPropertyChanged
{
#region Methods

public static bool ShouldFindSuperMemo(CoreCfg startupCfg, NativeDataCfg nativeDataCfg)
{
return string.IsNullOrWhiteSpace(startupCfg.SuperMemo.SMBinPath)
|| SuperMemoFinderUtil.CheckSuperMemoExecutable(
nativeDataCfg,
startupCfg.SuperMemo.SMBinPath,
out _,
out _) == false;
}

#endregion
/// <summary>Whether this setup step is done</summary>
bool IsSetup { get; }

/// <summary>The title to display in the setup step list</summary>
string ListTitle { get; }

/// <summary>The title to display in the setup window title bar</summary>
string WindowTitle { get; }

/// <summary>Description of the current setup step</summary>
string Description { get; }

/// <summary>Called when this screen is displayed</summary>
void OnDisplayed();

/// <summary>
/// Called when this screen is about to be swapped out for the next one (or the end of
/// the setup process)
/// </summary>
void OnNext();
}
}
Loading

0 comments on commit 48e2176

Please sign in to comment.