-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeepcode.js
More file actions
202 lines (159 loc) · 5.3 KB
/
Copy pathdeepcode.js
File metadata and controls
202 lines (159 loc) · 5.3 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
'use babel';
import { CompositeDisposable, Disposable } from 'atom';
import { config } from './config';
import { Store } from './modules/Store';
import { PluginManager } from './modules/PluginManager';
import { CommonUtils } from './modules/CommonUtils';
import { Logger } from './modules/Logger';
import { HttpModule } from './modules/HttpModule';
import { DB } from './modules/Database';
import { PLUGIN } from './constants/common';
import { COMMANDS } from './constants/commands';
import { CUSTOM_EVENTS, STORE_KEYS } from './constants/store';
import { ProblemsPanel } from './views/ProblemsPanel';
import { StatusBarButton } from './views/StatusBarButton';
import { EditorUtils } from './modules/EditorUtils';
export default {
subscriptions: null,
statusBarButton: null,
lastStateLog: 0,
config,
async initialize() {
Logger.init();
const dbConnected = await DB.init();
Logger.log(`DB connected: ${dbConnected}`);
const sharedState = await DB.restoreState(true);
const projectState = await DB.restoreState();
Store.init(sharedState, projectState);
Logger.log('Activating plugin');
Logger.log('Shared State: ', sharedState);
Logger.log('Project State: ', projectState);
// clone some configs into Store and init HTTP module
CommonUtils.clonePluginConfig();
const serviceURL = Store.get(STORE_KEYS.serviceURL);
const debugLog = atom.config.get(`${PLUGIN.name}.debugLog`);
HttpModule.init({
baseURL: serviceURL,
useDebug: debugLog,
});
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.initSubscriptions();
// Check login and start the rest operations in queue
const isLoggedIn = Store.flags.isLoggedIn();
if (!isLoggedIn) {
PluginManager.openLoginDialog();
return;
}
PluginManager.checkLogin();
},
initSubscriptions() {
this.subscriptions = new CompositeDisposable(
// Add an opener for our view
atom.workspace.addOpener((uri) => {
if (uri === PLUGIN.problemsPanelURI) {
return new ProblemsPanel();
}
return null;
}),
// Register command that toggles this view
atom.commands.add('atom-workspace', {
[COMMANDS.openPanel]: () => PluginManager.openProblemsPanel(),
[COMMANDS.resetPlugin]: () => PluginManager.resetPlugin(),
}),
// Destroy any ProblemsPanel when the package is deactivated
new Disposable(() => {
atom.workspace.getPaneItems().forEach((item) => {
if (item instanceof ProblemsPanel) {
item.destroy();
}
});
}),
// observe config changes: 'debugLog'
atom.config.observe(`${PLUGIN.name}.debugLog`, (newValue) => {
Logger.init();
const serviceURL = Store.get(STORE_KEYS.serviceURL);
HttpModule.init({
baseURL: serviceURL,
useDebug: newValue,
});
}),
// observe config changes: 'sessionToken'
atom.config.observe(`${PLUGIN.name}.sessionToken`, (sessionToken) => {
Store.set(STORE_KEYS.sessionToken, sessionToken);
}),
// observe config changes: 'serviceURL'
atom.config.observe(`${PLUGIN.name}.serviceURL`, (newServiceURL) => {
const serviceURL = Store.get(STORE_KEYS.serviceURL);
if (serviceURL === newServiceURL) {
return;
}
Store.emit(CUSTOM_EVENTS.didLogout);
const debugLog = atom.config.get(`${PLUGIN.name}.debugLog`);
HttpModule.init({
baseURL: newServiceURL,
useDebug: debugLog,
});
}),
// observe changing project paths
atom.project.onDidChangePaths(projectPaths => {
PluginManager.didChangePaths(projectPaths);
}),
);
},
consumeStatusBar(statusBar) {
this.statusBarButton = new StatusBarButton();
this.statusBarButton.init(statusBar);
},
serialize() {
const sharedState = Store.getSharedState();
CommonUtils.saveSharedStore();
CommonUtils.saveProjectStore();
const now = new Date();
if (now - this.lastStateLog > 1000 * 60) {
const projectState = Store.getProjectState();
Logger.log('Serialize. Shared State:', sharedState);
Logger.log('Serialize. Project State:', projectState);
this.lastStateLog = now;
}
return {
...sharedState,
};
},
deactivate() {
if (this.subscriptions) {
this.subscriptions.dispose();
}
if (this.statusBarButton) {
this.statusBarButton.destroy();
this.statusBarButton = null;
}
EditorUtils.destroy();
PluginManager.destroy();
Logger.destroy();
},
// Testing API ------------------------------------------------------------------------------------------------------
getPluginState() {
return Store.getState();
},
setPluginState(state = {}) {
Store.setMany(state);
},
initHTTP(serviceURL) {
HttpModule.init({
baseURL: serviceURL,
useDebug: true,
});
},
checkFilters(testCallback) {
PluginManager.checkFilters(testCallback);
},
async createBundle() {
return PluginManager.createBundle();
},
async createRemoteBundle(bundleId) {
return PluginManager.createRemoteBundle(bundleId);
},
async checkAnalysis(analysisResults) {
return PluginManager.checkAnalysis(analysisResults);
},
};