Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const PROJECT_STORE_KEYS = [
];

export const CUSTOM_EVENTS = {
didLogin: 'didLogin',
didLogout: 'didLogout',
didScanSingleFolder: 'didScanSingleFolder',
};
42 changes: 24 additions & 18 deletions lib/deepcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export default {
HttpModule.init(serviceURL);

// 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) => {
Expand Down Expand Up @@ -85,23 +98,12 @@ export default {
atom.config.observe(`${PLUGIN.name}.serviceURL`, (newServiceURL) => {
HttpModule.init(newServiceURL);
}),
);

// Main work-flow
const isConfigured = Store.flags.isConfigured();
if (!isConfigured) {
PluginManager.openConfigureDialog();
return;
}

const isLoggedIn = Store.flags.isLoggedIn();
if (!isLoggedIn) {
PluginManager.openLoginDialog();
return;
}

// Check login and start the rest operations in queue
PluginManager.checkLogin();
// observe changing project paths
atom.project.onDidChangePaths(projectPaths => {
PluginManager.didChangePaths(projectPaths);
}),
);
},

consumeStatusBar(statusBar) {
Expand Down Expand Up @@ -156,7 +158,11 @@ export default {
HttpModule.init(serviceURL);
},

checkFilters() {
PluginManager.checkFilters();
checkFilters(testCallback) {
PluginManager.checkFilters(testCallback);
},

scanProject() {

},
};
7 changes: 5 additions & 2 deletions lib/modules/AuthModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import open from 'open';
import { Store } from './Store';
import { HttpModule } from './HttpModule';
import { Logger } from './Logger';
import { STORE_KEYS } from '../constants/store';
import { CUSTOM_EVENTS, STORE_KEYS } from '../constants/store';
import { PLUGIN } from '../constants/common';

class AuthModule {
Expand Down Expand Up @@ -48,8 +48,11 @@ class AuthModule {
[STORE_KEYS.loginInProcess]: false,
[STORE_KEYS.accountType]: type || 'free',
});
Logger.log('Login successful!');
atom.config.set(`${PLUGIN.name}.sessionToken`, sessionToken);
Store.emit(CUSTOM_EVENTS.didLogin);

Logger.log('Login successful!');

return;
}

Expand Down
9 changes: 9 additions & 0 deletions lib/modules/BundleModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ class BundleModule {
return Promise.resolve();
}

async stopBundleLoop() {
if (this.loopTimeout) {
clearTimeout(this.loopTimeout);
}

this.loopTimeout = null;
return Promise.resolve();
}

async createBundle() {
const sessionToken = await this.getSessionToken();

Expand Down
12 changes: 12 additions & 0 deletions lib/modules/CommonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export class CommonUtils {
});
}

static resetDB() {
setTimeout(async () => {
try {
await DB.clearDB();

} catch (err) {
Logger.log(err);
Logger.dbError(err);
}
}, 0);
}

static saveSharedStore() {
const sharedState = Store.getSharedState();

Expand Down
20 changes: 20 additions & 0 deletions lib/modules/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ class Database {
};
});
}

async clearDB() {
if (!this.db) {
return Promise.reject('DB is not running');
}

return new Promise((resolve, reject) => {
const transaction = this.db.transaction(tName, 'readwrite');
const store = transaction.objectStore(tName);
const request = store.clear();

request.onsuccess = () => {
resolve(request.result);
};

request.onerror = () => {
reject(request.error);
};
});
}
}

const DB = new Database();
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/EditorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,12 @@ class EditorUtils {
}

const { startRow, startCol, suggestionID } = tableRow;
const ignoreText = `// ${forFile ? 'file ' : ''}deepcode ignore ${suggestionID}: <please specify a reason of ignoring this>`;
const ignoreText = `${forFile ? 'file ' : ''}deepcode ignore ${suggestionID}: <please specify a reason of ignoring this>`;

editor.setCursorBufferPosition(this.createPoint(startRow, startCol));
editor.insertNewlineAbove();
editor.insertText(ignoreText);
editor.toggleLineCommentsInSelection();
editor.save();

this.hideMarkerOverlay(fileName);
Expand Down
18 changes: 9 additions & 9 deletions lib/modules/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ class FileUtils {
ignoreFilters = new Map();

constructor() {
this.projectPaths = this.getProjectPaths();
this.init();
this.initIgnore();
}

getProjectPaths() {
const projectPaths = atom.project.getPaths();
if (!Array.isArray(projectPaths) || projectPaths.length === 0) {
return [];
}

this.projectPaths = projectPaths;
init() {
this.projectPaths = atom.project.getPaths();
}

return projectPaths;
getProjectPaths() {
this.init();
return this.projectPaths;
}

getMainProjectPath() {
this.init();
return this.projectPaths[0];
}

Expand Down Expand Up @@ -86,6 +85,7 @@ class FileUtils {
}

getUnconfirmedProjectFolders() {
this.init();
const confirmedFolders = Store.get(STORE_KEYS.confirmedFolders);
const projectPaths = this.getProjectPaths();

Expand Down
Loading