Skip to content

Commit

Permalink
* Fixed session removal feature.
Browse files Browse the repository at this point in the history
* Removing linked session has been only unlinking the project and required to then remove the session. It's now unlink and remove the session.
* Badge displays improvement.
  • Loading branch information
agektmr committed Sep 24, 2016
1 parent b267ad7 commit e32821a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## Version 4.0.2
* Removing linked session has been only unlinking the project and required to then remove the session. It's now unlink and remove the session.
* Badge displays improvement.

## Version 4.0.1
* Fixed critical bug that deletes all sessions when max unlinked sessions option is set to `Unlimited`.

Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "project-tab-manager",
"version": "4.0.1",
"version": "4.0.2",
"authors": [
"Eiji Kitamura <agektmr@gmail.com>"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ProjectTabManager",
"version": "4.0.1",
"version": "4.0.2",
"description": "Project tab management per window on your Chrome",
"main": "app/js/background.js",
"scripts": {
Expand Down
36 changes: 28 additions & 8 deletions src/js/ProjectManager.js
Expand Up @@ -86,10 +86,7 @@ const ProjectManager = (function() {
*/
open() {
sessionManager.openingProject = this.id;

chrome.browserAction.setBadgeText({
text: this.title.substr(0, 4).trim() || ''
});
this.setBadgeText();

// If there's no fields, open an empty window
if (this.fields.length === 0) {
Expand Down Expand Up @@ -159,10 +156,15 @@ const ProjectManager = (function() {
if (this.session) {
this.session.setId(folder.id);
}
resolve();
this.setBadgeText();
resolve(folder);
});
} else {
bookmarkManager.renameFolder(this.id, name).then(resolve);
bookmarkManager.renameFolder(this.id, name)
.then(folder => {
this.setBadgeText();
resolve(folder);
});
}
});
}
Expand Down Expand Up @@ -280,6 +282,16 @@ const ProjectManager = (function() {
this.session.setId(this.id);
this.load(this.session.tabs, undefined);
}

/**
* Sets badge text
* @param {String} winId Window Id
*/
setBadgeText() {
let text = this.title.substr(0, 4).trim() || '';
if (config_.debug) console.log(`[ProjectEntiry] Badge set to "${text}"`, this);
chrome.browserAction.setBadgeText({text: text});
}
}

/**
Expand All @@ -291,7 +303,14 @@ const ProjectManager = (function() {
config_ = config;
this.projects = [];

chrome.windows.onFocusChanged.addListener(this.setBadgeText.bind(this));
chrome.windows.onFocusChanged.addListener(winId => {
let project = this.getProjectFromWinId(winId);
if (project) {
project.setBadgeText();
} else {
chrome.browserAction.setBadgeText({text: ''});
}
});
}

/**
Expand Down Expand Up @@ -415,7 +434,8 @@ const ProjectManager = (function() {
if (project.bookmark) {
project.deassociateBookmark();
}
return sessionManager.removeSessionFromProjectId(id);
let sessionId = project.session.id;
return sessionManager.removeSessionFromId(sessionId);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/js/SessionManager.js
Expand Up @@ -392,6 +392,7 @@ const SessionManager = (function() {
chrome.windows.onFocusChanged.addListener(this.onwindowfocuschanged.bind(this));
chrome.windows.onRemoved.addListener(this.onwindowremoved.bind(this));
}

/**
* Adds Project
* @param {chrome.tabs.Tab} tab - adds a tab to project
Expand Down Expand Up @@ -617,6 +618,23 @@ const SessionManager = (function() {
}
}

/**
* Removes session of given id
* @param {String} id [description]
* @return Promise A promise that resolves with session object
*/
removeSessionFromId(id) {
for (let i = 0; i < this.sessions.length; i++) {
if (this.sessions[i].id === id) {
let session = this.sessions.splice(i, 1);
if (config_.debug) console.log(`[SessionManager] removed session of id:`, id);
UpdateManager.storeSessions();
return Promise.resolve(session);
}
}
return Promise.reject();
}

/**
* Removes session of given project id
* @param {String} projectId [description]
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Expand Up @@ -3,7 +3,7 @@
"short_name": "PTM",
"description": "__MSG_description__",
"manifest_version": 2,
"version": "4.0.1",
"version": "4.0.2",
"icons": {
"48": "img/48.png",
"128": "img/128.png"
Expand Down

0 comments on commit e32821a

Please sign in to comment.