Skip to content

Commit

Permalink
Update README and the on-install behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
itsojon committed May 12, 2020
1 parent 7190e25 commit e679018
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
# Trotto Go Links Browser Extension

A browser extension providing go links goodness.

## Build the extension (and watch for changes)
## Building the extension and watching for changes

```
npm install
grunt --edition=lite
```

Use `lite` for now. TODO: Document how to make use of different editions.
Once the Grunt task is running, you can load the unpacked extension from `dist_lite` as
described [here](https://developer.chrome.com/extensions/getstarted#manifest) and use the `dist_lite.zip` file
to [publish](https://developer.chrome.com/extensions/hosting) your own version of the extension.

TODO: Document how to make use of different editions.

## Specifying a go links application instance

To use a go links application instance other than the managed instance of Trotto at https://trot.to, update
the `DEFAULT_INSTANCE` constant in `src/background.js`. Feel free to test with the test instance of Trotto at
https://latest-master.trotto.dev:

```
const DEFAULT_INSTANCE = 'https://latest-master.trotto.dev';
```

## Bumping the extension version

To bump the extension version, update the `version` key in `editions/lite/manifest_overrides.json`.

## FAQs

### Why does the extension open and immediately close a tab on installation?

Chrome has to be "taught" that go links are URLs and not search engine queries. Otherwise, typing "go/foo" just
takes you to https://www.google.com/search?q=go%2Ffoo. So when the extension is installed, it automatically opens
https://go/ in a new tab so Chrome learns that `go` should be treated as a hostname. The extension then quickly
closes that tab so that it's not cluttering the window.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
},
"homepage": "https://github.com/trotto/browser-extension#readme",
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-compress": "^1.4.3",
"grunt": "^1.1.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-update-json": "^0.2.2",
Expand Down
19 changes: 17 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,23 @@ chrome.runtime.onInstalled.addListener(function(details) {
// the app. So reload that tab and focus on it so 1) Chrome learns to treat "go/whatever" as a URL and 2) the
// user can continue the walkthrough experience.
if (tabs.length === 0) {
chrome.tabs.create({
url: 'https://go/trotto-init'
// then open a new tab next to the current tab
chrome.tabs.query({active: true}, function(tabs) {
var createArgs = {
url: 'https://go/'
};

if (tabs.length === 1) {
createArgs.index = tabs[0].index + 1;
}

chrome.tabs.create(createArgs, (newTab) => {
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (tabId !== newTab.id) return;

if (changeInfo.status === 'loading') chrome.tabs.remove(newTab.id);
});
});
});
} else {
chrome.tabs.update(tabs[0].id, {url: 'https://go/trotto-init', active: true});
Expand Down

0 comments on commit e679018

Please sign in to comment.