Skip to content

Commit

Permalink
Merge pull request #175 from cxw42/switchover
Browse files Browse the repository at this point in the history
v0.2.0, and switchover to Brunch build system
  • Loading branch information
cxw42 authored Apr 7, 2019
2 parents 8792425 + 6acfb57 commit 1689e5e
Show file tree
Hide file tree
Showing 280 changed files with 24,530 additions and 163,030 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ core
*.stackdump
/*_history
tags
/webstore.zip
*.zip
foo.*

# Outputs
# Output directories
/public*
/build*
/doc/
/dist/
*-packed/
*.zip

# A holding pen
/spare

# Test outputs
*.e
*.map
*.txt

# readline history
*.history

# dependencies
# External dependencies (managed by npm)
/node_modules/
10 changes: 6 additions & 4 deletions INTERNALS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# TabFern internals

NOTE: this document has not yet been fully updated for brunch usage.

## Project layout

- `/tabfern`: The development tree for TabFern itself
* `/tabfern/src`: Main source
* `/tabfern/app`: Main source
- `/tabfern/src/bg`: Background page
- `/tabfern/src/view`: Popup
- `/tabfern/src/options_custom`: Options page
- `/tabfern/src/win`: Popup
- `/tabfern/src/settings`: Options page
* `/tabfern/test`: Jasmine tests of TabFern
- `/dist`: where build output from the build process will eventually go.
- `/tools`: Useful scripts
- `/webstore`: The latest version of TabFern released to the Chrome Web Store.
Updated manually by the maintainers.
- `/doc`: Documentation
Expand Down
50 changes: 0 additions & 50 deletions Makefile

This file was deleted.

10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ See [INTERNALS.md](INTERNALS.md) for details of how the code is structured.

# Legal

Copyright (c) 2017 Chris White and contributors. CC-BY-SA 4.0 International.
See [LICENSE.md](LICENSE.md) for details, which are controlling in case of any
difference between that file and this section.
Copyright (c) 2017--2019 Chris White and contributors. CC-BY-SA 4.0
International. See [LICENSE.md](LICENSE.md) for details, which are controlling
in case of any difference between that file and this section.

Contributors (in alphabetical order, case-insensitive):

- [Devin Rhode](https://github.com/devinrhode2)
- [Jasmine Hegman](https://github.com/r4j4h)
- [Procyon-b](https://github.com/Procyon-b)
- [RiotPharaoh](https://github.com/RiotPharaoh)
- [rwexmd](https://github.com/rwexmd)
- [Yasujizr](https://github.com/Yasujizr)

Originally inspired by
[Tabs Outliner](https://chrome.google.com/webstore/detail/tabs-outliner/eggkanocgddhmamlbiijnphhppkpkmkl)
by Vladyslav Volovyk. However, TabFern is not derived from Tabs Outliner.
TabFern is not affiliated in any way with Vladyslav or Tabs Outliner.

![logo](https://raw.githubusercontent.com/cxw42/TabFern/master/webstore/assets/fern128.png)

83 changes: 50 additions & 33 deletions tabfern/src/bg/background.js → app/bg/background.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
// background.js: background script for TabFern. Runs as a module.
// CC-BY-SA 3.0
console.log('TabFern: running background.js');
console.log('TabFern: running ' + __filename);

if(false) { // Vendor files - listed here only so they'll be bundled
require('vendor/validation');
require('vendor/common');
}

const S = require('common/setting-definitions'); // in app/

/// The module exports, for use in command-line debugging
let me = {
viewWindowID: undefined, // the chrome.windows ID of our view
loadView: undefined,
};

module.exports = me;

var viewWindowID; // the chrome.windows ID of our view

//////////////////////////////////////////////////////////////////////////
// Helpers //

// Open the view
function loadView()
me.loadView = function loadView()
{
console.log("TabFern: Opening view");
chrome.windows.create(
{ 'url': chrome.runtime.getURL('src/view/main.html'),
{ 'url': chrome.runtime.getURL('win/container.html'),
'type': 'popup',
'left': 10,
'top': 10,
'width': 200,
'height': 200,
//'focused': true
// Note: `focused` is not supported on Firefox, but
// focused=true is usually the effect.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1253129
// However, Firefox does support windows.update with focused.
},
function(win) {
viewWindowID = win.id;
console.log('TabFern new View ID: ' + viewWindowID.toString());
me.viewWindowID = win.id;
console.log('TabFern new View ID: ' + me.viewWindowID.toString());
chrome.windows.update(win.id, {focused:true}, ignore_chrome_error);
});
} //loadView()
Expand All @@ -37,8 +56,8 @@ function moveTabFernViewToWindow(reference_cwin)
function clip(x, lo, hi) { if(hi<lo) hi=lo; return Math.min(hi, Math.max(lo, x)); }

if(!isLastError()) {
if(!viewWindowID) return;
chrome.windows.get(viewWindowID, function(view_cwin) {
if(!me.viewWindowID) return;
chrome.windows.get(me.viewWindowID, function(view_cwin) {
// TODO handle Chrome error
let updates = {left: reference_cwin.left+16,
top: reference_cwin.top+16,
Expand All @@ -49,7 +68,7 @@ function moveTabFernViewToWindow(reference_cwin)
updates.width = clip(view_cwin.width, 200, reference_cwin.width-32);
updates.height = clip(view_cwin.height, 100, reference_cwin.height-32);

chrome.windows.update(viewWindowID, updates
chrome.windows.update(me.viewWindowID, updates
// TODO handle Chrome error
);
});
Expand All @@ -63,18 +82,18 @@ function moveTabFernViewToWindow(reference_cwin)
let onClickedListener = function(tab) {

// If viewWindowID is undefined then there isn't a popup currently open.
if (typeof viewWindowID === "undefined") { // Open the popup
loadView();
if (typeof me.viewWindowID === "undefined") { // Open the popup
me.loadView();
} else { // There's currently a popup open
// Bring it to the front so the user can see it
chrome.windows.update(viewWindowID, { "focused": true });
chrome.windows.update(me.viewWindowID, { "focused": true });
}

// Set a timer to bring the window to the front on another click
// that follows fairly shortly.
if(tab) {
let clickListener = function(tab) {
if(viewWindowID && tab.windowId) {
if(me.viewWindowID && tab.windowId) {
chrome.windows.get(tab.windowId, moveTabFernViewToWindow);
}
};
Expand Down Expand Up @@ -104,9 +123,10 @@ chrome.commands.onCommand.addListener(onCommandListener);
// When a window is closed
chrome.windows.onRemoved.addListener(function(windowId) {
// If the window getting closed is the popup we created
if (windowId === viewWindowID) {
if (windowId === me.viewWindowID) {
// Set viewWindowID to undefined so we know the popup is not open
viewWindowID = undefined;
me.viewWindowID = undefined;
console.log('Popup window was closed');
}
});

Expand Down Expand Up @@ -155,39 +175,36 @@ function messageListener(request, sender, sendResponse)
}

if(request.msg === MSG_GET_VIEW_WIN_ID && !request.response) {
console.log('Responding with window ID ' + viewWindowID.toString());
sendResponse({msg: request.msg, response: true, id: viewWindowID});
console.log('Responding with window ID ' + me.viewWindowID.toString());
sendResponse({msg: request.msg, response: true, id: me.viewWindowID});
}
} //messageListener

chrome.runtime.onMessage.addListener(messageListener);

//var settings = new Store('settings', {
// 'sample_setting': 'This is how you use Store.js to remember values'
//});

//////////////////////////////////////////////////////////////////////////
// MAIN //

// Create the main window when Chrome starts
window.addEventListener('load',
function() {
console.log('TabFern: background window loaded');
if(getBoolSetting(CFG_POPUP_ON_STARTUP)) {
console.log('Opening popup window');
setTimeout(loadView, 500);
if(true) {
callbackOnLoad(
function() {
console.log('TabFern: background window loaded');
if(S.getBool(S.POPUP_ON_STARTUP)) {
console.log('Opening popup window');
setTimeout(me.loadView, 500);
}
}
},
{ 'once': true }
);
);
}

// Set the defaults for the options. The settings boilerplate from
// extensionizr does not appear to have this facility.
for(opt in CFG_DEFAULTS) {
setSettingIfNonexistent(opt, CFG_DEFAULTS[opt]);
for(let opt in S.defaults) {
S.setIfNonexistent(opt, S.defaults[opt]);
}

setSetting(CFG_PRUNE_NEW_WINDOWS, false); // don't prune - it's a Chrome bug
S.set(S.PRUNE_NEW_WINDOWS, false); // don't prune - it's a Chrome bug
// See https://bugs.chromium.org/p/chromium/issues/detail?id=883709#c16

console.log('TabFern: done running background.js');
Expand Down
Loading

0 comments on commit 1689e5e

Please sign in to comment.