-
Notifications
You must be signed in to change notification settings - Fork 73
How To Create Desktop Shortcut
Yehuda Kremer edited this page Nov 29, 2021
·
2 revisions
Msix installer not support desktop shortcuts
But you can create desktop shortcut file (.link) programmatically. first check if the app is running for the first time, if so, create desktop shortcut.
- download .lnk file: MyAppName.zip
- edit the .lnk file name to what ever you want
- right click on the .lnk file and open properties, edit the field Target: change the "...[flutter_again_2].exe" to your app name (same value as
name:
from your pubspec.yaml), and save - create assets folder called "myAssets" in your project folder, and copy to it the .lnk file
- use the latest version of msix package:
2.6.4
or later - add to your
msix_config
:
add_execution_alias: true
assets_directory_path: 'C:\Users\me\Desktop\your_project_path\myAssets'
- edit your
main.dart
:
Future<void> _moveLnkFileToDesktop() async {
// "my_app_name" is the value of "name:" in your pubspec.yaml
String myAppDataPath = '${Platform.environment['AppData']}\\my_app_name';
try {
var myAppDataDirectoryExists = await Directory(myAppDataPath).exists();
//if myAppDataDirectoryExists is false then the app is running for the first time
if (!myAppDataDirectoryExists) {
await Directory(myAppDataPath).create();
await File('${File(Platform.resolvedExecutable).parent.path}\\myAssets\\MyAppName.lnk')
.copy('${Platform.environment['USERPROFILE']}\\desktop\\MyAppName.lnk');
}
} catch (e) {
//log
}
}
void main() {
runApp(MyApp());
_moveLnkFileToDesktop();
}
in this code update your app name and the .lnk file name
And that is, this function will copy the .lnk file to the user desktop, only the first time the app will open (usually after the msix is finish installing)
TA DA: