Skip to content

Commit

Permalink
Refactor if chains into switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim committed Jun 12, 2024
1 parent 5fa894f commit 58610d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
18 changes: 8 additions & 10 deletions lib/forwarding_log_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ class ForwardingLogReader extends DeviceLogReader {
return message;
}
final String prefix = match.group(1)!;
TerminalColor color;
if (prefix == '[I]') {
color = TerminalColor.cyan;
} else if (prefix == '[W]') {
color = TerminalColor.yellow;
} else if (prefix == '[E]') {
color = TerminalColor.red;
} else if (prefix == '[F]') {
color = TerminalColor.magenta;
} else {
final TerminalColor? color = switch (prefix) {
'[I]' => TerminalColor.cyan,
'[W]' => TerminalColor.yellow,
'[E]' => TerminalColor.red,
'[F]' => TerminalColor.magenta,
_ => null,
};
if (color == null) {
return message;
}
return message.replaceFirst(prefix, globals.terminal.color(prefix, color));
Expand Down
19 changes: 10 additions & 9 deletions lib/tizen_device_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ class TizenDeviceDiscovery extends PollingDeviceDiscovery {
final String deviceId = splitLine[0];
final String deviceState = splitLine[1];

if (deviceState == 'unauthorized') {
messages.add(
'Device $deviceId is not authorized.\n'
'You might need to check your device for an authorization dialog.',
);
} else if (deviceState == 'offline') {
messages.add('Device $deviceId is offline.');
} else if (deviceState == 'unknown') {
messages.add('Device $deviceId is not ready.');
switch (deviceState) {
case 'unauthorized':
messages.add(
'Device $deviceId is not authorized.\n'
'You might need to check your device for an authorization dialog.',
);
case 'offline':
messages.add('Device $deviceId is offline.');
case 'unknown':
messages.add('Device $deviceId is not ready.');
}
}
return messages;
Expand Down
40 changes: 20 additions & 20 deletions lib/tizen_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,28 +264,28 @@ class TizenSdk {
throwToolExit('Not supported API version: $apiVersion');
}

if (profile == 'common') {
if (versionToDouble(apiVersion) >= 8.0) {
// Note: Starting with Tizen 8.0, the unified "tizen" profile is used.
profile = 'tizen';
} else {
profile = arch == 'x86' ? 'mobile' : 'iot-headed';
}
} else if (profile == 'tv') {
// Note: The tv-samsung rootstrap is not publicly available.
profile = 'tv-samsung';
} else if (profile == 'mobile') {
if (versionToDouble(apiVersion) >= 8.0) {
profile = 'tizen';
}
switch (profile) {
case 'common':
if (versionToDouble(apiVersion) >= 8.0) {
// Note: Starting with Tizen 8.0, the unified "tizen" profile is used.
profile = 'tizen';
} else {
profile = arch == 'x86' ? 'mobile' : 'iot-headed';
}
case 'tv':
// Note: The tv-samsung rootstrap is not publicly available.
profile = 'tv-samsung';
case 'mobile':
if (versionToDouble(apiVersion) >= 8.0) {
profile = 'tizen';
}
}

String type = 'device';
if (arch == 'x86') {
type = 'emulator';
} else if (arch == 'arm64') {
type = 'device64';
}
final String type = switch (arch) {
'x86' => 'emulator',
'arm64' => 'device64',
_ => 'device',
};

Rootstrap findRootstrap(String profile, String apiVersion, String type) {
final String id = '$profile-$apiVersion-$type.core';
Expand Down

0 comments on commit 58610d3

Please sign in to comment.