Migrate files from Wox to PowerLauncher (#5014)

* Moved all files from Wox to Powerlauncher

* Removed Wox project

* Changed namespace for imported files

* Resolved errors for VM

* Added build dependency order

* Fixed errors in helper class

* Remove Wox files

* Fixed errors in SingleInstance class

* Fixed wox.tests

* Fixed MSI

* Removed obsolete methods from PublicAPI

* nit fixes

* Throw null exception

* Fix merge conflict
This commit is contained in:
Divyansh Srivastava
2020-07-20 11:22:03 -07:00
committed by GitHub
parent 177546bab6
commit c85cd4ac24
40 changed files with 587 additions and 1048 deletions

View File

@@ -0,0 +1,45 @@
using System;
namespace PowerLauncher.Storage
{
public class HistoryItem
{
public string Query { get; set; }
public DateTime ExecutedDateTime { get; set; }
public string GetTimeAgo()
{
return DateTimeAgo(ExecutedDateTime);
}
private static string DateTimeAgo(DateTime dt)
{
var span = DateTime.Now - dt;
if (span.Days > 365)
{
int years = (span.Days / 365);
if (span.Days % 365 != 0)
years += 1;
return $"about {years} {(years == 1 ? "year" : "years")} ago";
}
if (span.Days > 30)
{
int months = (span.Days / 30);
if (span.Days % 31 != 0)
months += 1;
return $"about {months} {(months == 1 ? "month" : "months")} ago";
}
if (span.Days > 0)
return $"about {span.Days} {(span.Days == 1 ? "day" : "days")} ago";
if (span.Hours > 0)
return $"about {span.Hours} {(span.Hours == 1 ? "hour" : "hours")} ago";
if (span.Minutes > 0)
return $"about {span.Minutes} {(span.Minutes == 1 ? "minute" : "minutes")} ago";
if (span.Seconds > 5)
return $"about {span.Seconds} seconds ago";
if (span.Seconds <= 5)
return "just now";
return string.Empty;
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Wox.Plugin;
namespace PowerLauncher.Storage
{
public class QueryHistory
{
public List<HistoryItem> Items { get; } = new List<HistoryItem>();
private int _maxHistory = 300;
public void Add(string query)
{
if (string.IsNullOrEmpty(query)) return;
if (Items.Count > _maxHistory)
{
Items.RemoveAt(0);
}
if (Items.Count > 0 && Items.Last().Query == query)
{
Items.Last().ExecutedDateTime = DateTime.Now;
}
else
{
Items.Add(new HistoryItem
{
Query = query,
ExecutedDateTime = DateTime.Now
});
}
}
}
}

View File

@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Wox.Plugin;
namespace PowerLauncher.Storage
{
// todo this class is not thread safe.... but used from multiple threads.
public class TopMostRecord
{
[JsonProperty]
private Dictionary<string, Record> records = new Dictionary<string, Record>();
internal bool IsTopMost(Result result)
{
if (records.Count == 0)
{
return false;
}
// since this dictionary should be very small (or empty) going over it should be pretty fast.
return records.Any(o => o.Value.Title == result.Title
&& o.Value.SubTitle == result.SubTitle
&& o.Value.PluginID == result.PluginID
&& o.Key == result.OriginQuery.RawQuery);
}
internal void Remove(Result result)
{
records.Remove(result.OriginQuery.RawQuery);
}
internal void AddOrUpdate(Result result)
{
var record = new Record
{
PluginID = result.PluginID,
Title = result.Title,
SubTitle = result.SubTitle
};
records[result.OriginQuery.RawQuery] = record;
}
public void Load(Dictionary<string, Record> dictionary)
{
records = dictionary;
}
}
public class Record
{
public string Title { get; set; }
public string SubTitle { get; set; }
public string PluginID { get; set; }
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
namespace PowerLauncher.Storage
{
public class UserSelectedRecord
{
[JsonProperty]
private Dictionary<string, int> records = new Dictionary<string, int>();
public void Add(Result result)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
var key = result.ToString();
if (records.TryGetValue(key, out int value))
{
records[key] = value + 1;
}
else
{
records.Add(key, 1);
}
}
public int GetSelectedCount(Result result)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
if (result != null && records.TryGetValue(result.ToString(), out int value))
{
return value;
}
return 0;
}
}
}