Skip to content

Commit

Permalink
windows changeAppName fix
Browse files Browse the repository at this point in the history
  • Loading branch information
onatcipli committed Oct 16, 2023
1 parent b082e05 commit 44446c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.Create(L"rename appname", origin, size)) {
if (!window.Create(L"rename appname"), origin, size)) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
Expand Down
31 changes: 17 additions & 14 deletions lib/platform_file_editors/windows_platform_file_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,30 @@ class WindowsPlatformFileEditor extends AbstractPlatformFileEditor {
List? contentLineByLine = await readFileAsLineByline(
filePath: filePath,
);
for (var i = 0; i < contentLineByLine.length; i++) {
if (contentLineByLine[i].contains('window.CreateAndShow')) {
contentLineByLine[i] = contentLineByLine[i]
.replaceAllMapped(RegExp(r'CreateAndShow\(L"(.*?)"'), (match) {
return 'Create(L"$appName"';
});
break;
} else if (contentLineByLine[i].contains('window.Create')) {
contentLineByLine[i] = contentLineByLine[i]
.replaceAllMapped(RegExp(r'Create\(L"(.*?)"'), (match) {
return 'Create(L"$appName"';
});
break;
var currentAppName = await getAppName();
if (currentAppName != null) {
for (var i = 0; i < contentLineByLine.length; i++) {
if (contentLineByLine[i]?.contains('window.CreateAndShow') ?? false) {
contentLineByLine[i] = contentLineByLine[i]?.replaceFirst(
currentAppName,
appName,
);
break;
} else if (contentLineByLine[i]?.contains('window.Create') ?? false) {
contentLineByLine[i] = contentLineByLine[i]?.replaceFirst(
currentAppName,
appName,
);
break;
}
}
}
final message = await super.setAppName(appName: appName);
await writeFile(
filePath: filePath,
content: contentLineByLine.join('\n'),
);
return message;
return 'App name set to $appName';
}

/// Sets the bundle ID in the Windows Runner.rc file.
Expand Down

0 comments on commit 44446c5

Please sign in to comment.