Skip to content

Commit

Permalink
- Added Notifications #53
Browse files Browse the repository at this point in the history
- Added Notification + Option to restart on plugin crash
- Added plugin labels #133
- Added ToolTips to UI icons #130
- Added install destination folder in confirmation popup message #129 (Squirrel.Windows)
- Added cancel button + reset in Collection Selection #117
- Added a setup step to import collections from supermemo.ini #73
- Added CfgBase with reset on cancel
- Added automatic version configuration
- Added more documentation
- Several other minor updates
  • Loading branch information
alexis- committed Mar 13, 2020
1 parent 48e2176 commit ccbc3bf
Show file tree
Hide file tree
Showing 59 changed files with 2,224 additions and 148 deletions.
1 change: 1 addition & 0 deletions SuperMemoAssistant.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ 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>
Expand Down
2 changes: 1 addition & 1 deletion libs/Squirrel.Windows
6 changes: 3 additions & 3 deletions src/AppHosts/SuperMemoAssistant/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ private async Task LoadApp(SMAParameters args)
SMA.Core.CoreConfig = coreCfg;

//
// Setup toast notifications (TODO: setup ToastActivatorCLSID on shortcut https://github.com/WindowsNotifications/desktop-toasts/blob/472a3f9f5849fbc62bf5cad769421d4299c47f51/CS/DesktopToastsSetupProject/Product.wxs)
DesktopNotificationManager.RegisterAumidAndComServer<SMANotificationActivator>("SuperMemoAssistant");
// Setup toast notifications
DesktopNotificationManager.RegisterAumidAndComServer<SMANotificationActivator>(SMANotificationActivator.AppUserModelId);
DesktopNotificationManager.RegisterActivator<SMANotificationActivator>();

//
// Check if SMA is setup, and run the setup wizard if it isn't
if (SMASetup.Run(nativeDataCfg, coreCfg) == false)
Expand Down
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.309")]
[assembly: AssemblyFileVersion("2.0.3.309")]
[assembly: AssemblyVersion("2.0.3.340")]
[assembly: AssemblyFileVersion("2.0.3.340")]

[assembly: AssemblyInformationalVersion("2.0.3")]
50 changes: 47 additions & 3 deletions src/AppHosts/SuperMemoAssistant/SMANotificationActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// DEALINGS IN THE SOFTWARE.
//
//
// Modified On: 2020/03/11 18:37
// Modified On: 2020/03/13 01:48
// Modified By: Alexis

#endregion
Expand All @@ -33,17 +33,28 @@
using System.Windows;
using Anotar.Serilog;
using Microsoft.QueryStringDotNET;
using SuperMemoAssistant.Extensions;
using SuperMemoAssistant.Plugins;
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")]
[Guid("55832db8-45ea-5ead-9291-9549b25a5f0c")]
[ComVisible(true)]
public class SMANotificationActivator : NotificationActivator
{
#region Constants & Statics

public const string AppUserModelId = "com.squirrel.SuperMemoAssistant.SuperMemoAssistant";

#endregion




#region Methods Impl

/// <inheritdoc />
Expand All @@ -56,15 +67,48 @@ public override void OnActivated(string arguments, NotificationUserInput userInp

QueryString args = QueryString.Parse(arguments);

if (args.Contains("action") == false)
{
LogTo.Warning($"Received a Toast activation without an action argument: '{arguments}'");
return;
}

switch (args["action"])
{
// Restart plugin after crash
case SMAPluginManager.ToastActionRestartAfterCrash:
if (args.Contains(SMAPluginManager.ToastActionParameterPluginId) == false)
{
LogTo.Error($"Received a ToastActionRestartAfterCrash toast activation without a plugin id parameter: '{arguments}'");
return;
}

var packageId = args[SMAPluginManager.ToastActionParameterPluginId];
SMAPluginManager.Instance.StartPlugin(packageId).RunAsync();
break;

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

#endregion




#if false
/// <summary>
/// Helper function to get the Squirrel-generated CLSID
/// </summary>
/// <returns></returns>
public static string GetActivatorCLSID()
{
return Utility.CreateGuidFromHash(AppUserModelId).ToString();
}

#endif
}
}
84 changes: 84 additions & 0 deletions src/AppHosts/SuperMemoAssistant/Setup/Models/SMImportCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#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/12 23:11
// Modified By: Alexis

#endregion




using System.ComponentModel;
using System.IO;

namespace SuperMemoAssistant.Setup.Models
{
/// <summary>A container for the importable collections</summary>
public class SMImportCollection : INotifyPropertyChanged
{
#region Constructors

public SMImportCollection(string collectionPath)
{
Name = Path.GetFileName(collectionPath);
CollectionPath = collectionPath;
}

#endregion




#region Properties & Fields - Public

public bool IsChecked { get; set; } = true;

public bool IsEnabled { get; set; } = true;

public string Name { get; set; }

public string CollectionPath { get; set; }

#endregion




#region Methods

public string GetKnoFilePath() => CollectionPath + ".kno";

#endregion




#region Events

/// <inheritdoc />
public event PropertyChangedEventHandler PropertyChanged;

#endregion
}
}
2 changes: 1 addition & 1 deletion src/AppHosts/SuperMemoAssistant/Setup/SMASetup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ShowIconOnTitleBar="True"
Style="{DynamicResource CleanWindowStyleKey}"
GlowBrush="{DynamicResource AccentColorBrush}"
Initialized="SMASetup_Initialized"
Loaded="SMASetup_Loaded"
KeyDown="MetroWindow_KeyDown">

<mah:MetroWindow.Resources>
Expand Down
27 changes: 20 additions & 7 deletions src/AppHosts/SuperMemoAssistant/Setup/SMASetup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@



using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows.Input;
using Anotar.Serilog;
using MahApps.Metro.Controls;
using SuperMemoAssistant.Services.UI.Extensions;
using SuperMemoAssistant.Setup.Screens;
using SuperMemoAssistant.SMA.Configs;
using SuperMemoAssistant.Sys.Windows.Input;
Expand All @@ -59,6 +61,7 @@ protected SMASetup(NativeDataCfg nativeDataCfg, CoreCfg startupCfg)
{
new TermsOfLicense(startupCfg),
new SuperMemoFinder(nativeDataCfg, startupCfg),
new ImportCollections(startupCfg),
new PluginSetup(),
};

Expand Down Expand Up @@ -139,22 +142,32 @@ private void ShowPreviousScreen()

private void ShowScreen(SMASetupScreenBase screen)
{
CurrentScreen?.OnNext();
try
{
CurrentScreen?.OnNext();

CurrentScreen = screen;
CurrentScreen?.OnDisplayed();
CurrentScreen = screen;
CurrentScreen?.OnDisplayed();

Title = CurrentScreen?.WindowTitle != null
? $"SMA Setup: {CurrentScreen.WindowTitle}"
: "SMA Setup";
Title = CurrentScreen?.WindowTitle != null
? $"SMA Setup: {CurrentScreen.WindowTitle}"
: "SMA Setup";
}
catch (Exception ex)
{
var errMsg = $"An exception occured while showing screen {screen?.ListTitle}";

LogTo.Error(ex, errMsg);
errMsg.ErrorMsgBox().Wait();
}
}

private SMASetupScreenBase FindNextScreen()
{
return Screens.FirstOrDefault(s => s.IsSetup == false);
}

private void SMASetup_Initialized(object sender, System.EventArgs e)
private void SMASetup_Loaded(object sender, System.EventArgs e)
{
ShowScreen(FindNextScreen());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<setup:SMASetupScreenBase x:Class="SuperMemoAssistant.Setup.Screens.ImportCollections"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:setup="clr-namespace:SuperMemoAssistant.Setup"
xmlns:models="clr-namespace:SuperMemoAssistant.Setup.Models"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>


<ListBox Name="lbCollections"
Grid.Row="0"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Collections}"
Grid.IsSharedSizeScope="True">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:SMImportCollection}">
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" SharedSizeGroup="Name" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>

<CheckBox Grid.Column="0" Margin="0 0 8 0" VerticalAlignment="Center" FontSize="14"
IsEnabled="{Binding IsEnabled}" IsChecked="{Binding IsChecked}" />
<TextBlock Grid.Column="1" Margin="0 0 16 0" VerticalAlignment="Center" FontSize="14" Text="{Binding Name}" />
<TextBlock Grid.Column="2" Margin="0" VerticalAlignment="Center" FontSize="14"
Text="{Binding CollectionPath}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>

<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick" />
</Style>
</ListBox.ItemContainerStyle>

<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Style.Triggers>
<!-- ReSharper disable once Xaml.BindingWithContextNotResolved -->
<DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}"
Value="0">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center">
You don't appear to have created any collection in SuperMemo yet :-(
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Style>
</ListBox>

</Grid>
</setup:SMASetupScreenBase>
Loading

0 comments on commit ccbc3bf

Please sign in to comment.