Skip to content

Commit

Permalink
feat: support for Flutter 3.27 template
Browse files Browse the repository at this point in the history
  • Loading branch information
OutdatedGuy committed Dec 19, 2024
1 parent 9f67bb3 commit cc28ca6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const _webDirPath = 'web';

// ? Linux
const _linuxDirPath = 'linux';
const _linuxRunnerDirPath = '$_linuxDirPath/runner';

// ? Windows
const _windowsDirPath = 'windows';
Expand Down Expand Up @@ -101,6 +102,8 @@ const _webManifestFilePath = '$_webDirPath/$_manifestJsonFileName';
// ? Linux
const _linuxCMakeListsFilePath = '$_linuxDirPath/$_cMakeListsFileName';
const _linuxMyApplicationFilePath = '$_linuxDirPath/$_myApplicationFileName';
const _linuxRunnerMyApplicationFilePath =
'$_linuxRunnerDirPath/$_myApplicationFileName';

// ? Windows
const _windowsCMakeListsFilePath = '$_windowsDirPath/$_cMakeListsFileName';
Expand Down
6 changes: 3 additions & 3 deletions lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ const _linuxCMakeListsNotFoundMessage = '''
''';

const _linuxMyApplicationNotFoundMessage = '''
╔══════════════════════════════════════════════╗
║ my_application.cc not found in `linux/`. ║
╚══════════════════════════════════════════════╝
╔══════════════════════════════════════════════════════════════════
║ my_application.cc not found in `linux/` and `linux/runner/`. ║
╚══════════════════════════════════════════════════════════════════
''';

const _invalidWindowsConfigMessage = '''
Expand Down
47 changes: 34 additions & 13 deletions lib/platforms/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,43 @@ void _setLinuxAppName(dynamic appName) {
if (appName is! String) throw _PackageRenameErrors.invalidAppName;

final myAppFile = File(_linuxMyApplicationFilePath);
if (!myAppFile.existsSync()) {
final runnerMyAppFile = File(_linuxRunnerMyApplicationFilePath);

final doesMyAppFileExist = myAppFile.existsSync();
final doesRunnerMyAppFileExist = runnerMyAppFile.existsSync();

if (!doesMyAppFileExist && !doesRunnerMyAppFileExist) {
throw _PackageRenameErrors.linuxMyApplicationNotFound;
}

final myAppString = myAppFile.readAsStringSync();
final newTitleMyAppString = myAppString
.replaceAll(
RegExp(r'gtk_header_bar_set_title\(header_bar, "(.*)"\);'),
'gtk_header_bar_set_title(header_bar, "$appName");',
)
.replaceAll(
RegExp(r'gtk_window_set_title\(window, "(.*)"\);'),
'gtk_window_set_title(window, "$appName");',
);

myAppFile.writeAsStringSync(newTitleMyAppString);
if (doesMyAppFileExist) {
final myAppString = myAppFile.readAsStringSync();
final newTitleMyAppString = myAppString
.replaceAll(
RegExp(r'gtk_header_bar_set_title\(header_bar, "(.*)"\);'),
'gtk_header_bar_set_title(header_bar, "$appName");',
)
.replaceAll(
RegExp(r'gtk_window_set_title\(window, "(.*)"\);'),
'gtk_window_set_title(window, "$appName");',
);

myAppFile.writeAsStringSync(newTitleMyAppString);
}
if (doesRunnerMyAppFileExist) {
final runnerMyAppString = runnerMyAppFile.readAsStringSync();
final newTitleRunnerMyAppString = runnerMyAppString
.replaceAll(
RegExp(r'gtk_header_bar_set_title\(header_bar, "(.*)"\);'),
'gtk_header_bar_set_title(header_bar, "$appName");',
)
.replaceAll(
RegExp(r'gtk_window_set_title\(window, "(.*)"\);'),
'gtk_window_set_title(window, "$appName");',
);

runnerMyAppFile.writeAsStringSync(newTitleRunnerMyAppString);
}

_logger.i('Linux app title set to: `$appName` (my_application.cc)');
} on _PackageRenameException catch (e) {
Expand Down

0 comments on commit cc28ca6

Please sign in to comment.