tomSecretsDataDirectory function
The data directory: TSM_DATA_DIR when set; on macOS
~/Library/Application Support/TomSecretsManager; on Windows
%LOCALAPPDATA%\TomSecretsManager (the runtime directory is its run\);
elsewhere $XDG_DATA_HOME/tom-secrets-manager, else
~/.local/share/tom-secrets-manager. environment and
operatingSystem default to this process's.
Throws StateError when the variables it is built from are not set.
Implementation
String tomSecretsDataDirectory({
Map<String, String>? environment,
String? operatingSystem,
}) {
final env = environment ?? Platform.environment;
final os = operatingSystem ?? Platform.operatingSystem;
final explicit = env['TSM_DATA_DIR'];
if (explicit != null && explicit.isNotEmpty) return explicit;
String need(String name) {
final value = env[name];
if (value == null || value.isEmpty) {
throw StateError('no data directory: $name is not set');
}
return value;
}
switch (os) {
case 'macos':
return '${need('HOME')}/Library/Application Support/TomSecretsManager';
case 'windows':
return '${need('LOCALAPPDATA')}\\TomSecretsManager';
default:
final xdg = env['XDG_DATA_HOME'];
return xdg != null && xdg.isNotEmpty
? '$xdg/tom-secrets-manager'
: '${need('HOME')}/.local/share/tom-secrets-manager';
}
}