-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
182 lines (163 loc) · 6.3 KB
/
options.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const optionsExports = {};
var utils = require('./utils');
const electron = require('electron');
const app = electron.remote.app;
const path = require('path');
let defaultOptions = {
screenshot: {
captureFullWindow: false,
directory: path.join(app.getPath('pictures'), 'electron-vlog', 'screenshots'),
fileNamePrefix: (() => {console.log('Title computed!'); return document.title;})() //TODO: Test and remove log
},
timelapse: {
captureFullWindow: false,
timeoutMillis: (20 * 60 * 1000),
directory: path.join(app.getPath('pictures'), 'electron-vlog', 'timelapse'),
fileNamePrefix: (() => {return document.title;})(),
screenshotIntervalMillis: (2 * 1000)
},
recording: {
directory: path.join(app.getPath('pictures'), 'electron-vlog', 'recording'),
fileNamePrefix: (() => {return document.title;})(),
timeoutMillis: (2 * 60 * 1000)
}
};
let options = defaultOptions;
/**
* Options format:
* {
* logLevel: 'DEBUG'|'INFO'|'ERROR'|'OFF',
* screenshot: {
* captureFullWindow: boolean,
* directory: String,
* fileNamePrefix: String
* },
* timelapse: {
* captureFullWindow: boolean,
* timeoutMillis: int,
* directory: String,
* fileNamePrefix: String,
* timelapseInterval: int
* },
* recording: {
* directory: String,
* fileNamePrefix: String,
* timeoutMillis: int
* }
* }
*/
optionsExports.setMediaOptions = function setMediaOptions(inputOptions) {
if (inputOptions == null) {
utils.error('options is undefined; needs to be of type Object');
}
if(isObject(inputOptions, 'options')) {
options = defaultOptions; //Reset whatever options were stored previously
setLogLevel(inputOptions.logLevel);
setScreenshotOptions(inputOptions);
setTimelapseOptions(inputOptions);
setRecordingOptions(inputOptions);
}
};
optionsExports.screenshot = options.screenshot;
optionsExports.timelapse = options.timelapse;
optionsExports.recording = options.recording;
/**
* @param {DEBUG, INFO, ERROR, OFF} inputLogLevel
*/
function setLogLevel(inputLogLevel) {
if (inputLogLevel != null) {
utils.setLogLevel(inputLogLevel);
}
}
/**
* @return {true|false}
*/
function isObject(inputOptions, displayName) {
if(Object.prototype.toString.call(inputOptions) !== '[object Object]') {
utils.warn(displayName + ' is ' + typeof (inputOptions) + ', required: Object');
return false;
}
return true;
}
let keys = {captureFullWindow: 'captureFullWindow', directory: 'directory',
fileNamePrefix: 'fileNamePrefix', timelapse: 'timelapse', screenshot: 'screenshot',
recording: 'recording', timeoutSeconds: 'timeoutSeconds', timeoutMinutes: 'timeoutMinutes',
timeoutMillis: 'timeoutMillis', screenshotIntervalSeconds: 'screenshotIntervalSeconds',
screenshotIntervalMillis: 'screenshotIntervalMillis'};
function setCaptureFullWindow(value, optionsObject) {
if (value != null) {
if (typeof value == 'boolean') {
optionsObject[keys.captureFullWindow] = value;
} else {
utils.warn(keys.captureFullWindow + ' is ' + typeof value + ', required: Boolean');
}
}
}
function setDirectory(value, optionsObject) {
if (value != null) {
if (typeof value == 'string') {
optionsObject[keys.directory] = value;
//Create directory
} else {
utils.warn(keys.directory + ' is ' + typeof value + ', required: String');
}
}
}
function setFileNamePrefix(value, optionsObject) {
if (value != null) {
if (typeof value == 'string') {
optionsObject[keys.fileNamePrefix] = value;
} else {
utils.warn(keys.fileNamePrefix + ' is ' + typeof value + ', required: String');
}
}
}
//If seconds is given, take seconds; if not present, take minutes
function setTimeout(timeoutSeconds, timeoutMinutes, optionsObject) {
if (timeoutSeconds != null) {
if (typeof timeoutSeconds == 'number') {
optionsObject[keys.timeoutMillis] = timeoutSeconds * 1000;
} else {
utils.warn(keys.timeoutSeconds + ' is ' + typeof valueSeconds + ', required: Number');
}
} else if (timeoutMinutes != null) {
if (typeof valueMinutes == 'number') {
optionsObject[keys.timeoutMillis] = timeoutMinutes * 60 * 1000;
} else {
utils.warn(keys.timeoutMinutes + ' is ' + typeof valueMinutes + ', required: Number');
}
}
}
function setTimelapseInterval(value, optionsObject) {
if (value != null) {
if (typeof valueSeconds == 'number') {
optionsObject[keys.screenshotIntervalMillis] = value * 1000;
} else {
utils.warn(keys.screenshotIntervalSeconds + ' is ' + typeof valueSeconds + ', required: Number');
}
}
}
function setScreenshotOptions(inputOptions) {
if (isObject(inputOptions[keys.screenshot], 'options.screenshot')) {
setCaptureFullWindow(inputOptions[keys.captureFullWindow], options[keys.screenshot]);
setDirectory(inputOptions[keys.directory], options[keys.screenshot]);
setFileNamePrefix(inputOptions[keys.fileNamePrefix], options[keys.screenshot]);
}
}
function setTimelapseOptions(inputOptions) {
if (isObject(inputOptions[keys.timelapse], 'options.timelapse')) {
setCaptureFullWindow(inputOptions[keys.captureFullWindow], options[keys.timelapse]);
setDirectory(inputOptions[keys.directory], options[keys.timelapse]);
setFileNamePrefix(inputOptions[keys.fileNamePrefix], options[keys.timelapse]);
setTimeout(inputOptions[keys.timeoutSeconds], inputOptions[keys.timeoutMinutes], options[keys.timelapse]);
setTimelapseInterval(inputOptions[keys.screenshotIntervalSeconds], options[keys.timelapse]);
}
}
function setRecordingOptions(inputOptions) {
if (isObject(inputOptions[keys.recording], 'options.recording')) {
setDirectory(inputOptions[keys.directory], options[keys.recording]);
setFileNamePrefix(inputOptions[keys.fileNamePrefix], options[keys.recording]);
setTimeout(inputOptions[keys.timeoutSeconds], inputOptions[keys.timeoutMinutes], options[keys.recording]);
}
}
module.exports = optionsExports;