Ejemplo n.º 1
0
 public static void CreateSettingsIfNotExists()
 {
     if (!SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
     {
         Log.Info("|SettingsWatcher.OverloadSettings|PT Run settings.json was missing, creating a new one");
         var defaultSettings = new PowerLauncherSettings();
         defaultSettings.Save();
     }
 }
Ejemplo n.º 2
0
        public void CreateSettingsIfNotExists()
        {
            if (!_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
            {
                Log.Info("PT Run settings.json was missing, creating a new one", GetType());

                var defaultSettings = new PowerLauncherSettings();
                defaultSettings.Save(_settingsUtils);
            }
        }
Ejemplo n.º 3
0
        public void OverloadSettings()
        {
            Monitor.Enter(_watcherSyncObject);
            var retry      = true;
            var retryCount = 0;

            while (retry)
            {
                try
                {
                    retryCount++;
                    if (!SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
                    {
                        Debug.WriteLine("PT Run settings.json was missing, creating a new one");

                        var defaultSettings = new PowerLauncherSettings();
                        defaultSettings.Save();
                    }

                    var overloadSettings = SettingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.ModuleName);

                    var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher);
                    if (_settings.Hotkey != openPowerlauncher)
                    {
                        _settings.Hotkey = openPowerlauncher;
                    }

                    var shell = PluginManager.AllPlugins.Find(pp => pp.Metadata.Name == "Shell");
                    if (shell != null)
                    {
                        var shellSettings = shell.Plugin as ISettingProvider;
                        shellSettings.UpdateSettings(overloadSettings);
                    }

                    if (_settings.MaxResultsToShow != overloadSettings.Properties.MaximumNumberOfResults)
                    {
                        _settings.MaxResultsToShow = overloadSettings.Properties.MaximumNumberOfResults;
                    }

                    if (_settings.IgnoreHotkeysOnFullscreen != overloadSettings.Properties.IgnoreHotkeysInFullscreen)
                    {
                        _settings.IgnoreHotkeysOnFullscreen = overloadSettings.Properties.IgnoreHotkeysInFullscreen;
                    }

                    var indexer = PluginManager.AllPlugins.Find(p => p.Metadata.Name.Equals("Windows Indexer Plugin", StringComparison.OrdinalIgnoreCase));
                    if (indexer != null)
                    {
                        var indexerSettings = indexer.Plugin as ISettingProvider;
                        indexerSettings.UpdateSettings(overloadSettings);
                    }

                    if (_settings.ClearInputOnLaunch != overloadSettings.Properties.ClearInputOnLaunch)
                    {
                        _settings.ClearInputOnLaunch = overloadSettings.Properties.ClearInputOnLaunch;
                    }

                    retry = false;
                }

                // the settings application can hold a lock on the settings.json file which will result in a IOException.
                // This should be changed to properly synch with the settings app instead of retrying.
                catch (IOException e)
                {
                    if (retryCount > _maxRetries)
                    {
                        retry = false;
                    }

                    Thread.Sleep(1000);
                    Debug.WriteLine(e.Message);
                }
            }

            Monitor.Exit(_watcherSyncObject);
        }