-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
258 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:image/image.dart'; | ||
import 'package:katana_cli/katana_cli.dart'; | ||
|
||
final _sizeList = { | ||
"document/store/icon.png": 512, | ||
"android/app/src/main/res/mipmap-hdpi/ic_launcher.png": 72, | ||
"android/app/src/main/res/mipmap-mdpi/ic_launcher.png": 48, | ||
"android/app/src/main/res/mipmap-xhdpi/ic_launcher.png": 96, | ||
"android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png": 144, | ||
"android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png": 192, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png": 20, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png": 40, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png": 60, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png": 29, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png": 58, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png": 87, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png": 40, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png": 80, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png": 120, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png": 120, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png": 180, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png": 76, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png": 152, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png": | ||
167, | ||
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png": | ||
1024, | ||
}; | ||
|
||
/// Automatically creates icon files for applications. | ||
/// | ||
/// アプリ用のアイコンファイルを自動作成します。 | ||
class AppIconCliAction extends CliCommand with CliActionMixin { | ||
/// Automatically creates icon files for applications. | ||
/// | ||
/// アプリ用のアイコンファイルを自動作成します。 | ||
const AppIconCliAction(); | ||
|
||
@override | ||
String get description => | ||
"Automatically creates icon files for applications. アプリ用のアイコンファイルを自動作成します。"; | ||
|
||
@override | ||
bool checkEnabled(ExecContext context) { | ||
final value = context.yaml.getAsMap("app").getAsMap("icon"); | ||
final enabled = value.get("enable", false); | ||
final path = value.get("path", ""); | ||
if (!enabled || path.isEmpty) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@override | ||
Future<void> exec(ExecContext context) async { | ||
final app = context.yaml.getAsMap("app"); | ||
if (app.isEmpty) { | ||
print("The item [app] is missing. Please add an item."); | ||
return; | ||
} | ||
final icon = app.getAsMap("icon"); | ||
if (icon.isEmpty) { | ||
print("The item [app]->[icon] is missing. Please add an item."); | ||
return; | ||
} | ||
final path = icon.get("path", ""); | ||
if (path.isEmpty) { | ||
print( | ||
"The item [app]->[icon]->[path] is missing. Please provide the path to the original icon.", | ||
); | ||
return; | ||
} | ||
label("Load a file from $path"); | ||
final iconFile = File(path); | ||
if (!iconFile.existsSync()) { | ||
print("Icon file not found in $path."); | ||
return; | ||
} | ||
final iconImage = decodeImage(iconFile.readAsBytesSync())!; | ||
if (iconImage.width != 1024 || iconImage.height != 1024) { | ||
print("Icon files should be 1024 x 1024."); | ||
return; | ||
} | ||
for (final tmp in _sizeList.entries) { | ||
label("Resize & Save to ${tmp.key}"); | ||
final dir = Directory(tmp.key.parentPath()); | ||
if (!dir.existsSync()) { | ||
await dir.create(recursive: true); | ||
} | ||
final file = File(tmp.key); | ||
if (file.existsSync()) { | ||
await file.delete(); | ||
} | ||
final resized = copyResize( | ||
iconImage, | ||
height: tmp.value, | ||
width: tmp.value, | ||
interpolation: Interpolation.average, | ||
); | ||
await file.writeAsBytes(encodePng(resized, level: 9)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.