/
ToggleSource.dart
59 lines (52 loc) · 1.4 KB
/
ToggleSource.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import 'dart:io';
import 'package:obs_command/commands/BaseCommand.dart';
class ToggleSource extends BaseCommand {
@override
String get description => 'Toggle a source in obs';
@override
String get name => 'ToggleSource';
ToggleSource() {
argParser.addOption('source',
abbr: 's',
mandatory: true,
help: 'The name of the source to change to',
valueHelp: 'Source Name');
argParser.addOption('scene',
abbr: 'i',
help:
'The name of the scene the source is on, will default to current scene if left blank',
valueHelp: 'Scene Name');
}
@override
Future<void> run() async {
await super.run();
bool visible;
var response;
var args = <String, dynamic>{
'item': argResults!['source'],
};
if (argResults?['scene'] != null) {
args['scene-name'] = argResults?['scene'];
}
try {
response = await obs.socket.command('GetSceneItemProperties', args);
} catch (e) {
print('Scene Error: $e');
exit(2);
}
if (response.rawResponse['visible'] == true) {
visible = false;
} else {
visible = true;
}
args['visible'] = visible;
try {
await obs.socket.command('SetSceneItemProperties', args);
print('Source visibility changed');
exit(0);
} catch (e) {
print('Failed to toggle source - ${e.toString()}');
exit(2);
}
}
}