This commit is contained in:
Dain Nilsson 2022-01-21 11:22:52 +01:00
commit dbf27f7972
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
2 changed files with 29 additions and 6 deletions

View File

@ -17,6 +17,7 @@ import 'error_page.dart';
final log = Logger('main');
void main() async {
_initLogging(Level.INFO);
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
@ -43,8 +44,8 @@ void main() async {
try {
var rpc = await RpcSession.launch(exe!);
// Enable logging TODO: Make this configurable
_initLogging(Level.INFO, rpc);
log.info('ykman process started', exe);
rpc.setLogLevel(Logger.root.level);
overrides.add(rpcProvider.overrideWithValue(rpc));
page = const MainPage();
} catch (e) {
@ -52,8 +53,8 @@ void main() async {
page = ErrorPage(error: e.toString());
}
// Only MacOS supports hiding the window at start currently.
// For now, this size should match windows/runner/main.cpp and linux/flutter/my_application.cc
// Linux doesn't currently support hiding the window at start currently.
// For now, this size should match linux/flutter/my_application.cc to avoid window flicker at startup.
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setSize(const Size(400, 720));
windowManager.show();
@ -65,7 +66,7 @@ void main() async {
));
}
void _initLogging(Level level, RpcSession rpc) {
void _initLogging(Level level) {
//TODO: Add support for logging to stderr and file
Logger.root.onRecord.listen((record) {
developer.log(
@ -78,7 +79,6 @@ void _initLogging(Level level, RpcSession rpc) {
});
Logger.root.level = level;
rpc.setLogLevel(level);
}
//TODO: Remove below this

View File

@ -107,6 +107,28 @@ bool Win32Window::CreateAndShow(const std::wstring& title,
const Size& size) {
Destroy();
// Attempt to create a mutex to enforce single instance.
CreateMutex(NULL, TRUE, L"com.yubico.authenticator.mutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
HWND handle=FindWindowA(NULL, "Yubico Authenticator");
WINDOWPLACEMENT place = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(handle, &place);
switch(place.showCmd) {
case SW_SHOWMAXIMIZED:
ShowWindow(handle, SW_SHOWMAXIMIZED);
break;
case SW_SHOWMINIMIZED:
ShowWindow(handle, SW_RESTORE);
break;
default:
ShowWindow(handle, SW_NORMAL);
break;
}
SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
SetForegroundWindow(handle);
return 0;
}
const wchar_t* window_class =
WindowClassRegistrar::GetInstance()->GetWindowClass();
@ -117,7 +139,8 @@ bool Win32Window::CreateAndShow(const std::wstring& title,
double scale_factor = dpi / 96.0;
HWND window = CreateWindow(
window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
//original line: window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
nullptr, nullptr, GetModuleHandle(nullptr), this);