public static void Show(string hash = null) { string url = GuideUrl + (hash ?? string.Empty); FormGuide guide = FormManager.TryFind <FormGuide>(); if (guide == null) { FormBrowser owner = FormManager.TryFind <FormBrowser>(); if (owner != null) { owner.AnalyticsFile.OpenGuide.Trigger(); new FormGuide(url, owner).Show(owner); } } else { guide.Reload(url); guide.Activate(); } }
public FormNotificationScreenshotable(Action callback, FormBrowser owner, PluginManager pluginManager, string html, int width) : base(owner, (_, browserComponent) => CreateBrowserImpl(browserComponent, pluginManager)) { int realWidth = BrowserUtils.Scale(width, DpiScale); browserComponent.AttachBridgeObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback)); browserComponent.BrowserLoaded += (sender, args) => { string script = ResourceUtils.ReadFileOrNull("notification/screenshot/screenshot.js"); if (script == null) { this.InvokeAsyncSafe(callback); return; } string substituted = script.Replace("{width}", realWidth.ToString()).Replace("1/*FRAMES*/", TweetScreenshotManager.WaitFrames.ToString()); browserComponent.RunScript("gen:screenshot", substituted); }; SetNotificationSize(realWidth, 1024); LoadTweet(new DesktopNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty)); }
public FormSettings(FormBrowser browser, PluginManager plugins, UpdateHandler updates, AnalyticsManager analytics, Type startTab) { InitializeComponent(); Text = Program.BrandName + " Options"; this.browser = browser; this.browser.PauseNotification(); this.plugins = plugins; this.buttonHeight = BrowserUtils.Scale(39, this.GetDPIScale()) | 1; AddButton("General", () => new TabSettingsGeneral(this.browser, updates)); AddButton("System Tray", () => new TabSettingsTray()); AddButton("Notifications", () => new TabSettingsNotifications(new FormNotificationExample(this.browser, this.plugins))); AddButton("Sounds", () => new TabSettingsSounds()); AddButton("Feedback", () => new TabSettingsFeedback(analytics, AnalyticsReportGenerator.ExternalInfo.From(this.browser), this.plugins)); AddButton("Advanced", () => new TabSettingsAdvanced(this.browser.ReinjectCustomCSS)); SelectTab(tabs[startTab ?? typeof(TabSettingsGeneral)]); }
public TweetScreenshotManager(FormBrowser owner, PluginManager pluginManager) { this.owner = owner; this.plugins = pluginManager; this.timeout = new Timer { Interval = 8000 }; this.timeout.Tick += timeout_Tick; this.disposer = new Timer { Interval = 1 }; this.disposer.Tick += disposer_Tick; #if GEN_SCREENSHOT_FRAMES this.debugger = new Timer { Interval = 16 }; this.debugger.Tick += debugger_Tick; #endif }
public TabSettingsGeneral(FormBrowser browser, UpdateHandler updates) { InitializeComponent(); this.browser = browser; this.updates = updates; this.updates.CheckFinished += updates_CheckFinished; Disposed += (sender, args) => this.updates.CheckFinished -= updates_CheckFinished; toolTip.SetToolTip(trackBarZoom, toolTip.GetToolTip(labelZoomValue)); trackBarZoom.SetValueSafe(Config.ZoomLevel); labelZoomValue.Text = trackBarZoom.Value + "%"; checkExpandLinks.Checked = Config.ExpandLinksOnHover; checkSwitchAccountSelectors.Checked = Config.SwitchAccountSelectors; checkOpenSearchInFirstColumn.Checked = Config.OpenSearchInFirstColumn; checkBestImageQuality.Checked = Config.BestImageQuality; checkAnimatedAvatars.Checked = Config.EnableAnimatedImages; checkSpellCheck.Checked = Config.EnableSpellCheck; checkUpdateNotifications.Checked = Config.EnableUpdateCheck; }
protected FormNotificationBase(FormBrowser owner, bool enableContextMenu) { InitializeComponent(); this.owner = owner; this.owner.FormClosed += owner_FormClosed; ResourceHandlerFactory resourceHandlerFactory = new ResourceHandlerFactory(); resourceHandlerFactory.RegisterHandler(TwitterUtils.TweetDeckURL, this.resourceHandler); resourceHandlerFactory.RegisterHandler(TweetNotification.AppLogo); this.browser = new ChromiumWebBrowser("about:blank") { MenuHandler = new ContextMenuNotification(this, enableContextMenu), JsDialogHandler = new JavaScriptDialogHandler(), LifeSpanHandler = new LifeSpanHandler(), RequestHandler = new RequestHandlerBase(false), ResourceHandlerFactory = resourceHandlerFactory }; this.browser.Dock = DockStyle.None; this.browser.ClientSize = ClientSize; this.browser.SetupZoomEvents(); Controls.Add(browser); Disposed += (sender, args) => { this.browser.Dispose(); this.owner.FormClosed -= owner_FormClosed; }; DpiScale = this.GetDPIScale(); // ReSharper disable once VirtualMemberCallInContructor UpdateTitle(); }
protected FormNotificationBase(FormBrowser owner, bool enableContextMenu) { InitializeComponent(); this.owner = owner; this.owner.FormClosed += owner_FormClosed; this.browser = new ChromiumWebBrowser("about:blank") { MenuHandler = new ContextMenuNotification(this, enableContextMenu), JsDialogHandler = new JavaScriptDialogHandler(), LifeSpanHandler = new LifeSpanHandler() }; this.browser.Dock = DockStyle.None; this.browser.ClientSize = ClientSize; this.browser.IsBrowserInitializedChanged += browser_IsBrowserInitializedChanged; #if DEBUG this.browser.ConsoleMessage += BrowserUtils.HandleConsoleMessage; #endif DpiScale = this.GetDPIScale(); DefaultResourceHandlerFactory handlerFactory = (DefaultResourceHandlerFactory)browser.ResourceHandlerFactory; handlerFactory.RegisterHandler(TwitterUtils.TweetDeckURL, this.resourceHandler); Controls.Add(browser); Disposed += (sender, args) => { this.browser.Dispose(); this.owner.FormClosed -= owner_FormClosed; }; // ReSharper disable once VirtualMemberCallInContructor UpdateTitle(); }
public static IResourceHandler CreateFileHandler(string path) { string mimeType = Path.GetExtension(path) switch { ".weba" => "audio/webm", ".webm" => "audio/webm", ".wav" => "audio/wav", ".ogg" => "audio/ogg", ".mp3" => "audio/mp3", ".flac" => "audio/flac", ".opus" => "audio/ogg; codecs=opus", _ => null }; try{ return(ResourceHandler.FromFilePath(path, mimeType)); }catch { FormBrowser browser = FormManager.TryFind <FormBrowser>(); browser?.InvokeAsyncSafe(() => { using (FormMessage form = new FormMessage("Sound Notification Error", "Could not find custom notification sound file:\n" + path, MessageBoxIcon.Error)){ form.AddButton(FormMessage.Ignore, ControlType.Cancel | ControlType.Focused); Button btnViewOptions = form.AddButton("View Options"); btnViewOptions.Width += 16; btnViewOptions.Location = new Point(btnViewOptions.Location.X - 16, btnViewOptions.Location.Y); if (form.ShowDialog() == DialogResult.OK && form.ClickedButton == btnViewOptions) { browser.OpenSettings(typeof(TabSettingsSounds)); } } }); return(null); } } }
private FormGuide(string url, FormBrowser owner) { InitializeComponent(); Text = Program.BrandName + " Guide"; Size = new Size(owner.Size.Width * 3 / 4, owner.Size.Height * 3 / 4); VisibleChanged += (sender, args) => this.MoveToCenter(owner); ResourceHandlerFactory resourceHandlerFactory = new ResourceHandlerFactory(); resourceHandlerFactory.RegisterHandler(DummyPage); this.browser = new ChromiumWebBrowser(url) { MenuHandler = new ContextMenuGuide(owner), JsDialogHandler = new JavaScriptDialogHandler(), KeyboardHandler = new KeyboardHandlerBase(), LifeSpanHandler = new LifeSpanHandler(), RequestHandler = new RequestHandlerBase(true), ResourceHandlerFactory = resourceHandlerFactory }; browser.LoadingStateChanged += browser_LoadingStateChanged; browser.FrameLoadEnd += browser_FrameLoadEnd; browser.BrowserSettings.BackgroundColor = (uint)BackColor.ToArgb(); browser.Dock = DockStyle.None; browser.Location = ControlExtensions.InvisibleLocation; browser.SetupZoomEvents(); Controls.Add(browser); Disposed += (sender, args) => { browser.Dispose(); }; }
public FormSettings(FormBrowser browser, PluginManager plugins, UpdateChecker updates, TweetDeckFunctions tweetDeckFunctions, Type startTab) { InitializeComponent(); Text = Program.BrandName + " Options"; this.browser = browser; this.browser.PauseNotification(NotificationPauseReason.SettingsDialogOpen); this.plugins = plugins; this.buttonHeight = BrowserUtils.Scale(39, this.GetDPIScale()) | 1; PrepareLoad(); AddButton("General", () => new TabSettingsGeneral(this.browser.ReloadToTweetDeck, tweetDeckFunctions.ReloadColumns, updates)); AddButton("Notifications", () => new TabSettingsNotifications(this.browser.CreateExampleNotification())); AddButton("Sounds", () => new TabSettingsSounds(() => tweetDeckFunctions.PlaySoundNotification(true))); AddButton("Tray", () => new TabSettingsTray()); AddButton("Feedback", () => new TabSettingsFeedback()); AddButton("Advanced", () => new TabSettingsAdvanced(tweetDeckFunctions.ReinjectCustomCSS, this.browser.OpenDevTools)); SelectTab(tabs[startTab ?? typeof(TabSettingsGeneral)]); }
public ContextMenuBrowser(FormBrowser form) : base(form) { this.form = form; }
public KeyboardHandlerBrowser(FormBrowser form) { this.form = form; }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Cef.EnableHighDPISupport(); WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore"); if (!WindowsUtils.CheckFolderWritePermission(StoragePath)) { FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: " + StoragePath, FormMessage.OK); return; } if (Arguments.HasFlag(Arguments.ArgRestart)) { LockManager.Result lockResult = LockManager.LockWait(10000); while (lockResult != LockManager.Result.Success) { if (lockResult == LockManager.Result.Fail) { FormMessage.Error("TweetDuck Has Failed :(", "An unknown error occurred accessing the data folder. Please, make sure TweetDuck is not already running. If the problem persists, try restarting your system.", FormMessage.OK); return; } else if (!FormMessage.Warning("TweetDuck Cannot Restart", "TweetDuck is taking too long to close.", FormMessage.Retry, FormMessage.Exit)) { return; } lockResult = LockManager.LockWait(5000); } } else { LockManager.Result lockResult = LockManager.Lock(); if (lockResult == LockManager.Result.HasProcess) { if (!LockManager.RestoreLockingProcess(2000) && FormMessage.Error("TweetDuck is Already Running", "Another instance of TweetDuck is already running.\nDo you want to close it?", FormMessage.Yes, FormMessage.No)) { if (!LockManager.CloseLockingProcess(10000, 5000)) { FormMessage.Error("TweetDuck Has Failed :(", "Could not close the other process.", FormMessage.OK); return; } lockResult = LockManager.Lock(); } else { return; } } if (lockResult != LockManager.Result.Success) { FormMessage.Error("TweetDuck Has Failed :(", "An unknown error occurred accessing the data folder. Please, make sure TweetDuck is not already running. If the problem persists, try restarting your system.", FormMessage.OK); return; } } Config.LoadAll(); if (Arguments.HasFlag(Arguments.ArgImportCookies)) { ProfileManager.ImportCookies(); } else if (Arguments.HasFlag(Arguments.ArgDeleteCookies)) { ProfileManager.DeleteCookies(); } if (Arguments.HasFlag(Arguments.ArgUpdated)) { WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000); BrowserCache.TryClearNow(); } BrowserCache.RefreshTimer(); CefSharpSettings.WcfEnabled = false; CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSettings settings = new CefSettings { UserAgent = BrowserUtils.UserAgentChrome, BrowserSubprocessPath = BrandName + ".Browser.exe", CachePath = StoragePath, UserDataPath = CefDataPath, LogFile = ConsoleLogFilePath, #if !DEBUG LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable #endif }; CommandLineArgs.ReadCefArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs); BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs); Cef.Initialize(settings, false, new BrowserProcessHandler()); Application.ApplicationExit += (sender, args) => ExitCleanup(); FormBrowser mainForm = new FormBrowser(); Application.Run(mainForm); if (mainForm.UpdateInstallerPath != null) { ExitCleanup(); // ProgramPath has a trailing backslash string updaterArgs = "/SP- /SILENT /FORCECLOSEAPPLICATIONS /UPDATEPATH=\"" + ProgramPath + "\" /RUNARGS=\"" + Arguments.GetCurrentForInstallerCmd() + "\"" + (IsPortable ? " /PORTABLE=1" : ""); bool runElevated = !IsPortable || !WindowsUtils.CheckFolderWritePermission(ProgramPath); if (WindowsUtils.OpenAssociatedProgram(mainForm.UpdateInstallerPath, updaterArgs, runElevated)) { Application.Exit(); } else { RestartWithArgsInternal(Arguments.GetCurrentClean()); } } }
public TweetDeckBridge(FormBrowser form, FormNotification notification) { this.form = form; this.notification = notification; }
public Notification(FormBrowser form, FormNotificationMain notification) : base(form, notification) { }
private static void Main() { SetupWinForms(); Cef.EnableHighDPISupport(); WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore"); if (!FileUtils.CheckFolderWritePermission(StoragePath)) { FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: " + StoragePath, FormMessage.OK); return; } if (!LockManager.Lock(Arguments.HasFlag(Arguments.ArgRestart))) { return; } Config.LoadAll(); if (Arguments.HasFlag(Arguments.ArgImportCookies)) { ProfileManager.ImportCookies(); } else if (Arguments.HasFlag(Arguments.ArgDeleteCookies)) { ProfileManager.DeleteCookies(); } if (Arguments.HasFlag(Arguments.ArgUpdated)) { WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000); WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(StoragePath, "Service Worker"), 4000); BrowserCache.TryClearNow(); } try{ ResourceRequestHandlerBase.LoadResourceRewriteRules(Arguments.GetValue(Arguments.ArgFreeze)); }catch (Exception e) { FormMessage.Error("Resource Freeze", "Error parsing resource rewrite rules: " + e.Message, FormMessage.OK); return; } BrowserCache.RefreshTimer(); CefSharpSettings.WcfEnabled = false; CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSettings settings = new CefSettings { UserAgent = BrowserUtils.UserAgentChrome, BrowserSubprocessPath = Path.Combine(ProgramPath, BrandName + ".Browser.exe"), CachePath = StoragePath, UserDataPath = CefDataPath, LogFile = ConsoleLogFilePath, #if !DEBUG LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable #endif }; var pluginScheme = new PluginSchemeFactory(); settings.RegisterScheme(new CefCustomScheme { SchemeName = PluginSchemeFactory.Name, IsStandard = false, IsSecure = true, IsCorsEnabled = true, IsCSPBypassing = true, SchemeHandlerFactory = pluginScheme }); CommandLineArgs.ReadCefArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs); BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs); Cef.Initialize(settings, false, new BrowserProcessHandler()); Win.Application.ApplicationExit += (sender, args) => ExitCleanup(); FormBrowser mainForm = new FormBrowser(pluginScheme); Resources.Initialize(mainForm); Win.Application.Run(mainForm); if (mainForm.UpdateInstaller != null) { ExitCleanup(); if (mainForm.UpdateInstaller.Launch()) { Win.Application.Exit(); } else { RestartWithArgsInternal(Arguments.GetCurrentClean()); } } }
protected TweetDeckBridge(FormBrowser form, FormNotificationMain notification) { this.form = form; this.notification = notification; }
public ContextMenuBrowser(FormBrowser form, IContextMenuHandler handler, TweetDeckExtraContext extraContext) : base(handler) { this.form = form; this.extraContext = extraContext; }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore"); if (!WindowsUtils.CheckFolderWritePermission(StoragePath)) { MessageBox.Show(BrandName + " does not have write permissions to the storage folder: " + StoragePath, "Permission Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Reporter = new Reporter(ErrorLogFilePath); Reporter.SetupUnhandledExceptionHandler(BrandName + " Has Failed :("); if (Arguments.HasFlag(Arguments.ArgRestart)) { for (int attempt = 0; attempt < 21; attempt++) { LockManager.Result lockResult = LockManager.Lock(); if (lockResult == LockManager.Result.Success) { break; } else if (lockResult == LockManager.Result.Fail) { MessageBox.Show("An unknown error occurred accessing the data folder. Please, make sure " + BrandName + " is not already running. If the problem persists, try restarting your system.", BrandName + " Has Failed :(", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (attempt == 20) { using (FormMessage form = new FormMessage(BrandName + " Cannot Restart", BrandName + " is taking too long to close.", MessageBoxIcon.Warning)){ form.CancelButton = form.AddButton("Exit"); form.ActiveControl = form.AddButton("Retry", DialogResult.Retry); if (form.ShowDialog() == DialogResult.Retry) { attempt /= 2; continue; } return; } } else { Thread.Sleep(500); } } } else { LockManager.Result lockResult = LockManager.Lock(); if (lockResult == LockManager.Result.HasProcess) { if (LockManager.LockingProcess.MainWindowHandle == IntPtr.Zero) // restore if the original process is in tray { NativeMethods.SendMessage(NativeMethods.HWND_BROADCAST, WindowRestoreMessage, LockManager.LockingProcess.Id, IntPtr.Zero); if (WindowsUtils.TrySleepUntil(() => { LockManager.LockingProcess.Refresh(); return(LockManager.LockingProcess.HasExited || (LockManager.LockingProcess.MainWindowHandle != IntPtr.Zero && LockManager.LockingProcess.Responding)); }, 2000, 250)) { return; // should trigger on first attempt if succeeded, but wait just in case } } if (MessageBox.Show("Another instance of " + BrandName + " is already running.\r\nDo you want to close it?", BrandName + " is Already Running", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (!LockManager.CloseLockingProcess(10000, 5000)) { MessageBox.Show("Could not close the other process.", BrandName + " Has Failed :(", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } LockManager.Lock(); } else { return; } } else if (lockResult != LockManager.Result.Success) { MessageBox.Show("An unknown error occurred accessing the data folder. Please, make sure " + BrandName + " is not already running. If the problem persists, try restarting your system.", BrandName + " Has Failed :(", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } ReloadConfig(); if (Arguments.HasFlag(Arguments.ArgImportCookies)) { ExportManager.ImportCookies(); } CefSharpSettings.WcfEnabled = false; CefSettings settings = new CefSettings { AcceptLanguageList = BrowserUtils.HeaderAcceptLanguage, UserAgent = BrowserUtils.HeaderUserAgent, Locale = Arguments.GetValue(Arguments.ArgLocale, string.Empty), CachePath = StoragePath, LogFile = ConsoleLogFilePath, #if !DEBUG BrowserSubprocessPath = BrandName + ".Browser.exe", LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable #endif }; CommandLineArgsParser.ReadCefArguments(UserConfig.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs); if (!HardwareAcceleration.IsEnabled) { settings.CefCommandLineArgs["disable-gpu"] = "1"; settings.CefCommandLineArgs["disable-gpu-vsync"] = "1"; } settings.CefCommandLineArgs["disable-extensions"] = "1"; settings.CefCommandLineArgs["disable-plugins-discovery"] = "1"; settings.CefCommandLineArgs["enable-system-flash"] = "0"; Cef.Initialize(settings, false, new BrowserProcessHandler()); Application.ApplicationExit += (sender, args) => ExitCleanup(); PluginManager plugins = new PluginManager(PluginPath, UserConfig.Plugins); plugins.Reloaded += plugins_Reloaded; plugins.Executed += plugins_Executed; plugins.Reload(); FormBrowser mainForm = new FormBrowser(plugins, new UpdaterSettings { AllowPreReleases = Arguments.HasFlag(Arguments.ArgDebugUpdates), DismissedUpdate = UserConfig.DismissedUpdate }); Application.Run(mainForm); if (mainForm.UpdateInstallerPath != null) { ExitCleanup(); // ProgramPath has a trailing backslash string updaterArgs = "/SP- /SILENT /CLOSEAPPLICATIONS /UPDATEPATH=\"" + ProgramPath + "\" /RUNARGS=\"" + Arguments.GetCurrentClean().ToString().Replace("\"", "^\"") + "\"" + (IsPortable ? " /PORTABLE=1" : ""); bool runElevated = !IsPortable || !WindowsUtils.CheckFolderWritePermission(ProgramPath); WindowsUtils.StartProcess(mainForm.UpdateInstallerPath, updaterArgs, runElevated); Application.Exit(); } }
public VideoPlayer(FormBrowser owner) { this.owner = owner; this.owner.FormClosing += owner_FormClosing; }
public FileDialogHandler(FormBrowser form) { this.form = form; }