Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Flow.Launcher.Core/ExternalPlugins/FlowPluginException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Flow.Launcher.Plugin;
using System;

namespace Flow.Launcher.Core.ExternalPlugins
{
public class FlowPluginException : Exception
{
public PluginMetadata Metadata { get; set; }

public FlowPluginException(PluginMetadata metadata, Exception e) : base(e.Message, e)
{
Metadata = metadata;
}

public override string ToString()
{
return $@"{Metadata.Name} Exception:
Websites: {Metadata.Website}
Author: {Metadata.Author}
Version: {Metadata.Version}
{base.ToString()}";
}
}
}
38 changes: 20 additions & 18 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Flow.Launcher.Core.ExternalPlugins;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -165,30 +166,28 @@ public static async Task InitializePlugins(IPublicAPI api)

public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
{
if (NonGlobalPlugins.ContainsKey(query.ActionKeyword))
{
var plugin = NonGlobalPlugins[query.ActionKeyword];
return new List<PluginPair>
{
plugin
};
}
else
{
if (query is null)
return Array.Empty<PluginPair>();

if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword))
return GlobalPlugins;
}


var plugin = NonGlobalPlugins[query.ActionKeyword];
return new List<PluginPair>
{
plugin
};
}

public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token)
{
var results = new List<Result>();
var metadata = pair.Metadata;

try
{
var metadata = pair.Metadata;

long milliseconds = -1L;

milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));

token.ThrowIfCancellationRequested();
Expand All @@ -206,7 +205,10 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
return null;
}

catch (Exception e)
{
throw new FlowPluginException(metadata, e);
}
return results;
}

Expand Down
4 changes: 4 additions & 0 deletions Flow.Launcher.Core/Resource/AvailableLanguages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal static class AvailableLanguages
public static Language Serbian = new Language("sr", "Srpski");
public static Language Portuguese_Portugal = new Language("pt-pt", "Português");
public static Language Portuguese_Brazil = new Language("pt-br", "Português (Brasil)");
public static Language Spanish = new Language("es", "Spanish");
public static Language Spanish_LatinAmerica = new Language("es-419", "Spanish (Latin America)");
public static Language Italian = new Language("it", "Italiano");
public static Language Norwegian_Bokmal = new Language("nb-NO", "Norsk Bokmål");
public static Language Slovak = new Language("sk", "Slovenský");
Expand All @@ -43,6 +45,8 @@ public static List<Language> GetAvailableLanguages()
Serbian,
Portuguese_Portugal,
Portuguese_Brazil,
Spanish,
Spanish_LatinAmerica,
Italian,
Norwegian_Bokmal,
Slovak,
Expand Down
5 changes: 4 additions & 1 deletion Flow.Launcher.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public bool ChangeTheme(string theme)

Settings.Theme = theme;

// reload all resources even if the theme itself hasn't changed in order to pickup changes
// to things like fonts
UpdateResourceDictionary(GetResourceDictionary());

//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
if (_oldTheme != theme || theme == defaultTheme)
{
UpdateResourceDictionary(GetResourceDictionary());
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
}

Expand Down
18 changes: 13 additions & 5 deletions Flow.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -104,14 +104,22 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
});
}


private void AutoStartup()
{
if (_settings.StartFlowLauncherOnSystemStartup)
// we try to enable auto-startup on first launch, or reenable if it was removed
// but the user still has the setting set
if (_settings.StartFlowLauncherOnSystemStartup && !Helper.AutoStartup.IsEnabled)
{
if (!SettingWindow.StartupSet())
try
{
Helper.AutoStartup.Enable();
}
catch (Exception e)
{
SettingWindow.SetStartup();
// but if it fails (permissions, etc) then don't keep retrying
// this also gives the user a visual indication in the Settings widget
_settings.StartFlowLauncherOnSystemStartup = false;
Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), e.Message);
}
}
}
Expand Down
63 changes: 63 additions & 0 deletions Flow.Launcher/Helper/AutoStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Microsoft.Win32;

namespace Flow.Launcher.Helper
{
public class AutoStartup
{
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";

public static bool IsEnabled
{
get
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
var path = key?.GetValue(Constant.FlowLauncher) as string;
return path == Constant.ExecutablePath;
}
catch (Exception e)
{
Log.Error("AutoStartup", $"Ignoring non-critical registry error (querying if enabled): {e}");
}

return false;
}
}

public static void Disable()
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
key?.DeleteValue(Constant.FlowLauncher, false);
}
catch (Exception e)
{
Log.Error("AutoStartup", $"Failed to disable auto-startup: {e}");
throw;
}
}

internal static void Enable()
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
}
catch (Exception e)
{
Log.Error("AutoStartup", $"Failed to enable auto-startup: {e}");
throw;
}
}
}
}
1 change: 1 addition & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<system:String x:Key="portableMode">Portable Mode</system:String>
<system:String x:Key="portableModeToolTIp">Store all settings and user data in one folder (Useful when used with removable drives or cloud services).</system:String>
<system:String x:Key="startFlowLauncherOnSystemStartup">Start Flow Launcher on system startup</system:String>
<system:String x:Key="setAutoStartFailed">Error setting launch on startup</system:String>
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Hide Flow Launcher when focus is lost</system:String>
<system:String x:Key="dontPromptUpdateMsg">Do not show new version notifications</system:String>
<system:String x:Key="rememberLastLocation">Remember last launch location</system:String>
Expand Down
Loading