28 lines
1.3 KiB
C++
28 lines
1.3 KiB
C++
#include "app.h"
|
|
#include "screenshot_notifications.h"
|
|
|
|
namespace ks {
|
|
static void launch(App &app, const Clip *clip)
|
|
{
|
|
auto path=std::filesystem::path(executable()).parent_path()/L"KSwitcher.Screenshot.exe";
|
|
if (!std::filesystem::exists(path))
|
|
throw std::runtime_error("KSwitcher.Screenshot.exe is missing. Extract the complete application package.");
|
|
auto command=L"\""+path.wstring()+L"\" ";
|
|
if(clip) command+=L"--open kswitcher-screenshot:"+cacheScreenshotForEditor(*clip);
|
|
else command+=std::wstring(L"--auto-open-editor=")+(app.settings.screenshotAutoOpenEditor?L"1":L"0");
|
|
if(app.settings.writeLog) command+=L" --write-log";
|
|
STARTUPINFOW startup{sizeof(startup)};
|
|
PROCESS_INFORMATION process{};
|
|
// Grant foreground rights before the child's first selection window opens.
|
|
if (!CreateProcessW(path.c_str(),command.data(),nullptr,nullptr,FALSE,CREATE_SUSPENDED,
|
|
nullptr,path.parent_path().c_str(),&startup,&process))
|
|
throw std::runtime_error(utf8(lastError(L"Cannot start screenshot editor")));
|
|
AllowSetForegroundWindow(process.dwProcessId);
|
|
ResumeThread(process.hThread);
|
|
CloseHandle(process.hThread);
|
|
CloseHandle(process.hProcess);
|
|
}
|
|
void launchScreenshot(App &app) { launch(app,nullptr); }
|
|
void launchScreenshotEditor(App &app,const Clip &clip) { launch(app,&clip); }
|
|
}
|