-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
147 lines (123 loc) · 3.12 KB
/
main.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
const electron = require('electron');
const {ipcMain} = require('electron');
const nativeImage = require('electron').nativeImage;
const path = require('path');
// External packages
const shell = require('shelljs');
const diff = require('./app/diff.js');
// Configration module
const configration = require('./app/js/configration.js');
const {app} = electron;
const {BrowserWindow} = electron;
let win;
function createWindow() {
fillConfigrations();
let windowsOptions = {
width: 800,
minWidth: 800,
height: 600,
minHeight: 600,
center: true,
title: 'Gitty | Unofficial Github Client'
}
win = new BrowserWindow(windowsOptions);
win.loadURL(`file://${__dirname}/index.html`);
win.webContents.openDevTools();
win.maximize();
win.on('closed', () => {
win = null;
});
}
function fillConfigrations() {
// Nothing for now;
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform != 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (win === null){
createWindow();
}
});
/*
index.html Helpers
*/
ipcMain.on('get-local-repos', (event) => {
let localRepos = configration.readSettings('localRepos');
if (localRepos){
event.sender.send('local-repos', localRepos);
}
})
ipcMain.on('refresh-local-repos', (event) => {
// command for finding all git repos as base dir ~.
let gitCommand = 'find ~ -type d -name .git | xargs -n 1 dirname';
// List of local repos
let localRepos = []
shell.exec(gitCommand, (err, stdout, stderr) => {
if (err) {
console.log('error in exec [%s]', error);
} else {
localRepos = stdout.split('\n');
configration.saveSettings('localRepos', localRepos);
event.sender.send('local-repos', localRepos);
}
});
});
/*
Getting list of all commits in a repo
*/
ipcMain.on('get-commits', (event, repoPath) => {
shell.cd(repoPath);
/*
Getting all git commits
Options for format -->
%H --> commit hash
%an --> author name
%ar --> author date, humanize form
%s --> message
*/
let gitCommand = 'git log --pretty=format:"%H | %an | %ar | %s"';
shell.exec(gitCommand, (err, stdout, stderr) => {
if (err){
console.log('error in exec [%s]', error);
} else {
allCommits = stdout.split('\n');
event.sender.send('commits', allCommits);
}
});
});
/*
Getting list of all branches in a repo
*/
ipcMain.on('get-branches', (event, repoPath) => {
shell.cd(repoPath);
let gitCommand = 'git branch';
shell.exec(gitCommand, (err, stdout, stderr) => {
if (err){
console.log('error in exec [%s]', error);
} else {
branches = stdout.split('\n');
event.sender.send('branches', branches);
}
});
});
/*
Getting info about a commit
*/
ipcMain.on('get-commit-info', (event, commitHash) => {
let gitCommand = 'git show ' + commitHash;
console.log(gitCommand);
shell.exec(gitCommand, (err, stdout, stderr) => {
if (err){
console.log(err);
} else {
diff(stdout, (err, output) => {
if (err) console.log(err);
event.sender.send('commit-info', output);
});
}
});
});