public async Task <bool> OnPluginConnected(IImportPluginService pluginSvc, string channelName) { if (pluginSvc == null) { return(false); } using (await _pluginSvcLock.LockAsync()) { try { var resp = pluginSvc.ConnectBrowser(_extensionId, _userAgent, channelName); if (resp == null) { LogTo.Warning($"{_extensionId} failed to connect to Plugin"); return(false); } LogTo.Debug($"Connected to plugin, version {resp.Version}"); await _host.Write(resp); PluginSvc = pluginSvc; return(true); } catch (EndOfStreamException) { } return(false); } }
private static async Task Main(string[] args) { var host = new NativeMessagingHost(); try { while (true) { var response = await host.Read <Message>(); // Echo response await host.Write(new Message($"You said {response.Value} at {response.DateTime}")); } } catch (EndOfStreamException) { // Disconnected } catch (Exception exception) { await host.Write(new Message($"Error: {exception}")); Console.WriteLine($"Oh 💩: {exception}"); Environment.FailFast("Oh 💩", exception); } }
static async Task Main(string[] args) { var host = new NativeMessagingHost(); try { await host.Read <dynamic>(); await host.Write(new { hostName = $"{Environment.MachineName}" }); } catch (Exception exception) { await host.Write(new { error = $"{exception}" }); } }