Skip to content

Commit

Permalink
Merge pull request #363 from ipfs-shipyard/fix/android
Browse files Browse the repository at this point in the history
Fixes and docs related to Firefox for Android
  • Loading branch information
lidel authored Feb 5, 2018
2 parents 6baacd9 + e5a42c9 commit 83f5028
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 33 deletions.
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Submit PR with a new locale or improve existing ones via [Crowdin](https://crowd

You will need [NodeJS](https://nodejs.org/) and [Firefox](https://www.mozilla.org/en-US/firefox/developer/). Make sure `npm` and `firefox` are in your `PATH`.

It may be a good idea to use `yarn` instead of `npm`. We provide `yarn.lock` if you choose to do so.

### Installing Dependencies

To install all dependencies into to `node_modules` directory, execute:
Expand All @@ -52,6 +54,38 @@ npm run build

Then open up `chrome://extensions` in Chromium-based browser, enable "Developer mode", click "Load unpacked extension..." and point it at `add-on/manifest.json`

### Firefox for Android

To run your extension in [Firefox for Android](https://www.mozilla.org/en-US/firefox/mobile/), follow these instructions:

- [Set up your computer and Android emulator or device](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Developing_WebExtensions_for_Firefox_for_Android#Set_up_your_computer_and_Android_emulator_or_device) (enable Developer Mode, USB Debugging etc)

With device connected to your development computer, run:

```
web-ext run -s add-on --target=firefox-android
```

It will list all connected devices with their IDs. If the list is empty, go back to the setup step.

Next, deploy extension to the specific device:

```
web-ext run --target=firefox-android --android-device=<device ID>
```

The first time you run this command there may be a popup on your Android device asking if you want to grant access over USB.

#### Debugging in Firefox for Android

Remote debug port will be printed to console right after successful deployment:

```
You can connect to this Android device on TCP port <debug PORT>
```

The fastest way to connect is to open `chrome://devtools/content/framework/connect/connect.xhtml` in Firefox the same machine you run web-ext from.

## Useful Tasks

Each `npm` task can be run separately. The most useful ones are:
Expand Down
7 changes: 6 additions & 1 deletion add-on/src/lib/context-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ function createContextMenus (getState, ipfsPathValidator, { onUploadToIpfs, onCo
onclick: onCopyAddressAtPublicGw
})
} catch (err) {
// documentUrlPatterns is not supported in brave
// documentUrlPatterns is not supported in Brave
if (err.message.indexOf('createProperties.documentUrlPatterns of contextMenus.create is not supported yet') > -1) {
console.warn('[ipfs-companion] Context menus disabled - createProperties.documentUrlPatterns of contextMenus.create is not supported yet')
return { update: () => Promise.resolve() }
}
// contextMenus are not supported in Firefox for Android
if (err.message === 'browser.contextMenus is undefined' || typeof browser.contextMenus === 'undefined') {
console.warn('[ipfs-companion] Context menus disabled - browser.contextMenus is undefined')
return { update: () => Promise.resolve() }
}
throw err
}

Expand Down
5 changes: 5 additions & 0 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ module.exports = async function init () {
// -------------------------------------------------------------------

async function updateBrowserActionBadge () {
if (typeof browser.browserAction.setBadgeBackgroundColor === 'undefined') {
// Firefox for Android does not have this UI, so we just skip it
return
}

let badgeText, badgeColor, badgeIcon
badgeText = state.peerCount.toString()
if (state.peerCount > 0) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"sinon-chrome": "2.2.1",
"standard": "10.0.3",
"watchify": "3.9.0",
"web-ext": "2.3.1"
"web-ext": "2.3.2"
},
"dependencies": {
"choo": "6.6.1",
Expand Down
3 changes: 2 additions & 1 deletion test/functional/lib/ipfs-companion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { optionDefaults } = require('../../../add-on/src/lib/options')
describe('init', () => {
let init

before(() => {
before(function () {
this.timeout = 1000 * 10
global.window = {}
global.browser = browser
global.URL = URL
Expand Down
Loading

0 comments on commit 83f5028

Please sign in to comment.