-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
151 lines (137 loc) · 4.98 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
148
149
150
151
// Modules to control application life and create native browser window
const { globalShortcut, app, BrowserWindow } = require('electron');
const { ipcMain } = require('electron')
const fileHelper = require('./FileHelper/fileElectronHelper');
const metricHelper = require('./metrics');
const path = require('path')
const metricsMap = {
mood: (dartFiles) => metricHelper.calculateMOODMetrics(dartFiles),
ck: (dartFiles) => metricHelper.calculateCKMetrics(dartFiles),
trd: (dartFiles) => metricHelper.calculateTraditionalMetrics(dartFiles),
all: function(dartFiles) {
console.log(this);
return {...this.mood(dartFiles), ...this.ck(dartFiles), ...this.trd(dartFiles)}
}
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
class DesktopApp {
constructor() {
this.app = app;
this.ipcMain = ipcMain;
this.setUpApp();
this.setUpAllListener();
}
createWindow () {
win = new BrowserWindow({
width: 1600,
height: 900,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, 'preload.js')
},
})
globalShortcut.register('f5', function() {
console.log('f5 is pressed')
win.reload()
})
globalShortcut.register('CommandOrControl+R', function() {
console.log('CommandOrControl+R is pressed')
win.reload()
})
win.loadFile('index.html')
win.webContents.openDevTools()
win.on('closed', () => {
win = null
})
}
setUpApp(){
this.app.on('ready', this.createWindow)
this.app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
this.app.quit()
}
})
this.app.on('activate', () => {
if (win === null) {
this.createWindow()
}
})
}
checkFlutterProject(path){
let splitedPath = path.split("\\"), isFlutterProject = fileHelper.checkFlutterPrj(path);
isFlutterProject.projectName = splitedPath[splitedPath.length-1];
return isFlutterProject;
}
setUpFolderCheckListener(){
this.ipcMain.on('folder-check', (event, options) => {
if (options.multipleProject) {
let flutterProjects = [], folderPaths = fileHelper.getDirectories(options.path);
//console.log(folderPaths);
for (let index = 0; index < folderPaths.length; index++) {
const path = folderPaths[index];
//console.log("Path: " + path);
let isFlutterProject = this.checkFlutterProject(path)
if(isFlutterProject.isFlutterProject){
flutterProjects.push(isFlutterProject);
}
}
event.sender.send('checked-folders', {flutterProjects: flutterProjects});
}
else{
let isFlutterProject = this.checkFlutterProject(options.path);
event.sender.send('checked-folder', isFlutterProject);
}
})
}
setUpSmellListener(){
this.ipcMain.on('smell', (event, data) => {
let res;
if(data.hasOneProject){
//console.log("\n\n\n\n\n\nSingle\n\n\n");
res = metricHelper.identifyGodClass(data.dartFiles);
event.sender.send('smell-detected', [{finalResult: res, projectName:data.projectName}]);
}
else{
res = [];
for (let index = 0; index < data.projects.length; index++) {
console.log("Project " + index + ":");
console.log(data.projects[index]);
const resOneProject = metricHelper.identifyGodClass(data.projects[index].dartFiles);
res.push({finalResult: resOneProject, projectName:data.projects[index].projectName})
}
//res = metricsMap[data.metricType](data.dartFilePaths);
event.sender.send('smell-detected', res);
}
})
}
setUpMetricListener(){
ipcMain.on('metric', (event, data) => {
let res;
if(data.hasOneProject){
//console.log("\n\n\n\n\n\nSingle\n\n\n");
res = metricsMap[data.metricType](data.dartFiles);
event.sender.send('project-metrics', [{...res, projectName:data.projectName}]);
}
else{
//console.log(data.projects);
res = [];
for (let index = 0; index < data.projects.length; index++) {
console.log("Project " + index + ":");
console.log(data.projects[index]);
const resOneProject = metricsMap[data.metricType](data.projects[index].dartFiles);
res.push({...resOneProject, projectName:data.projects[index].projectName})
}
//res = metricsMap[data.metricType](data.dartFilePaths);
event.sender.send('project-metrics', res);
}
})
}
setUpAllListener() {
this.setUpMetricListener();
this.setUpSmellListener();
this.setUpFolderCheckListener();
}
}
module.exports = DesktopApp;