Skip to content

Commit 8db8d5c

Browse files
committed
Add dispatcher back
1 parent ff9f1e1 commit 8db8d5c

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,45 +1332,48 @@ private async Task<Query> ConstructQueryAsync(string queryText, IEnumerable<Cust
13321332
}
13331333

13341334
var customExpanded = queryBuilder.ToString();
1335-
var queryChanged = false;
1336-
1337-
foreach (var shortcut in builtInShortcuts)
1335+
await Application.Current.Dispatcher.InvokeAsync(async () =>
13381336
{
1339-
string expansion;
1340-
if (shortcut is BuiltinShortcutModel syncShortcut)
1341-
{
1342-
expansion = syncShortcut.Expand();
1343-
}
1344-
else if (shortcut is AsyncBuiltinShortcutModel asyncShortcut)
1345-
{
1346-
expansion = await asyncShortcut.ExpandAsync();
1347-
}
1348-
else
1349-
{
1350-
continue;
1351-
}
1352-
try
1337+
var queryChanged = false;
1338+
1339+
foreach (var shortcut in builtInShortcuts)
13531340
{
1354-
if (customExpanded.Contains(shortcut.Key))
1341+
string expansion;
1342+
if (shortcut is BuiltinShortcutModel syncShortcut)
1343+
{
1344+
expansion = syncShortcut.Expand();
1345+
}
1346+
else if (shortcut is AsyncBuiltinShortcutModel asyncShortcut)
13551347
{
1356-
queryBuilder.Replace(shortcut.Key, expansion);
1357-
queryBuilderTmp.Replace(shortcut.Key, expansion);
1358-
queryChanged = true;
1348+
expansion = await asyncShortcut.ExpandAsync();
1349+
}
1350+
else
1351+
{
1352+
continue;
1353+
}
1354+
try
1355+
{
1356+
if (customExpanded.Contains(shortcut.Key))
1357+
{
1358+
queryBuilder.Replace(shortcut.Key, expansion);
1359+
queryBuilderTmp.Replace(shortcut.Key, expansion);
1360+
queryChanged = true;
1361+
}
1362+
}
1363+
catch (Exception e)
1364+
{
1365+
App.API.LogException(ClassName, $"Error when expanding shortcut {shortcut.Key}", e);
13591366
}
13601367
}
1361-
catch (Exception e)
1368+
1369+
if (queryChanged)
13621370
{
1363-
App.API.LogException(ClassName, $"Error when expanding shortcut {shortcut.Key}", e);
1371+
// show expanded builtin shortcuts
1372+
// use private field to avoid infinite recursion
1373+
_queryText = queryBuilderTmp.ToString();
1374+
OnPropertyChanged(nameof(QueryText));
13641375
}
1365-
}
1366-
1367-
if (queryChanged)
1368-
{
1369-
// show expanded builtin shortcuts
1370-
// use private field to avoid infinite recursion
1371-
_queryText = queryBuilderTmp.ToString();
1372-
OnPropertyChanged(nameof(QueryText));
1373-
}
1376+
});
13741377

13751378
return QueryBuilder.Build(queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins);
13761379
}

0 commit comments

Comments
 (0)