Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding font installation #269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions lib/msix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ class Msix {
await _initConfig();
await _buildMsixFiles();
String msixStyledPath = File(_msixOutputPath).parent.path.blue.emphasized;
_logger
.write('${'unpackaged msix files created in: '.green}$msixStyledPath');
_logger.write('${'unpackaged msix files created in: '.green}$msixStyledPath');
}

/// Execute with the `msix:pack` command
Future<void> pack() async {
await _initConfig();

/// check if the appx manifest is exist
String appxManifestPath =
p.join(_config.buildFilesFolder, 'AppxManifest.xml');
String appxManifestPath = p.join(_config.buildFilesFolder, 'AppxManifest.xml');
if (!(await File(appxManifestPath).exists())) {
String error = 'run "msix:build" first';
_logger.stderr(error.red);
Expand Down Expand Up @@ -74,24 +72,19 @@ class Msix {
await appInstaller.generateAppInstaller();
await appInstaller.generateAppInstallerWebSite();
loggerProgress.finish(showTiming: true);
_logger.write(
'${'appinstaller created: '.green}${_config.appInstallerPath.blue.emphasized}');
_logger.write('${'appinstaller created: '.green}${_config.appInstallerPath.blue.emphasized}');
}

/// Register [Logger] and [Configuration] as singleton services
_setupSingletonServices(List<String> args) {
GetIt.I.registerSingleton<Logger>(args.contains('-v')
? Logger.verbose()
: Logger.standard(ansi: Ansi(true)));
GetIt.I.registerSingleton<Logger>(args.contains('-v') ? Logger.verbose() : Logger.standard(ansi: Ansi(true)));

GetIt.I.registerSingleton<Configuration>(Configuration(args));
}

String get _msixOutputPath =>
_config.msixPath.contains(p.join('build', 'windows'))
? _config.msixPath
.substring(_config.msixPath.indexOf(p.join('build', 'windows')))
: _config.msixPath;
String get _msixOutputPath => _config.msixPath.contains(p.join('build', 'windows'))
? _config.msixPath.substring(_config.msixPath.indexOf(p.join('build', 'windows')))
: _config.msixPath;

Future<void> _initConfig() async {
await _config.getConfigValues();
Expand All @@ -114,10 +107,8 @@ class Msix {
await assets.createIcons();
await assets.copyVCLibsFiles();

if (_config.contextMenuConfiguration?.comSurrogateServers.isNotEmpty ==
true) {
for (var element
in _config.contextMenuConfiguration!.comSurrogateServers) {
if (_config.contextMenuConfiguration?.comSurrogateServers.isNotEmpty == true) {
for (var element in _config.contextMenuConfiguration!.comSurrogateServers) {
await assets.copyContextMenuDll(element.dllPath);
}
}
Expand All @@ -140,9 +131,7 @@ class Msix {
if (_config.signMsix && !_config.store) {
SignTool signTool = SignTool();

if (_config.installCert &&
(_config.signToolOptions == null ||
_config.signToolOptions!.isEmpty)) {
if (_config.installCert && (_config.signToolOptions == null || _config.signToolOptions!.isEmpty)) {
await signTool.installCertificate();
}

Expand All @@ -153,8 +142,7 @@ class Msix {
}

/// print the location of the created msix file
void _printMsixOutputLocation() => _logger
.write('${'msix created: '.green}${_msixOutputPath.blue.emphasized}');
void _printMsixOutputLocation() => _logger.write('${'msix created:: '.green}${_msixOutputPath.blue.emphasized}');

static void registerWith() {}
}
54 changes: 24 additions & 30 deletions lib/src/appx_manifest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class AppxManifest {
//clear empty rows
manifestContent = manifestContent.replaceAll(' \n', '');

String appxManifestPath =
p.join(_config.buildFilesFolder, 'AppxManifest.xml');
String appxManifestPath = p.join(_config.buildFilesFolder, 'AppxManifest.xml');
await File(appxManifestPath).writeAsString(manifestContent);
}

Expand All @@ -89,8 +88,7 @@ class AppxManifest {
_config.protocolActivation.isNotEmpty ||
!_config.fileExtension.isNull ||
!_config.toastActivatorCLSID.isNull ||
(_config.appUriHandlerHosts != null &&
_config.appUriHandlerHosts!.isNotEmpty) ||
(_config.appUriHandlerHosts != null && _config.appUriHandlerHosts!.isNotEmpty) ||
_config.enableAtStartup ||
_config.startupTask != null ||
_config.contextMenuConfiguration != null) {
Expand All @@ -103,6 +101,7 @@ class AppxManifest {
${_config.appUriHandlerHosts != null && _config.appUriHandlerHosts!.isNotEmpty ? _getAppUriHandlerHostExtension() : ''}
${_config.contextMenuConfiguration != null ? _getContextMenuExtension() : ''}
${_config.contextMenuConfiguration?.comSurrogateServers.isNotEmpty == true || _config.toastActivatorCLSID != null ? _getComServers() : ''}
${_config.msixFontsFiles?.isNotEmpty ?? false ? _getFonts() : ''}
</Extensions>''';
} else {
return '';
Expand Down Expand Up @@ -184,12 +183,9 @@ class AppxManifest {
}

String _getStartupTaskExtension() {
final taskId =
_config.startupTask?.taskId ?? _config.appName?.replaceAll('_', '');
final taskId = _config.startupTask?.taskId ?? _config.appName?.replaceAll('_', '');
final enabled = _config.startupTask?.enabled ?? true;
final parameters = _config.startupTask?.parameters != null
? 'uap10:Parameters="${_config.startupTask?.parameters}"'
: '';
final parameters = _config.startupTask?.parameters != null ? 'uap10:Parameters="${_config.startupTask?.parameters}"' : '';
return '''<desktop:Extension Category="windows.startupTask" Executable="${_config.executableFileName.toHtmlEscape()}" EntryPoint="Windows.FullTrustApplication" $parameters>
<desktop:StartupTask TaskId="$taskId" Enabled="$enabled" DisplayName="${_config.displayName.toHtmlEscape()}"/>
</desktop:Extension>''';
Expand All @@ -205,6 +201,16 @@ class AppxManifest {
</uap3:Extension>''';
}

String _getFonts() {
return ''' <uap4:Extension Category="windows.sharedFonts">
<uap4:SharedFonts>
${_config.msixFontsFiles!.map((f) {
return '<uap4:Font File="data\\flutter_assets\\fonts\\$f" />';
}).toList().join('\n ')}
</uap4:SharedFonts>
</uap4:Extension>''';
}

String _normalizeCapability(String capability) {
capability = capability.trim();
String firstLetter = capability.substring(0, 1).toLowerCase();
Expand All @@ -219,43 +225,31 @@ class AppxManifest {
String capabilitiesString = '';
const newline = '\n ';

capabilities
.where((capability) => !capability.isNullOrEmpty)
.forEach((capability) {
capabilities.where((capability) => !capability.isNullOrEmpty).forEach((capability) {
capability = _normalizeCapability(capability);

if (appCapabilities['generalUseCapabilities']!.contains(capability)) {
capabilitiesString += '<Capability Name="$capability" />$newline';
} else if (appCapabilities['generalUseCapabilitiesUap']!
.contains(capability)) {
} else if (appCapabilities['generalUseCapabilitiesUap']!.contains(capability)) {
capabilitiesString += '<uap:Capability Name="$capability" />$newline';
} else if (appCapabilities['generalUseCapabilitiesIot']!
.contains(capability)) {
} else if (appCapabilities['generalUseCapabilitiesIot']!.contains(capability)) {
capabilitiesString += '<iot:Capability Name="$capability" />$newline';
} else if (appCapabilities['generalUseCapabilitiesMobile']!
.contains(capability)) {
capabilitiesString +=
'<mobile:Capability Name="$capability" />$newline';
} else if (appCapabilities['generalUseCapabilitiesMobile']!.contains(capability)) {
capabilitiesString += '<mobile:Capability Name="$capability" />$newline';
}
});

capabilities
.where((capability) => !capability.isNullOrEmpty)
.forEach((capability) {
capabilities.where((capability) => !capability.isNullOrEmpty).forEach((capability) {
capability = _normalizeCapability(capability);

if (appCapabilities['restrictedCapabilitiesUap']!.contains(capability)) {
capabilitiesString += '<uap:Capability Name="$capability" />$newline';
} else if (appCapabilities['restrictedCapabilitiesRescap']!
.contains(capability)) {
capabilitiesString +=
'<rescap:Capability Name="$capability" />$newline';
} else if (appCapabilities['restrictedCapabilitiesRescap']!.contains(capability)) {
capabilitiesString += '<rescap:Capability Name="$capability" />$newline';
}
});

capabilities
.where((capability) => !capability.isNullOrEmpty)
.forEach((capability) {
capabilities.where((capability) => !capability.isNullOrEmpty).forEach((capability) {
capability = _normalizeCapability(capability);

if (appCapabilities['deviceCapabilities']!.contains(capability)) {
Expand Down
Loading