diff --git a/src/Lanceur.Core/Services/IDataService.cs b/src/Lanceur.Core/Services/IDataService.cs
index b772ebea..543665e5 100644
--- a/src/Lanceur.Core/Services/IDataService.cs
+++ b/src/Lanceur.Core/Services/IDataService.cs
@@ -65,6 +65,13 @@ public interface IDataService
/// Points of the chart
IEnumerable> GetUsage(Per per, long? idSession = null);
+ ///
+ /// Hydrate the macro with its id and count. This method will try to find the
+ /// macro by using its name that should be something like '@it_s_name@'
+ ///
+ /// Macro to hydrate
+ void HydrateMacro(QueryResult alias);
+
///
/// Update the usage of the specified
///
diff --git a/src/Lanceur.Infra.SQLite/Models/Tuple.cs b/src/Lanceur.Infra.SQLite/Models/Tuple.cs
new file mode 100644
index 00000000..63fa79cb
--- /dev/null
+++ b/src/Lanceur.Infra.SQLite/Models/Tuple.cs
@@ -0,0 +1,8 @@
+namespace Lanceur.Infra.SQLite
+{
+ internal record Tuple
+ {
+ public T1 Item1 { get; set; }
+ public T2 Item2 { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Lanceur.Infra.SQLite/SQLiteAppSettingsService.cs b/src/Lanceur.Infra.SQLite/SQLiteAppSettingsService.cs
index 2e180cef..d48d8c1a 100644
--- a/src/Lanceur.Infra.SQLite/SQLiteAppSettingsService.cs
+++ b/src/Lanceur.Infra.SQLite/SQLiteAppSettingsService.cs
@@ -15,7 +15,7 @@ public class SQLiteAppSettingsService : SQLiteServiceBase, IAppSettingsService
"IdSession",
"ShowAtStartup",
"HotKey.Key",
- "HotKey.ModifierKeys",
+ "HotKey.ModifierKey",
"Repository.ScoreLimit",
"Window.Position.Left",
"Window.Position.Top",
@@ -97,7 +97,8 @@ public void Save(AppSettings settings)
foreach (var item in Keys)
{
- DB.Connection.Execute(sql, new { key = item, value = settings.GetPropValue(item) });
+ var value = settings.GetPropValue(item);
+ DB.Connection.Execute(sql, new { key = item, value });
}
}
diff --git a/src/Lanceur.Infra.SQLite/SQLiteDataService.cs b/src/Lanceur.Infra.SQLite/SQLiteDataService.cs
index d1f7bfda..eb1b91d7 100644
--- a/src/Lanceur.Infra.SQLite/SQLiteDataService.cs
+++ b/src/Lanceur.Infra.SQLite/SQLiteDataService.cs
@@ -6,7 +6,7 @@
namespace Lanceur.Infra.SQLite
{
- public class SQLiteDataService : SQLiteServiceBase, IDataService
+ public partial class SQLiteDataService : SQLiteServiceBase, IDataService
{
#region Fields
@@ -161,6 +161,30 @@ public IEnumerable> GetUsage(Per per, long? idSessio
};
}
+ public void HydrateMacro(QueryResult alias)
+ {
+ var sql = @"
+ select
+ a.id as Item1,
+ count(a.id) as Item2
+ from
+ alias a
+ inner join alias_usage au on a.id = au.id_alias
+ where
+ file_name like @name
+ group by
+ a.id ";
+
+ var results = DB.Connection.Query>(sql, new { name = alias.Name });
+
+ if (results.Count() == 1)
+ {
+ var item = results.ElementAt(0);
+ alias.Id = item.Item1;
+ alias.Count = item.Item2;
+ }
+ }
+
public IEnumerable RefreshUsage(IEnumerable result) => _aliasDbAction.RefreshUsage(result);
public void Remove(AliasQueryResult alias) => _aliasDbAction.Remove(alias);
diff --git a/src/Lanceur.Infra/Managers/MacroManager.cs b/src/Lanceur.Infra/Managers/MacroManager.cs
index 5988dfec..34bfa921 100644
--- a/src/Lanceur.Infra/Managers/MacroManager.cs
+++ b/src/Lanceur.Infra/Managers/MacroManager.cs
@@ -15,16 +15,18 @@ public class MacroManager : IMacroManager
private static Dictionary _macroInstances = null;
private readonly Assembly _asm;
+ private readonly IDataService _dataService;
private readonly IAppLogger _log;
#endregion Fields
#region Constructors
- public MacroManager(Assembly asm, IAppLoggerFactory logFactory = null)
+ public MacroManager(Assembly asm, IAppLoggerFactory logFactory = null, IDataService dataService = null)
{
_asm = asm;
_log = Locator.Current.GetLogger(logFactory);
+ _dataService = Locator.Current.GetService();
}
#endregion Constructors
@@ -50,6 +52,8 @@ where t.GetCustomAttributes().Any()
var description = (type.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute)?.Description;
alias.SetDescription(description);
+
+ _dataService.HydrateMacro(alias);
macroInstances.Add(name, alias);
_log.Info($"Found macro '{name}'");
@@ -95,7 +99,7 @@ public QueryResult Handle(QueryResult item)
}
else
{
- /* Well, this a misconfigured macro, log it and forget it */
+ /* Well, this is a misconfigured macro, log it and forget it */
_log.Warning($"User has misconfigured a Macro with name '{src.FileName}'. Fix the name of the macro or remove the alias from the database.");
return null;
}
diff --git a/src/Lanceur.Infra/Services/SearchService.cs b/src/Lanceur.Infra/Services/SearchService.cs
index 317b7415..50144cff 100644
--- a/src/Lanceur.Infra/Services/SearchService.cs
+++ b/src/Lanceur.Infra/Services/SearchService.cs
@@ -73,6 +73,7 @@ public IEnumerable Search(Cmdline query)
results.AddRange(res);
}
+ // Remember the query
foreach (var result in results) { result.Query = query; }
if (results.Any())
@@ -86,8 +87,14 @@ public IEnumerable Search(Cmdline query)
// Updgrade alias to executable macro and return the result
var toReturn = _macroManager.Handle(results);
+
+ //Refresh the thumbnails
_thumbnailManager.RefreshThumbnails(toReturn);
- return toReturn;
+
+ // Order the list and return the result
+ return toReturn
+ .OrderByDescending(e => e.Count)
+ .ThenBy(e => e.Name);
}
else { return DisplayQueryResult.SingleFromResult("No result found", iconKind: "AlertCircleOutline"); }
}
diff --git a/src/Lanceur/Lanceur.csproj b/src/Lanceur/Lanceur.csproj
index 4723cbb0..fcc14b1f 100644
--- a/src/Lanceur/Lanceur.csproj
+++ b/src/Lanceur/Lanceur.csproj
@@ -11,6 +11,7 @@
+
@@ -31,6 +32,7 @@
+
diff --git a/src/Lanceur/SQL/script-0.10.sql b/src/Lanceur/SQL/script-0.10.sql
new file mode 100644
index 00000000..7c34c068
--- /dev/null
+++ b/src/Lanceur/SQL/script-0.10.sql
@@ -0,0 +1,12 @@
+/*
+ * Add into the database the default values into the Settings table
+ */
+
+ insert into settings (s_key, s_value)
+select
+ 'HotKey.ModifierKey',
+ s_value
+from settings
+where s_key = 'HotKey.ModifierKeys';
+
+delete from settings where s_key = 'HotKey.ModifierKeys';
diff --git a/src/Lanceur/Views/AppSettingsViewModel.cs b/src/Lanceur/Views/AppSettingsViewModel.cs
index 6cf06b0b..7a280a0f 100644
--- a/src/Lanceur/Views/AppSettingsViewModel.cs
+++ b/src/Lanceur/Views/AppSettingsViewModel.cs
@@ -103,7 +103,6 @@ public AppSettingsViewModel(
private TimeSpan GetDelay()
{
- _settings.Save(Context.AppSettings);
var delay = Context.AppSettings.RestartDelay;
var time = TimeSpan.FromMilliseconds(delay);
return time;
@@ -123,15 +122,18 @@ private ActivationContext OnActivate()
private async void OnSaveSettings()
{
- //Save DB Path
+ //Save DB Path in property file
_stg[Setting.DbPath] = DbPath?.Replace("\"", "");
_stg.Save();
- // Save hotkey & Session
+ // Save hotkey & Session in DB
Context.AppSettings.RestartDelay = RestartDelay;
Context.AppSettings.HotKey = HotKeySection;
if (CurrentSession is not null) { Context.AppSettings.IdSession = CurrentSession.Id; }
+ //Save settings
+ _settings.Save(Context.AppSettings);
+
TimeSpan time = GetDelay();
Toast.Information($"Application settings saved. Restart in {time.TotalMilliseconds} milliseconds");
await _delay.Of(time);