glp-companion/windows/runner/utils.h

39 lines
1.6 KiB
C++

#ifndef RUNNER_UTILS_H_
#define RUNNER_UTILS_H_
#include <string>
#include <vector>
// Creates a console for the process, and redirects stdout and stderr to
// it for both the runner and the Flutter library.
void CreateAndAttachConsole();
// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
// encoded in UTF-8. Returns an empty std::string on failure.
std::string Utf8FromUtf16(const wchar_t* utf16_string);
// Gets the command line arguments passed in as a std::vector<std::string>,
// encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
std::vector<std::string> GetCommandLineArguments();
// Registers the per-user URL protocol (HKCU\Software\Classes) for OAuth /
// magic-link callbacks so Windows routes com.companionglp.glpcompanion://
// links to this executable. Idempotent and requires no elevation.
void RegisterAppLinkProtocol();
// Appends a timestamped line to %TEMP%\glpcompanion-protocol.log and the
// debugger output stream. Used to diagnose the OAuth custom-scheme handoff.
void LogAppLink(const std::string& message);
// True when this process was started by Windows protocol activation, i.e.
// its command line carries a single URI argument such as
// com.companionglp.glpcompanion://login-callback/?code=...
bool HasAppLinkArgument();
// Claims the per-session single-instance mutex for this process. Returns
// false when a previous instance already owns it (callers should then
// activate that instance and exit instead of starting a competing window).
bool AcquireSingleInstanceMutex();
#endif // RUNNER_UTILS_H_