/// <summary> /// Call initialize for all plugins /// </summary> /// <returns>return the list of failed to init plugins or null for none</returns> public static void InitializePlugins(IPublicAPI api) { API = api; var failedPlugins = new ConcurrentQueue <PluginPair>(); Parallel.ForEach(AllPlugins, pair => { try { var milliseconds = Stopwatch.Debug($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>", () => { pair.Plugin.Init(new PluginInitContext { CurrentPluginMetadata = pair.Metadata, API = API }); }); pair.Metadata.InitTime += milliseconds; Log.Info($"|PluginManager.InitializePlugins|Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>"); } catch (Exception e) { Log.Exception(nameof(PluginManager), $"Fail to Init plugin: {pair.Metadata.Name}", e); pair.Metadata.Disabled = true; failedPlugins.Enqueue(pair); } }); _contextMenuPlugins = GetPluginsForInterface <IContextMenu>(); foreach (var plugin in AllPlugins) { if (IsGlobalPlugin(plugin.Metadata)) { GlobalPlugins.Add(plugin); } // Plugins may have multiple ActionKeywords, eg. WebSearch plugin.Metadata.ActionKeywords .Where(x => x != Query.GlobalPluginWildcardSign) .ToList() .ForEach(x => NonGlobalPlugins[x] = plugin); } if (failedPlugins.Any()) { var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name)); API.ShowMsg($"Fail to Init Plugins", $"Plugins: {failed} - fail to load and would be disabled, please contact plugin creator for help", "", false); } }
private static bool OpenFileOrFolder(string program, string path, IPublicAPI contextApi) { try { Process.Start(program, path); } catch (Exception e) { string messageBoxTitle = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path); Log.Exception($"Failed to open {path} in {FileExplorerProgramName}, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType); contextApi.ShowMsg(messageBoxTitle, e.Message); } return(true); }
private void Launch(IPublicAPI api) { try { var appManager = new ApplicationActivationManager(); uint unusedPid; const string noArgs = ""; const ACTIVATEOPTIONS noFlags = ACTIVATEOPTIONS.AO_NONE; appManager.ActivateApplication(UserModelId, noArgs, noFlags, out unusedPid); } catch (Exception) { var name = "Plugin: Program"; var message = $"Can't start UWP: {DisplayName}"; api.ShowMsg(name, message, string.Empty); } }
private async void Launch(IPublicAPI api, string queryArguments) { var appManager = new ApplicationActivationHelper.ApplicationActivationManager(); const ApplicationActivationHelper.ActivateOptions noFlags = ApplicationActivationHelper.ActivateOptions.None; await Task.Run(() => { try { appManager.ActivateApplication(UserModelId, queryArguments, noFlags, out var unusedPid); } catch (Exception) { var name = "Plugin: " + Properties.Resources.wox_plugin_program_plugin_name; var message = $"{Properties.Resources.powertoys_run_plugin_program_uwp_failed}: {DisplayName}"; api.ShowMsg(name, message, string.Empty); } }).ConfigureAwait(false); }
private async void Launch(IPublicAPI api) { var appManager = new ApplicationActivationHelper.ApplicationActivationManager(); const string noArgs = ""; const ApplicationActivationHelper.ActivateOptions noFlags = ApplicationActivationHelper.ActivateOptions.None; await Task.Run(() => { try { appManager.ActivateApplication(UserModelId, noArgs, noFlags, out uint unusedPid); } catch (Exception) { var name = "Plugin: Program"; var message = $"Can't start UWP: {DisplayName}"; api.ShowMsg(name, message, string.Empty); } }).ConfigureAwait(false); }
private static bool OpenFileOrFolder(string path, IPublicAPI contextApi) { try { using (var process = new Process()) { process.StartInfo.FileName = path; process.StartInfo.UseShellExecute = true; process.Start(); } } catch (Exception e) { string messageBoxTitle = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path); Log.Exception($"Failed to open {path}, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType); contextApi.ShowMsg(messageBoxTitle, e.Message); } return(true); }
private async void Launch(IPublicAPI api) { var appManager = new ApplicationActivationManager(); uint unusedPid; const string noArgs = ""; const ACTIVATEOPTIONS noFlags = ACTIVATEOPTIONS.AO_NONE; await Task.Run(() => { try { appManager.ActivateApplication(UserModelId, noArgs, noFlags, out unusedPid); } catch (Exception) { var name = "Plugin: Program"; var message = $"Can't start UWP: {DisplayName}"; api.ShowMsg(name, message, string.Empty); } }); }
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true) { try { UpdateInfo newUpdateInfo; if (!silentUpdate) { api.ShowMsg(api.GetTranslation("pleaseWait"), api.GetTranslation("update_flowlauncher_update_check")); } using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false); // UpdateApp CheckForUpdate will return value only if the app is squirrel installed newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false); var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString()); var currentVersion = Version.Parse(Constant.Version); Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>"); if (newReleaseVersion <= currentVersion) { if (!silentUpdate) { MessageBox.Show(api.GetTranslation("update_flowlauncher_already_on_latest")); } return; } if (!silentUpdate) { api.ShowMsg(api.GetTranslation("update_flowlauncher_update_found"), api.GetTranslation("update_flowlauncher_updating")); } await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false); await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false); if (DataLocation.PortableDataLocationInUse()) { var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}"; FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination); if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination)) { MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"), DataLocation.PortableDataPath, targetDestination)); } } else { await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false); } var newVersionTips = NewVersinoTips(newReleaseVersion.ToString()); Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}"); if (MessageBox.Show(newVersionTips, api.GetTranslation("update_flowlauncher_new_update"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) { UpdateManager.RestartApp(Constant.ApplicationFileName); } } catch (Exception e) when(e is HttpRequestException || e is WebException || e is SocketException || e is TaskCanceledException) { Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e); api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"), api.GetTranslation("update_flowlauncher_check_connection")); return; } }
public Result Result(string query, IPublicAPI api) { string title; MatchResult matchResult; // We suppose Name won't be null if (!Main._settings.EnableDescription || Description == null || Name.StartsWith(Description)) { title = Name; matchResult = StringMatcher.FuzzySearch(query, title); } else if (Description.StartsWith(Name)) { title = Description; matchResult = StringMatcher.FuzzySearch(query, Description); } else { title = $"{Name}: {Description}"; var nameMatch = StringMatcher.FuzzySearch(query, Name); var desciptionMatch = StringMatcher.FuzzySearch(query, Description); if (desciptionMatch.Score > nameMatch.Score) { for (int i = 0; i < desciptionMatch.MatchData.Count; i++) { desciptionMatch.MatchData[i] += Name.Length + 2; // 2 is ": " } matchResult = desciptionMatch; } else { matchResult = nameMatch; } } if (!matchResult.Success) { return(null); } var result = new Result { Title = title, SubTitle = Main._settings.HideAppsPath ? string.Empty : Package.Location, Icon = Logo, Score = matchResult.Score, TitleHighlightData = matchResult.MatchData, ContextData = this, Action = e => { var elevated = ( e.SpecialKeyState.CtrlPressed && e.SpecialKeyState.ShiftPressed && !e.SpecialKeyState.AltPressed && !e.SpecialKeyState.WinPressed ); if (elevated && CanRunElevated) { LaunchElevated(); } else { Launch(api); if (elevated) { var title = "Plugin: Program"; var message = api.GetTranslation("flowlauncher_plugin_program_run_as_administrator_not_supported_message"); api.ShowMsg(title, message, string.Empty); } } return(true); } }; return(result); }
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true) { try { UpdateInfo newUpdateInfo; if (!silentUpdate) { api.ShowMsg("Please wait...", "Checking for new update"); } using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false); // UpdateApp CheckForUpdate will return value only if the app is squirrel installed newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false); var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString()); var currentVersion = Version.Parse(Constant.Version); Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>"); if (newReleaseVersion <= currentVersion) { if (!silentUpdate) { MessageBox.Show("You already have the latest Flow Launcher version"); } return; } if (!silentUpdate) { api.ShowMsg("Update found", "Updating..."); } await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false); await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false); if (DataLocation.PortableDataLocationInUse()) { var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}"; FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination); if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination)) { MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " + $"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}"); } } else { await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false); } var newVersionTips = NewVersinoTips(newReleaseVersion.ToString()); Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}"); if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { UpdateManager.RestartApp(Constant.ApplicationFileName); } } catch (Exception e) when(e is HttpRequestException || e is WebException || e is SocketException) { Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e); api.ShowMsg("Update Failed", "Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com."); return; } }