mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
fix some bug (v1 still broken)
This commit is contained in:
parent
683f6ebce4
commit
a3367abd7a
6 changed files with 38 additions and 27 deletions
|
|
@ -47,7 +47,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
public abstract List<Result> LoadContextMenus(Result selectedResult);
|
||||
|
||||
private static readonly JsonSerializerOptions options = new()
|
||||
protected static readonly JsonSerializerOptions options = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
#pragma warning disable SYSLIB0020
|
||||
|
|
@ -155,6 +155,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
API = Context.API
|
||||
};
|
||||
|
||||
await Settings.InitializeAsync();
|
||||
|
||||
}
|
||||
|
||||
public virtual async Task InitAsync(PluginInitContext context)
|
||||
|
|
@ -165,7 +167,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
public void Save()
|
||||
{
|
||||
Settings.Save();
|
||||
Settings?.Save();
|
||||
}
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using Flow.Launcher.Plugin;
|
|||
|
||||
namespace Flow.Launcher.Core.Plugin
|
||||
{
|
||||
public abstract class JsonRpcPluginV2 : IAsyncPlugin, IContextMenu, ISettingProvider, ISavable
|
||||
internal abstract class JsonRpcPluginV2 : JsonRPCPluginBase
|
||||
{
|
||||
public abstract string SupportedLanguage { get; set; }
|
||||
|
||||
|
|
@ -56,14 +56,10 @@ namespace Flow.Launcher.Core.Plugin
|
|||
await JsonSerializer.SerializeAsync(InputStream, fullMessage, cancellationToken: token);
|
||||
}
|
||||
|
||||
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
|
||||
protected override async Task<List<Result>> QueryRequestAsync(JsonRPCRequestModel query, CancellationToken token)
|
||||
{
|
||||
int currentRequestId = Interlocked.Add(ref RequestId, 1);
|
||||
var message = new JsonRPCRequestModel(currentRequestId, "query", new object[]
|
||||
{
|
||||
query
|
||||
});
|
||||
await InputMessageChannel.Writer.WriteAsync(message, token);
|
||||
await InputMessageChannel.Writer.WriteAsync(query, token);
|
||||
await Task.Delay(50, token);
|
||||
await InputStream.FlushAsync(token);
|
||||
var task = new TaskCompletionSource<JsonRPCQueryResponseModel>();
|
||||
|
|
@ -72,8 +68,9 @@ namespace Flow.Launcher.Core.Plugin
|
|||
//TODO: Parse Result
|
||||
return new List<Result>();
|
||||
}
|
||||
public virtual Task InitAsync(PluginInitContext context)
|
||||
public override async Task InitAsync(PluginInitContext context)
|
||||
{
|
||||
await base.InitAsync(context);
|
||||
InputMessageChannel = Channel.CreateUnbounded<JsonRPCRequestModel>();
|
||||
MessageCancellationTokenSource = new CancellationTokenSource();
|
||||
SendMessageAsync(context.CurrentPluginMetadata, MessageCancellationTokenSource.Token);
|
||||
|
|
@ -81,20 +78,6 @@ namespace Flow.Launcher.Core.Plugin
|
|||
// MessageTask =
|
||||
// (SendMessageAsync(context.CurrentPluginMetadata, MessageCancellationTokenSource.Token),
|
||||
// ReceiveMessageAsync(MessageCancellationTokenSource.Token));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public List<Result> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
// TODO: Implement CreateSettingPanel
|
||||
return new Control();
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
// TODO: Save settings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
_storage = new JsonStorage<Dictionary<string, object>>(SettingPath);
|
||||
Settings = await _storage.LoadAsync();
|
||||
|
||||
foreach (var (type, attributes) in Configuration.Body)
|
||||
{
|
||||
if (attributes.Name == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Settings.ContainsKey(attributes.Name))
|
||||
{
|
||||
Settings[attributes.Name] = attributes.DefaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
|
|
@ -38,7 +39,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
|
||||
{
|
||||
_startInfo.ArgumentList[2] = request.ToString();
|
||||
_startInfo.ArgumentList[2] = JsonSerializer.Serialize(request);
|
||||
|
||||
return ExecuteAsync(_startInfo, token);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
|
@ -8,7 +9,7 @@ using Flow.Launcher.Plugin;
|
|||
|
||||
namespace Flow.Launcher.Core.Plugin
|
||||
{
|
||||
public class PythonPluginV2 : JsonRpcPluginV2
|
||||
internal class PythonPluginV2 : JsonRpcPluginV2
|
||||
{
|
||||
private readonly ProcessStartInfo _startInfo;
|
||||
private Process _process;
|
||||
|
|
@ -42,8 +43,16 @@ namespace Flow.Launcher.Core.Plugin
|
|||
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
||||
_startInfo.ArgumentList.Add("-B");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override List<Result> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected override Task<bool> ExecuteResultAsync(JsonRPCResult result)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override async Task InitAsync(PluginInitContext context)
|
||||
{
|
||||
_startInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
public JsonStorage(string filePath)
|
||||
{
|
||||
FilePath = filePath;
|
||||
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
|
||||
|
||||
Helper.ValidateDirectory(DirectoryPath);
|
||||
}
|
||||
|
||||
public async Task<T> LoadAsync()
|
||||
|
|
|
|||
Loading…
Reference in a new issue