From a71bd025a063e8ae465a8587c5d287971e9f7717 Mon Sep 17 00:00:00 2001 From: cjsimon Date: Sat, 28 Jun 2025 04:55:03 -0400 Subject: [PATCH 1/2] Use updated linux runner path as of flutter 3.27.0, and fallback to legacy path --- .../linux_platform_file_editor.dart | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/platform_file_editors/linux_platform_file_editor.dart b/lib/platform_file_editors/linux_platform_file_editor.dart index efce405..dc168bf 100644 --- a/lib/platform_file_editors/linux_platform_file_editor.dart +++ b/lib/platform_file_editors/linux_platform_file_editor.dart @@ -4,6 +4,7 @@ /// Created Date: 24.09.2023 /// Description: This file is responsible for editing Linux platform files. +import 'package:rename/custom_exceptions.dart'; import 'package:rename/enums.dart'; import 'package:rename/platform_file_editors/abs_platform_file_editor.dart'; import 'package:rename/utils/files.dart'; @@ -19,6 +20,10 @@ class LinuxPlatformFileEditor extends AbstractPlatformFileEditor { ['linux', 'CMakeLists.txt'], ); String linuxAppCppPath = convertPath( + ['linux', 'runner', 'my_application.cc'], + ); + + final String _legacyLinuxAppCppPath = convertPath( ['linux', 'my_application.cc'], ); @@ -55,11 +60,26 @@ class LinuxPlatformFileEditor extends AbstractPlatformFileEditor { /// Returns: Future, the bundle ID if found, null otherwise. @override Future getBundleId() async { - final filePath = linuxAppCppPath; - var contentLineByLine = await readFileAsLineByline( - filePath: filePath, - platform: platform, - ); + var filePath = linuxAppCppPath; + var contentLineByLine; + try { + contentLineByLine = await readFileAsLineByline( + filePath: filePath, + platform: platform, + ); + } on FileReadException catch(e) { + try { + var legacyFilePath = _legacyLinuxAppCppPath; + contentLineByLine = await readFileAsLineByline( + filePath: legacyFilePath, + platform: platform, + ); + filePath = legacyFilePath; + } on FileReadException { + print(e); + rethrow; + } + } for (var i = 0; i < contentLineByLine.length; i++) { if (contentLineByLine[i]?.contains('kFlutterWindowTitle') ?? false) { var match = RegExp(r'kFlutterWindowTitle = "(.*?)"') @@ -106,11 +126,26 @@ class LinuxPlatformFileEditor extends AbstractPlatformFileEditor { /// Returns: Future, a success message indicating the change in bundle ID. @override Future setBundleId({required String bundleId}) async { - final filePath = linuxAppCppPath; - List? contentLineByLine = await readFileAsLineByline( - filePath: filePath, - platform: platform, - ); + var filePath = linuxAppCppPath; + List? contentLineByLine; + try { + contentLineByLine = await readFileAsLineByline( + filePath: filePath, + platform: platform, + ); + } on FileReadException catch(e) { + try { + var legacyFilePath = _legacyLinuxAppCppPath; + contentLineByLine = await readFileAsLineByline( + filePath: legacyFilePath, + platform: platform, + ); + filePath = legacyFilePath; + } on FileReadException { + print(e); + rethrow; + } + } for (var i = 0; i < contentLineByLine.length; i++) { if (contentLineByLine[i].contains('kFlutterWindowTitle')) { contentLineByLine[i] = From ef7a3f2d1319c4f4d9aa33e57c7fc38425a43aa1 Mon Sep 17 00:00:00 2001 From: cjsimon Date: Sat, 28 Jun 2025 06:58:12 -0400 Subject: [PATCH 2/2] Fix new bundle id and fallback to old --- .../linux_platform_file_editor.dart | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/lib/platform_file_editors/linux_platform_file_editor.dart b/lib/platform_file_editors/linux_platform_file_editor.dart index dc168bf..75b6abb 100644 --- a/lib/platform_file_editors/linux_platform_file_editor.dart +++ b/lib/platform_file_editors/linux_platform_file_editor.dart @@ -4,7 +4,6 @@ /// Created Date: 24.09.2023 /// Description: This file is responsible for editing Linux platform files. -import 'package:rename/custom_exceptions.dart'; import 'package:rename/enums.dart'; import 'package:rename/platform_file_editors/abs_platform_file_editor.dart'; import 'package:rename/utils/files.dart'; @@ -55,31 +54,29 @@ class LinuxPlatformFileEditor extends AbstractPlatformFileEditor { return null; } - /// Fetches the bundle ID from the Linux my_application.cc file. + /// Fetches the bundle ID from the Linux CMakeLists.txt file. /// /// Returns: Future, the bundle ID if found, null otherwise. @override Future getBundleId() async { - var filePath = linuxAppCppPath; - var contentLineByLine; - try { - contentLineByLine = await readFileAsLineByline( - filePath: filePath, - platform: platform, - ); - } on FileReadException catch(e) { - try { - var legacyFilePath = _legacyLinuxAppCppPath; - contentLineByLine = await readFileAsLineByline( - filePath: legacyFilePath, - platform: platform, - ); - filePath = legacyFilePath; - } on FileReadException { - print(e); - rethrow; + var filePath = linuxCMakeListsPath; + var contentLineByLine = await readFileAsLineByline( + filePath: filePath, + platform: platform, + ); + for (var i = 0; i < contentLineByLine.length; i++) { + if (contentLineByLine[i]?.contains('set(APPLICATION_ID') ?? false) { + var match = RegExp(r'set\(APPLICATION_ID "(.*?)"\)') + .firstMatch(contentLineByLine[i]!); + return match?.group(1)?.trim(); } } + + filePath = _legacyLinuxAppCppPath; + contentLineByLine = await readFileAsLineByline( + filePath: filePath, + platform: platform, + ); for (var i = 0; i < contentLineByLine.length; i++) { if (contentLineByLine[i]?.contains('kFlutterWindowTitle') ?? false) { var match = RegExp(r'kFlutterWindowTitle = "(.*?)"') @@ -118,7 +115,7 @@ class LinuxPlatformFileEditor extends AbstractPlatformFileEditor { return message; } - /// Sets the bundle ID in the Linux my_application.cc file. + /// Sets the bundle ID in the Linux CMakeLists.txt file. /// /// Parameters: /// - `bundleId`: The new bundle ID to be set for the application. @@ -126,32 +123,34 @@ class LinuxPlatformFileEditor extends AbstractPlatformFileEditor { /// Returns: Future, a success message indicating the change in bundle ID. @override Future setBundleId({required String bundleId}) async { - var filePath = linuxAppCppPath; - List? contentLineByLine; - try { + var filePath = linuxCMakeListsPath; + List? contentLineByLine = await readFileAsLineByline( + filePath: filePath, + platform: platform, + ); + var applicationIdSet = false; + for (var i = 0; i < contentLineByLine.length; i++) { + if (contentLineByLine[i].contains('set(APPLICATION_ID')) { + contentLineByLine[i] = 'set(APPLICATION_ID \"$bundleId\")'; + applicationIdSet = true; + break; + } + } + + if(!applicationIdSet) { + filePath = _legacyLinuxAppCppPath; contentLineByLine = await readFileAsLineByline( filePath: filePath, platform: platform, ); - } on FileReadException catch(e) { - try { - var legacyFilePath = _legacyLinuxAppCppPath; - contentLineByLine = await readFileAsLineByline( - filePath: legacyFilePath, - platform: platform, - ); - filePath = legacyFilePath; - } on FileReadException { - print(e); - rethrow; - } - } - for (var i = 0; i < contentLineByLine.length; i++) { - if (contentLineByLine[i].contains('kFlutterWindowTitle')) { - contentLineByLine[i] = - 'const char kFlutterWindowTitle[] = \"$bundleId\";'; + for (var i = 0; i < contentLineByLine.length; i++) { + if (contentLineByLine[i].contains('kFlutterWindowTitle')) { + contentLineByLine[i] = + 'const char kFlutterWindowTitle[] = \"$bundleId\";'; + } } } + final message = await super.setBundleId(bundleId: bundleId); await writeFile( filePath: filePath,