Flutter桌面应用实现只启动一次(单实例)
简介很多时候我们只希望我们的应用只能启动一次,本文主要介绍下Flutter的windows桌面端如何实现只启动一次的方法。
最先看网上说只启动一次需要修改C++代码,参考文档如下:
Run only single instance of flutter desktop application
代码内容如下:
HANDLE hMutexHandle=CreateMutex(NULL, TRUE, L"my.mutex.name");
HWND handle=FindWindowA(NULL, "Test Application");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
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;
}
操作那么多实在看不懂,毕竟没有写过C++。通过继续努力寻找,终于在现有的插件中,有这样一款插件可以实现。
Add WidgetsFlutterBinding.ensureInitialized(); to the start of your apps main function.
Add the async modifier to your apps main function.
Add a call to WindowsSingleInstance.ensureSingleInstance(), passing the apps startup args, a custom app string unique to your app (a-z, 0-9, _ and - only), and an optional callback function.
使用非常简单
void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
//单实例启动
await WindowsSingleInstance.ensureSingleInstance(args, "app_id",
onSecondWindow: (args) async {
if (await windowManager.isMinimized()) {
windowManager.restore();
}
windowManager.focus();
});
runApp(const MyApp());
}
以上就可以实现单实例启动了。
快速生成表格
在使用Laravel中如果要进行复杂的查询,那么通过模型中的函数来查询是不行的,所以本文主要记录如何通过aggregate来进行复杂的查询。
网页扫描二维码库:Html5-Qrcode,官网地址:https://scanapp.org/html5-qrcode-docs/
nodejs中使用npm和yarn,使用最新阿里云镜像 aliyun mirror,网上很多还是文章用的是下面这个地址~~yarn config set registry https://registry.npm.taobao.org~~
某些时候我们需要通过在使用count的过程中,只需要计算某些条件下的记录数,这时候我们就需要使用到Count条件计数问题。
Electron页面跳转、浏览器打开链接和打开新窗口
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。