Skip to content

Commit

Permalink
Add option restore previous session at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
sienori committed Dec 18, 2017
1 parent d30d192 commit 4fd6aa6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Tab-Session-Manager/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
"ifLazyLoadingCaptionLabel": {
"message": "When opening a session, the contents of each page are not loaded until you select the tab.<br>If checked off, memory usage greatly increases when session is restored."
},
"ifOpenLastSessionWhenStartUpLabel": {
"message": "Restore previous session at startup"
},
"ifOpenLastSessionWhenStartUpCaptionLabel": {
"message": "When Firefox starts up, restore the session that was closed the last time."
},
"ifAutoSaveLabel": {
"message": "Save the session regularly"
},
Expand Down
25 changes: 19 additions & 6 deletions Tab-Session-Manager/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ initSettings().then(function () {
updateAutoName();
setStorage();
setAutoSave();
autoSaveWhenClose();
autoSaveWhenClose()
.then(openLastSession);
browser.storage.onChanged.addListener(setAutoSave);
browser.tabs.onActivated.addListener(replacePage);
browser.windows.onFocusChanged.addListener(replacePage);
Expand Down Expand Up @@ -173,13 +174,25 @@ function onUpdate(tabId, changeInfo, tab) {
}

function autoSaveWhenClose() {
if (!IsOpeningSession && !IsSavingSession && S.get().ifAutoSaveWhenClose) {
saveSession(browser.i18n.getMessage("winCloseSessionName"), "auto winClose temp").then(function () {
removeOverLimit("winClose");
});
}
return new Promise((resolve, reject) => {
if (!IsOpeningSession && !IsSavingSession && (S.get().ifAutoSaveWhenClose || S.get().ifOpenLastSessionWhenStartUp)) {
saveSession(browser.i18n.getMessage("winCloseSessionName"), "auto winClose temp").then(function () {
removeOverLimit("winClose");
resolve();
});
}
})
};

function openLastSession() {
if (S.get().ifOpenLastSessionWhenStartUp) {
const winCloseSessions = (sessions.filter((element, index, array) => {
return (element.tag.includes("winClose") && !element.tag.includes("temp"));
}));
openSession(winCloseSessions[winCloseSessions.length - 1], true);
}
}

function removeOverLimit(tagState) {
let limit;
if (tagState == "regular") limit = S.get().autoSaveLimit;
Expand Down
18 changes: 18 additions & 0 deletions Tab-Session-Manager/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@
</div>
</div>
</li>

<hr>

<li>
<div class=optionContainer>
<div class=optionText>
<p class=ifOpenLastSessionWhenStartUpLabel>起動時に前回のセッションを復元</p>
<p class="caption ifOpenLastSessionWhenStartUpCaptionLabel">Firefox起動時に前回終了時のセッションを開きます。</p>
</div>
<div class="optionForm">
<label>
<input type="checkbox" id="ifOpenLastSessionWhenStartUp" class=saveByChange>
<span class=checkbox></span>
</label>
</div>
</div>
</li>

<hr>

<li>
Expand Down

0 comments on commit 4fd6aa6

Please sign in to comment.