Skip to content

Commit 8ad0aaf

Browse files
committed
update sqlite version
1 parent 40d79b2 commit 8ad0aaf

File tree

6 files changed

+181
-50
lines changed

6 files changed

+181
-50
lines changed

src/Flow.Launcher.Plugin.ClipboardPlus.Core.Test/DatabaseHelperTest.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public async Task TestCreateDatabase()
8888
{
8989
var helper = new SqliteDatabase(
9090
"TestDb",
91+
1,
9192
mode: SqliteOpenMode.Memory,
9293
cache: SqliteCacheMode.Private
9394
);
@@ -106,6 +107,7 @@ public async Task TestInsertRecord()
106107
var exampleTextRecord = GetRandomClipboardData();
107108
var helper = new SqliteDatabase(
108109
"TestDb",
110+
1,
109111
mode: SqliteOpenMode.Memory,
110112
cache: SqliteCacheMode.Private
111113
);
@@ -135,6 +137,7 @@ public async Task TestDeleteRecordBefore(int type, string creatTime, int keepTim
135137
{
136138
var helper = new SqliteDatabase(
137139
"TestDb",
140+
1,
138141
mode: SqliteOpenMode.Memory,
139142
cache: SqliteCacheMode.Private
140143
);
@@ -149,12 +152,12 @@ public async Task TestDeleteRecordBefore(int type, string creatTime, int keepTim
149152
foreach (var s in spans)
150153
{
151154
var tmpRecord = GetRandomClipboardData(ctime + s);
152-
await helper.AddOneRecordAsync(tmpRecord, (str) => _testOutputHelper.WriteLine($"{str}"));
155+
await helper.AddOneRecordAsync(tmpRecord, true, (str) => _testOutputHelper.WriteLine($"{str}"));
153156
// test dulplicated data
154157
if (_random.NextDouble() > 0.99)
155158
{
156159
var cloneRecord = tmpRecord.Clone();
157-
await helper.AddOneRecordAsync(cloneRecord, (str) => _testOutputHelper.WriteLine($"{str}"));
160+
await helper.AddOneRecordAsync(cloneRecord, true, (str) => _testOutputHelper.WriteLine($"{str}"));
158161
}
159162
}
160163
// helper.Connection.BackupDatabase(new SqliteConnection("Data Source=a.db"));
@@ -178,6 +181,7 @@ public async Task TestPinRecord()
178181
var exampleTextRecord = GetRandomClipboardData();
179182
var helper = new SqliteDatabase(
180183
"TestDb",
184+
1,
181185
mode: SqliteOpenMode.Memory,
182186
cache: SqliteCacheMode.Private
183187
);
@@ -197,6 +201,7 @@ public async Task TestDeleteOneRecord()
197201
var exampleTextRecord = GetRandomClipboardData();
198202
var helper = new SqliteDatabase(
199203
"TestDb",
204+
1,
200205
mode: SqliteOpenMode.Memory,
201206
cache: SqliteCacheMode.Private
202207
);
@@ -213,6 +218,7 @@ public async Task TestDeleteInvalidRecord()
213218
{
214219
var helper = new SqliteDatabase(
215220
"TestDb",
221+
1,
216222
mode: SqliteOpenMode.Memory,
217223
cache: SqliteCacheMode.Private
218224
);
@@ -253,6 +259,7 @@ public async Task TestDeleteUnpinnedRecord()
253259
{
254260
var helper = new SqliteDatabase(
255261
"TestDb",
262+
1,
256263
mode: SqliteOpenMode.Memory,
257264
cache: SqliteCacheMode.Private
258265
);

src/Flow.Launcher.Plugin.ClipboardPlus.Core/Data/Models/Clipboard/ClipboardData.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public ClipboardData()
319319
/// <returns>
320320
/// The clipboard data converted from the record.
321321
/// </returns>
322-
public static ClipboardData FromRecord(Record record)
322+
public static ClipboardData FromRecord(Record record, int initScore)
323323
{
324324
var data = record.DataMd5B64;
325325
var type = (DataType)record.DataType;
@@ -328,7 +328,7 @@ public static ClipboardData FromRecord(Record record)
328328
{
329329
HashId = record.HashId,
330330
SenderApp = record.SenderApp,
331-
InitScore = record.InitScore,
331+
InitScore = initScore,
332332
CreateTime = record.createTime,
333333
CachedImagePath = record.CachedImagePath,
334334
Pinned = record.Pinned,

src/Flow.Launcher.Plugin.ClipboardPlus.Core/Data/Models/Database/Record.cs

+26-7
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public class Record
3737
/// </summary>
3838
public string SenderApp { get; set; } = string.Empty;
3939

40-
/// <summary>
41-
/// Initial score of the record for pinning feature.
42-
/// </summary>
43-
public int InitScore { get; set; }
44-
4540
/// <summary>
4641
/// Create time of the record.
4742
/// </summary>
@@ -52,6 +47,11 @@ public string CreateTime
5247
set => createTime = DateTime.Parse(value);
5348
}
5449

50+
/// <summary>
51+
/// Datetime score of the record for sorting.
52+
/// </summary>
53+
public int DatetimeScore { get; set; }
54+
5555
/// <summary>
5656
/// Path of the cached image for preview.
5757
/// </summary>
@@ -62,6 +62,11 @@ public string CreateTime
6262
/// </summary>
6363
public string UnicodeText { get; set; } = string.Empty;
6464

65+
/// <summary>
66+
/// MD5 hash of the encryption key for identifying the database.
67+
/// </summary>
68+
public string EncryptKeyMd5 { get; set; } = string.Empty;
69+
6570
#endregion
6671

6772
#region Pin
@@ -99,15 +104,29 @@ public static Record FromClipboardData(ClipboardData data, bool needEncryptData)
99104
DataType = (int)data.DataType,
100105
EncryptData = needEncryptData && data.EncryptData,
101106
SenderApp = data.SenderApp,
102-
InitScore = data.InitScore,
103107
CreateTime = data.CreateTime.ToString("O"),
108+
DatetimeScore = GetDateTimeScore(data.CreateTime),
104109
CachedImagePath = data.CachedImagePath,
105110
Pinned = data.Pinned,
106-
UnicodeText = string.Empty // just for getting the unicode text from the database
111+
UnicodeText = string.Empty, // just for getting the unicode text from the database
112+
EncryptKeyMd5 = StringUtils.EncryptKeyMd5
107113
};
108114
return record;
109115
}
110116

117+
// Note: Use the Flow.Launcher first version commit time as the base time for sorting.
118+
private static readonly int BaseDateTimeScore = GetDateTimeScore(new DateTime(2020, 6, 28, 10, 24, 46, DateTimeKind.Utc));
119+
120+
public static int GetDateTimeScore(DateTime dateTime)
121+
{
122+
var ctime = new DateTimeOffset(dateTime);
123+
var seconds = ctime.ToUnixTimeSeconds();
124+
var str = seconds.ToString();
125+
var s = str[^9..];
126+
var score = Convert.ToInt32(s);
127+
return score - BaseDateTimeScore;
128+
}
129+
111130
#endregion
112131

113132
public static bool operator ==(Record a, Record b) => a.Equals(b);

0 commit comments

Comments
 (0)