private static void ConfigureIPC() { Electron.ipcRenderer.on(Constants.IPC.StartCapture, () => { jquery.jQuery.select("#placeholder").hide(); jquery.jQuery.select(".play").hide(); jquery.jQuery.select(".pause").show(); _listener = InitListener(); if (_listener != null) { _listener.Start(); _isStarted = true; } else { // Can't start capturing due to some error (no filter, no credentials) Electron.ipcRenderer.send(Constants.IPC.StopCapture); } }); Electron.ipcRenderer.on(Constants.IPC.StopCapture, () => { jquery.jQuery.select(".pause").hide(); jquery.jQuery.select(".play").show(); _listener?.Stop(); _isStarted = false; }); Electron.ipcRenderer.on(Constants.IPC.ClearCapture, () => { jquery.jQuery.select("#capturedItemsDiv").html(""); jquery.jQuery.select("#placeholder").show(); }); Electron.ipcRenderer.on(Constants.IPC.ToggleTheme, new Action <electron.Electron.Event>(ev => { ToggleTheme(); })); }
public void listenAsync() { tl = new TwitterListener(); tl.listenForTweetEvent(streamingWebclient, oauthToken, oauthTokenSecret); }
private static TwitterListener InitListener() { // Get credentials from the main process: var credentials = (TwitterCredentials)Electron.ipcRenderer.sendSync(Constants.IPC.GetCredentialsSync); // Check credentials: if (credentials == null || string.IsNullOrEmpty(credentials.ApiKey) || string.IsNullOrEmpty(credentials.ApiSecret) || string.IsNullOrEmpty(credentials.AccessToken) || string.IsNullOrEmpty(credentials.AccessTokenSecret)) { dom.alert("Please specify API keys and Access tokens before starting."); return(null); } // Check filter value: var filter = (string)jquery.jQuery.select("#captureFilterInput").val(); if (string.IsNullOrEmpty(filter)) { dom.alert("Please specify filter value."); return(null); } // Create Twitter stream listener: var listener = new TwitterListener(credentials, filter); // Configure handlers for the created listener events: listener.OnReceived += (sender, tweet) => { AddTweetToPage(tweet); // Notify about the obtained tweet: var notificationEnabled = jquery.jQuery.select("#notificationEnabledCheckbox").@is(":checked"); if (notificationEnabled) { // Use delay to avoid creating too many notifications: if (_lastNotificationDate == null || (DateTime.UtcNow - _lastNotificationDate.Value).TotalSeconds > NotificationBufferTimeSec) { _lastNotificationDate = DateTime.UtcNow; CreateNotification(tweet); } } else { _lastNotificationDate = null; } }; listener.OnError += (sender, err) => { // Stop capturing on error: Electron.ipcRenderer.send(Constants.IPC.StopCapture); dom.alert($"Error: {err}"); }; return(listener); }