mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 09:17:36 +13:00
fixed #6317: await OCRImage inside HandleHotkeys
This commit is contained in:
parent
f7f6870502
commit
101c4e12db
5 changed files with 37 additions and 30 deletions
|
@ -327,14 +327,14 @@ private void UpdateToolbar(List<HotkeyType> actions)
|
||||||
Image = TaskHelpers.FindMenuIcon(action)
|
Image = TaskHelpers.FindMenuIcon(action)
|
||||||
};
|
};
|
||||||
|
|
||||||
tsb.Click += (sender, e) =>
|
tsb.Click += async (sender, e) =>
|
||||||
{
|
{
|
||||||
if (Program.Settings.ActionsToolbarStayTopMost)
|
if (Program.Settings.ActionsToolbarStayTopMost)
|
||||||
{
|
{
|
||||||
TopMost = false;
|
TopMost = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskHelpers.ExecuteJob(action);
|
await TaskHelpers.ExecuteJob(action);
|
||||||
|
|
||||||
if (Program.Settings.ActionsToolbarStayTopMost)
|
if (Program.Settings.ActionsToolbarStayTopMost)
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,7 +54,7 @@ public MainForm()
|
||||||
InitializeControls();
|
InitializeControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_HandleCreated(object sender, EventArgs e)
|
private async void MainForm_HandleCreated(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
RunPuushTasks();
|
RunPuushTasks();
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ private void MainForm_HandleCreated(object sender, EventArgs e)
|
||||||
|
|
||||||
DebugHelper.WriteLine("Startup time: {0} ms", Program.StartTimer.ElapsedMilliseconds);
|
DebugHelper.WriteLine("Startup time: {0} ms", Program.StartTimer.ElapsedMilliseconds);
|
||||||
|
|
||||||
Program.CLI.UseCommandLineArgs();
|
await Program.CLI.UseCommandLineArgs();
|
||||||
|
|
||||||
if (Program.Settings.ActionsToolbarRunAtStartup)
|
if (Program.Settings.ActionsToolbarRunAtStartup)
|
||||||
{
|
{
|
||||||
|
@ -350,11 +350,11 @@ private void InitHotkeys()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleHotkeys(HotkeySettings hotkeySetting)
|
private async void HandleHotkeys(HotkeySettings hotkeySetting)
|
||||||
{
|
{
|
||||||
DebugHelper.WriteLine("Hotkey triggered. " + hotkeySetting);
|
DebugHelper.WriteLine("Hotkey triggered. " + hotkeySetting);
|
||||||
|
|
||||||
TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings);
|
await TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateWorkflowsMenu()
|
private void UpdateWorkflowsMenu()
|
||||||
|
@ -436,7 +436,7 @@ private ToolStripMenuItem WorkflowMenuItem(HotkeySettings hotkeySetting)
|
||||||
{
|
{
|
||||||
tsmi.Font = new Font(tsmi.Font, FontStyle.Bold);
|
tsmi.Font = new Font(tsmi.Font, FontStyle.Bold);
|
||||||
}
|
}
|
||||||
tsmi.Click += (sender, e) => TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings);
|
tsmi.Click += async (sender, e) => await TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings);
|
||||||
return tsmi;
|
return tsmi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1947,13 +1947,13 @@ private void tsbAbout_Click(object sender, EventArgs e)
|
||||||
|
|
||||||
#region Tray events
|
#region Tray events
|
||||||
|
|
||||||
private void niTray_MouseUp(object sender, MouseEventArgs e)
|
private async void niTray_MouseUp(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == MouseButtons.Left)
|
if (e.Button == MouseButtons.Left)
|
||||||
{
|
{
|
||||||
if (Program.Settings.TrayLeftDoubleClickAction == HotkeyType.None)
|
if (Program.Settings.TrayLeftDoubleClickAction == HotkeyType.None)
|
||||||
{
|
{
|
||||||
TaskHelpers.ExecuteJob(Program.Settings.TrayLeftClickAction);
|
await TaskHelpers.ExecuteJob(Program.Settings.TrayLeftClickAction);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1969,24 +1969,24 @@ private void niTray_MouseUp(object sender, MouseEventArgs e)
|
||||||
trayClickCount = 0;
|
trayClickCount = 0;
|
||||||
timerTraySingleClick.Stop();
|
timerTraySingleClick.Stop();
|
||||||
|
|
||||||
TaskHelpers.ExecuteJob(Program.Settings.TrayLeftDoubleClickAction);
|
await TaskHelpers.ExecuteJob(Program.Settings.TrayLeftDoubleClickAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (e.Button == MouseButtons.Middle)
|
else if (e.Button == MouseButtons.Middle)
|
||||||
{
|
{
|
||||||
TaskHelpers.ExecuteJob(Program.Settings.TrayMiddleClickAction);
|
await TaskHelpers.ExecuteJob(Program.Settings.TrayMiddleClickAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timerTraySingleClick_Tick(object sender, EventArgs e)
|
private async void timerTraySingleClick_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (trayClickCount == 1)
|
if (trayClickCount == 1)
|
||||||
{
|
{
|
||||||
trayClickCount = 0;
|
trayClickCount = 0;
|
||||||
timerTraySingleClick.Stop();
|
timerTraySingleClick.Stop();
|
||||||
|
|
||||||
TaskHelpers.ExecuteJob(Program.Settings.TrayLeftClickAction);
|
await TaskHelpers.ExecuteJob(Program.Settings.TrayLeftClickAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ You should have received a copy of the GNU General Public License
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
#if MicrosoftStore
|
#if MicrosoftStore
|
||||||
|
@ -394,7 +395,10 @@ private static void SingleInstanceCallback(object sender, InstanceCallbackEventA
|
||||||
{
|
{
|
||||||
if (WaitFormLoad(5000))
|
if (WaitFormLoad(5000))
|
||||||
{
|
{
|
||||||
MainForm.InvokeSafe(() => UseCommandLineArgs(args.CommandLineArgs));
|
MainForm.InvokeSafe(async () =>
|
||||||
|
{
|
||||||
|
await UseCommandLineArgs(args.CommandLineArgs);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +416,7 @@ private static bool WaitFormLoad(int wait)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UseCommandLineArgs(string[] args)
|
private static async Task UseCommandLineArgs(string[] args)
|
||||||
{
|
{
|
||||||
if (args == null || args.Length < 1)
|
if (args == null || args.Length < 1)
|
||||||
{
|
{
|
||||||
|
@ -433,7 +437,7 @@ private static void UseCommandLineArgs(string[] args)
|
||||||
CLIManager cli = new CLIManager(args);
|
CLIManager cli = new CLIManager(args);
|
||||||
cli.ParseCommands();
|
cli.ParseCommands();
|
||||||
|
|
||||||
CLI.UseCommandLineArgs(cli.Commands);
|
await CLI.UseCommandLineArgs(cli.Commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdatePersonalPath()
|
private static void UpdatePersonalPath()
|
||||||
|
|
|
@ -27,6 +27,7 @@ You should have received a copy of the GNU General Public License
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ShareX
|
namespace ShareX
|
||||||
{
|
{
|
||||||
|
@ -36,12 +37,12 @@ public ShareXCLIManager(string[] arguments) : base(arguments)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UseCommandLineArgs()
|
public async Task UseCommandLineArgs()
|
||||||
{
|
{
|
||||||
UseCommandLineArgs(Commands);
|
await UseCommandLineArgs(Commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UseCommandLineArgs(List<CLICommand> commands)
|
public async Task UseCommandLineArgs(List<CLICommand> commands)
|
||||||
{
|
{
|
||||||
TaskSettings taskSettings = FindCLITask(commands);
|
TaskSettings taskSettings = FindCLITask(commands);
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ public void UseCommandLineArgs(List<CLICommand> commands)
|
||||||
|
|
||||||
if (command.IsCommand)
|
if (command.IsCommand)
|
||||||
{
|
{
|
||||||
if (CheckCustomUploader(command) || CheckImageEffect(command) || CheckCLIHotkey(command) || CheckCLIWorkflow(command) ||
|
if (CheckCustomUploader(command) || CheckImageEffect(command) || await CheckCLIHotkey(command) || await CheckCLIWorkflow(command) ||
|
||||||
CheckNativeMessagingInput(command))
|
CheckNativeMessagingInput(command))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -121,13 +122,14 @@ private bool CheckImageEffect(CLICommand command)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckCLIHotkey(CLICommand command)
|
private async Task<bool> CheckCLIHotkey(CLICommand command)
|
||||||
{
|
{
|
||||||
foreach (HotkeyType job in Helpers.GetEnums<HotkeyType>())
|
foreach (HotkeyType job in Helpers.GetEnums<HotkeyType>())
|
||||||
{
|
{
|
||||||
if (command.CheckCommand(job.ToString()))
|
if (command.CheckCommand(job.ToString()))
|
||||||
{
|
{
|
||||||
TaskHelpers.ExecuteJob(job, command);
|
await TaskHelpers.ExecuteJob(job, command);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +137,7 @@ private bool CheckCLIHotkey(CLICommand command)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckCLIWorkflow(CLICommand command)
|
private async Task<bool> CheckCLIWorkflow(CLICommand command)
|
||||||
{
|
{
|
||||||
if (Program.HotkeysConfig != null && command.CheckCommand("workflow") && !string.IsNullOrEmpty(command.Parameter))
|
if (Program.HotkeysConfig != null && command.CheckCommand("workflow") && !string.IsNullOrEmpty(command.Parameter))
|
||||||
{
|
{
|
||||||
|
@ -145,7 +147,8 @@ private bool CheckCLIWorkflow(CLICommand command)
|
||||||
{
|
{
|
||||||
if (command.Parameter == hotkeySetting.TaskSettings.ToString())
|
if (command.Parameter == hotkeySetting.TaskSettings.ToString())
|
||||||
{
|
{
|
||||||
TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings);
|
await TaskHelpers.ExecuteJob(hotkeySetting.TaskSettings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,17 +52,17 @@ namespace ShareX
|
||||||
{
|
{
|
||||||
public static class TaskHelpers
|
public static class TaskHelpers
|
||||||
{
|
{
|
||||||
public static void ExecuteJob(HotkeyType job, CLICommand command = null)
|
public static async Task ExecuteJob(HotkeyType job, CLICommand command = null)
|
||||||
{
|
{
|
||||||
ExecuteJob(Program.DefaultTaskSettings, job, command);
|
await ExecuteJob(Program.DefaultTaskSettings, job, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExecuteJob(TaskSettings taskSettings)
|
public static async Task ExecuteJob(TaskSettings taskSettings)
|
||||||
{
|
{
|
||||||
ExecuteJob(taskSettings, taskSettings.Job);
|
await ExecuteJob(taskSettings, taskSettings.Job);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLICommand command = null)
|
public static async Task ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLICommand command = null)
|
||||||
{
|
{
|
||||||
if (job == HotkeyType.None) return;
|
if (job == HotkeyType.None) return;
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLIComm
|
||||||
OpenVideoThumbnailer(safeTaskSettings);
|
OpenVideoThumbnailer(safeTaskSettings);
|
||||||
break;
|
break;
|
||||||
case HotkeyType.OCR:
|
case HotkeyType.OCR:
|
||||||
OCRImage(safeTaskSettings).GetAwaiter().GetResult();
|
await OCRImage(safeTaskSettings);
|
||||||
break;
|
break;
|
||||||
case HotkeyType.QRCode:
|
case HotkeyType.QRCode:
|
||||||
OpenQRCode();
|
OpenQRCode();
|
||||||
|
|
Loading…
Reference in a new issue