-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
83 lines (77 loc) · 2.28 KB
/
main.ts
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
import { app, dialog } from 'electron';
import * as path from 'path';
import * as fs from 'fs';
import { GitClient } from './git/GitClient';
import { AskPassApplication } from './askPassApplication';
import { take } from 'rxjs/operators';
import { MainApplication } from './mainApplication';
import * as mkdirp from 'mkdirp';
const userDataPath = app.getPath('userData');
if (!fs.existsSync(userDataPath)) {
mkdirp(userDataPath, (err) => {
if (err) {
dialog.showErrorBox('An error occurred', err.toString());
}
});
}
const output = fs.createWriteStream(path.join(userDataPath, 'stdout.log'), {
flags: 'a',
});
const errorOutput = fs.createWriteStream(
path.join(userDataPath, 'stderr.log'),
{ flags: 'a' },
);
const logger = new console.Console(output, errorOutput);
GitClient.logger = logger;
process.on('uncaughtException', (error) => {
logger.error(JSON.stringify(error));
console.error(error);
dialog
.showMessageBox(null, {
type: 'error',
message: `An error occurred. Please see the log for more details. Message: ${error.message}`,
buttons: ['Ignore', 'Quit'],
})
.then((arg) => {
if (arg.response === 1) {
process.exit(-1);
}
});
});
function getAskPassInstance(host: string) {
const askPassApplication = new AskPassApplication(GitClient.logger, host);
askPassApplication.start();
return askPassApplication.onLogin.pipe(take(1));
}
// no error dialogs shown to users
try {
if (process.argv.slice(1).some((x) => !!x.match(/Password|Username/))) {
let text = process.argv[1];
let needsUsername = text.match(/^Username\s+for\s+'(\S+?)'/m);
let needsPassword = text.match(/^Password\s+for\s+'(\S+?)'/m);
if (needsUsername) {
getAskPassInstance(needsUsername[1]).subscribe((creds) => {
if (creds != null) {
process.stdout.write(creds.username);
} else {
process.exit(-1);
}
});
} else if (needsPassword) {
getAskPassInstance(needsPassword[1]).subscribe((creds) => {
if (creds != null) {
process.stdout.write(creds.password);
} else {
process.exit(-1);
}
});
}
} else {
new MainApplication(logger).start();
}
} catch (e) {
// Catch Error
// throw e;
logger.error(e);
console.error(e);
}