public TabSettingsAdvanced(Action <string> reinjectBrowserCSS, Action openDevTools)
        {
            InitializeComponent();

            this.reinjectBrowserCSS = reinjectBrowserCSS;
            this.openDevTools       = openDevTools;

            // application

            toolTip.SetToolTip(btnOpenAppFolder, "Opens the folder where the app is located.");
            toolTip.SetToolTip(btnOpenDataFolder, "Opens the folder where your profile data is located.");
            toolTip.SetToolTip(btnRestart, "Restarts the program using the same command\r\nline arguments that were used at launch.");
            toolTip.SetToolTip(btnRestartArgs, "Restarts the program with customizable\r\ncommand line arguments.");

            // browser cache

            toolTip.SetToolTip(btnClearCache, "Clearing cache will free up space taken by downloaded images and other resources.");
            toolTip.SetToolTip(checkClearCacheAuto, "Automatically clears cache when its size exceeds the set threshold. Note that cache can only be cleared when closing TweetDuck.");

            checkClearCacheAuto.Checked    = SysConfig.ClearCacheAutomatically;
            numClearCacheThreshold.Enabled = checkClearCacheAuto.Checked;
            numClearCacheThreshold.SetValueSafe(SysConfig.ClearCacheThreshold);

            BrowserCache.GetCacheSize(task => {
                string text = task.Status == TaskStatus.RanToCompletion ? (int)Math.Ceiling(task.Result / (1024.0 * 1024.0)) + " MB" : "unknown";
                this.InvokeSafe(() => btnClearCache.Text = $"Clear Cache ({text})");
            });

            // configuration

            toolTip.SetToolTip(btnEditCefArgs, "Set custom command line arguments for Chromium Embedded Framework.");
            toolTip.SetToolTip(btnEditCSS, "Set custom CSS for browser and notification windows.");
        }
Example #2
0
        public TabSettingsAdvanced(Action <string> reinjectBrowserCSS)
        {
            InitializeComponent();

            this.reinjectBrowserCSS = reinjectBrowserCSS;

            if (SystemConfig.IsHardwareAccelerationSupported)
            {
                checkHardwareAcceleration.Checked = SysConfig.HardwareAcceleration;
            }
            else
            {
                checkHardwareAcceleration.Enabled = false;
                checkHardwareAcceleration.Checked = false;
            }

            checkBrowserGCReload.Checked = SysConfig.EnableBrowserGCReload;
            numMemoryThreshold.Enabled   = checkBrowserGCReload.Checked;
            numMemoryThreshold.SetValueSafe(SysConfig.BrowserMemoryThreshold);

            BrowserCache.CalculateCacheSize(task => {
                string text = task.IsCompleted ? (int)Math.Ceiling(task.Result / (1024.0 * 1024.0)) + " MB" : "(unknown size)";
                this.InvokeSafe(() => btnClearCache.Text = $"Clear Cache ({text})");
            });
        }
        private void btnClearCache_Click(object sender, EventArgs e)
        {
            btnClearCache.Enabled = false;
            BrowserCache.SetClearOnExit();

            MessageBox.Show("Cache will be automatically cleared when " + Program.BrandName + " exits.", "Clear Cache", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #4
0
        public TabSettingsAdvanced(Action <string> reinjectBrowserCSS, Action openDevTools)
        {
            InitializeComponent();

            this.reinjectBrowserCSS = reinjectBrowserCSS;
            this.openDevTools       = openDevTools;

            // application

            toolTip.SetToolTip(btnOpenAppFolder, "Opens the folder where the app is located.");
            toolTip.SetToolTip(btnOpenDataFolder, "Opens the folder where your profile data is located.");
            toolTip.SetToolTip(btnRestart, "Restarts the program using the same command\r\nline arguments that were used at launch.");
            toolTip.SetToolTip(btnRestartArgs, "Restarts the program with customizable\r\ncommand line arguments.");

            // browser settings

            toolTip.SetToolTip(checkTouchAdjustment, "Toggles Chromium touch screen adjustment.\r\nDisabled by default, because it is very imprecise with TweetDeck.");
            toolTip.SetToolTip(checkAutomaticallyDetectColorProfile, "Automatically detects the color profile of your system.\r\nUses the sRGB profile if disabled.");
            toolTip.SetToolTip(checkHardwareAcceleration, "Uses graphics card to improve performance.\r\nDisable if you experience visual glitches, or to save a small amount of RAM.");

            checkTouchAdjustment.Checked = SysConfig.EnableTouchAdjustment;
            checkAutomaticallyDetectColorProfile.Checked = SysConfig.EnableColorProfileDetection;
            checkHardwareAcceleration.Checked            = SysConfig.HardwareAcceleration;

            // browser cache

            toolTip.SetToolTip(btnClearCache, "Clearing cache will free up space taken by downloaded images and other resources.");
            toolTip.SetToolTip(checkClearCacheAuto, "Automatically clears cache when its size exceeds the set threshold. Note that cache can only be cleared when closing TweetDuck.");

            checkClearCacheAuto.Checked    = SysConfig.ClearCacheAutomatically;
            numClearCacheThreshold.Enabled = checkClearCacheAuto.Checked;
            numClearCacheThreshold.SetValueSafe(SysConfig.ClearCacheThreshold);

            BrowserCache.GetCacheSize(task => {
                string text = task.Status == TaskStatus.RanToCompletion ? (int)Math.Ceiling(task.Result / (1024.0 * 1024.0)) + " MB" : "unknown";
                this.InvokeSafe(() => btnClearCache.Text = $"Clear Cache ({text})");
            });

            // configuration

            toolTip.SetToolTip(btnEditCefArgs, "Set custom command line arguments for Chromium Embedded Framework.");
            toolTip.SetToolTip(btnEditCSS, "Set custom CSS for browser and notification windows.");

            // proxy

            toolTip.SetToolTip(checkUseSystemProxyForAllConnections, "Sets whether all connections should automatically detect and use the system proxy.\r\nBy default, only the browser component uses the system proxy, while other parts (such as update checks) ignore it.\r\nDisabled by default because Windows' proxy detection can be really slow.");

            checkUseSystemProxyForAllConnections.Checked = SysConfig.UseSystemProxyForAllConnections;

            // development tools

            toolTip.SetToolTip(checkDevToolsInContextMenu, "Sets whether all context menus include an option to open dev tools.");
            toolTip.SetToolTip(checkDevToolsWindowOnTop, "Sets whether dev tool windows appears on top of other windows.");

            checkDevToolsInContextMenu.Checked = Config.DevToolsInContextMenu;
            checkDevToolsWindowOnTop.Checked   = Config.DevToolsWindowOnTop;
        }
Example #5
0
        public void OpenSettings(Type startTab)
        {
            if (!FormManager.TryBringToFront <FormSettings>())
            {
                bool prevEnableUpdateCheck = Config.EnableUpdateCheck;

                FormSettings form = new FormSettings(this, plugins, updates, analytics, startTab);

                form.FormClosed += (sender, args) => {
                    if (!prevEnableUpdateCheck && Config.EnableUpdateCheck)
                    {
                        Config.DismissedUpdate = null;
                        Config.Save();

                        updates.Check(true);
                    }

                    if (!Config.EnableTrayHighlight)
                    {
                        trayIcon.HasNotifications = false;
                    }

                    if (Config.AllowDataCollection)
                    {
                        if (analytics == null)
                        {
                            analytics = new AnalyticsManager(this, plugins, Program.AnalyticsFilePath);
                        }
                    }
                    else if (analytics != null)
                    {
                        analytics.Dispose();
                        analytics = null;
                    }

                    BrowserCache.RefreshTimer();

                    if (form.ShouldReloadBrowser)
                    {
                        FormManager.TryFind <FormPlugins>()?.Close();
                        plugins.Reload(); // also reloads the browser
                    }
                    else
                    {
                        browser.UpdateProperties();
                    }

                    notification.RequiresResize = true;
                    form.Dispose();
                };

                AnalyticsFile.OpenOptions.Trigger();
                ShowChildForm(form);
            }
        }
Example #6
0
            public void BeforeLaunch()
            {
                if (Arguments.HasFlag(Arguments.ArgUpdated))
                {
                    WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(App.StoragePath, InstallerFolder), 8000);
                    WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(App.StoragePath, "Service Worker"), 4000);
                    BrowserCache.TryClearNow();
                }

                if (Config.System.Migrate())
                {
                    Config.System.Save();
                }
            }
Example #7
0
        private static void ExitCleanup()
        {
            if (HasCleanedUp)
            {
                return;
            }

            Config.SaveAll();

            Cef.Shutdown();
            BrowserCache.Exit();

            LockManager.Unlock();
            HasCleanedUp = true;
        }
Example #8
0
        private static void ExitCleanup()
        {
            if (hasCleanedUp)
            {
                return;
            }

            App.Close();

            Cef.Shutdown();
            BrowserCache.Exit();

            lockManager.Unlock();
            hasCleanedUp = true;
        }
Example #9
0
            public void Launch(ResourceCache resourceCache, PluginManager pluginManager)
            {
                string storagePath = App.StoragePath;

                BrowserCache.RefreshTimer();

                CefSharpSettings.WcfEnabled = false;
                CefSharpSettings.SubprocessExitIfParentProcessClosed = false;

                CefSettings settings = new CefSettings {
                    UserAgent             = BrowserUtils.UserAgentChrome,
                    BrowserSubprocessPath = Path.Combine(App.ProgramPath, BrandName + ".Browser.exe"),
                    CachePath             = storagePath,
                    UserDataPath          = Path.Combine(storagePath, CefDataFolder),
                    LogFile = Path.Combine(storagePath, ConsoleLogFile),
                                        #if !DEBUG
                    LogSeverity = Arguments.HasFlag(Arguments.ArgLogging) ? LogSeverity.Info : LogSeverity.Disable
                                        #endif
                };

                CefSchemeHandlerFactory.Register(settings, new TweetDuckSchemeHandler(resourceCache));
                CefSchemeHandlerFactory.Register(settings, new PluginSchemeHandler(resourceCache, pluginManager));

                CefUtils.ParseCommandLineArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs);
                BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs);

                Cef.Initialize(settings, false, new BrowserProcessHandler());

                Win.Application.ApplicationExit += (sender, args) => ExitCleanup();
                var updateCheckClient = new UpdateCheckClient(Path.Combine(storagePath, InstallerFolder));
                var mainForm          = new FormBrowser(resourceCache, pluginManager, updateCheckClient, lockManager.WindowRestoreMessage);

                Win.Application.Run(mainForm);

                if (mainForm.UpdateInstaller != null)
                {
                    ExitCleanup();

                    if (mainForm.UpdateInstaller.Launch())
                    {
                        Win.Application.Exit();
                    }
                    else
                    {
                        RestartWithArgsInternal(Arguments.GetCurrentClean());
                    }
                }
            }
Example #10
0
        private RiteAidWatcher(RiteAidConfig riteAidConfig)
        {
            Alerts = new List <Alert>();
            var configuration = provider.GetService <NotifierConfiguration>();

            Notifier     = new Notifier(configuration);
            Filter       = riteAidConfig.Filter;
            MaxMiles     = riteAidConfig.MaxMiles;
            BrowserCheck = riteAidConfig.BrowserCheck;
            riteAidData  = riteAidConfig.Data;
            DumpStateRules(riteAidData);
            if (BrowserCheck)
            {
                browserCache = new BrowserCache(MaxBrowsers, riteAidData, Checker.Initializer, Checker.Resetter);
                browserCache.Preload();
            }
        }
Example #11
0
        public void RiteAidCreate()
        {
            var data = new RiteAidData()
            {
                BirthDate  = "01/01/2000",
                City       = "Downingtown",
                StateCode  = "PA",
                StateName  = "Pennsylvania",
                Zip        = "19335",
                Condition  = ConditionType.WeakendImmuneSystem,
                Occupation = OccupationType.NoneOfTheAbove
            };

            var cache     = new BrowserCache(1, data, Checker.Initializer, Checker.Resetter);
            var browser   = cache.Pop();
            var available = Checker.Check("19406", "11158", data, browser);
        }
        public TabSettingsAdvanced(Action <string> reinjectBrowserCSS, PluginManager plugins)
        {
            InitializeComponent();

            this.reinjectBrowserCSS = reinjectBrowserCSS;
            this.plugins            = plugins;

            checkHardwareAcceleration.Checked = HardwareAcceleration.IsEnabled;

            BrowserCache.CalculateCacheSize(bytes => this.InvokeSafe(() => {
                if (bytes == -1L)
                {
                    btnClearCache.Text = "Clear Cache (unknown size)";
                }
                else
                {
                    btnClearCache.Text = "Clear Cache (" + (int)Math.Ceiling(bytes / (1024.0 * 1024.0)) + " MB)";
                }
            }));
        }
        public void Test()
        {
            var data = new RiteAidData()
            {
                BirthDate  = "01/01/2000",
                City       = "Downingtown",
                StateName  = "Pennsylvania",
                Zip        = "19335",
                Condition  = ConditionType.WeakendImmuneSystem,
                Occupation = OccupationType.NoneOfTheAbove
            };

            var cache = new BrowserCache(5, data, Checker.Initializer, Checker.Resetter);

            var browser1 = cache.Pop();
            var browser2 = cache.Pop();

            cache.Push(browser1);

            browser1 = cache.Pop();
        }
Example #14
0
        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());
                }
            }
        }
Example #15
0
        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());
                }
            }
        }
 private void btnClearCache_Click(object sender, EventArgs e)
 {
     btnClearCache.Enabled = false;
     BrowserCache.SetClearOnExit();
     FormMessage.Information("Clear Cache", "Cache will be automatically cleared when TweetDuck exits.", FormMessage.OK);
 }
 /// <summary>
 /// 页面缓存
 /// </summary>
 /// <param name="server">服务缓存类型</param>
 /// <param name="browser">浏览器缓存类型</param>
 /// <param name="minutes">缓存时间</param>
 public PageCacheAttribute(ServerCache server, BrowserCache browser, int minutes)
 {
 }