Skip to content

Commit

Permalink
feat: add support for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Sep 27, 2020
1 parent addcb5c commit 30b5e88
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 37 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"build:prod:zip:all": "run-s 'build:prod:zip:@(chrome|edge|firefox|opera)'",
"start:chrome": "web-ext run -s dist/chrome -t chromium",
"start:firefox": "web-ext run -s dist/firefox -t firefox-desktop",
"start:android": "web-ext run -s dist/firefox -t firefox-android",
"inspect": "cross-env NODE_ENV=production gulp inspect",
"update": "ncu --upgrade",
"push": "git push --follow-tags origin master",
Expand Down
19 changes: 10 additions & 9 deletions src/action/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ import {
showContributePage,
showProjectPage
} from 'utils/app';
import {getText} from 'utils/common';
import {getText, isAndroid} from 'utils/common';
import {optionKeys} from 'utils/data';
export default {
Expand Down Expand Up @@ -146,6 +146,7 @@ export default {
},
hasScrollBar: false,
isPopup: false,
tabId: null,
dataTypes: [],
clearAllDataTypes: false,
Expand Down Expand Up @@ -201,8 +202,8 @@ export default {
},
closeAction: async function () {
if (!this.isPopup) {
browser.tabs.remove((await browser.tabs.getCurrent()).id);
if (this.tabId) {
browser.tabs.remove(this.tabId);
} else {
window.close();
}
Expand All @@ -222,7 +223,11 @@ export default {
},
created: async function () {
this.isPopup = !(await browser.tabs.getCurrent());
const currentTab = await browser.tabs.getCurrent();
if (currentTab) {
this.tabId = currentTab.id;
}
this.isPopup = !this.tabId && !(await isAndroid());
if (!this.isPopup) {
document.documentElement.style.height = '100%';
document.body.style.minWidth = 'initial';
Expand Down Expand Up @@ -268,11 +273,6 @@ $mdc-theme-primary: #1abc9c;
@import 'vue-resize/dist/vue-resize';
html,
body {
overflow: hidden;
}
body,
#app {
height: 100%;
Expand All @@ -286,6 +286,7 @@ body,
body {
margin: 0;
min-width: 387px;
overflow: hidden;
@include mdc-typography-base;
font-size: 100%;
background-color: #ffffff;
Expand Down
2 changes: 1 addition & 1 deletion src/action/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function init() {
await document.fonts.load('500 14px Roboto');
} catch (err) {}

const vm = new Vue({
new Vue({
el: '#app',
render: h => h(App)
});
Expand Down
60 changes: 35 additions & 25 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import browser from 'webextension-polyfill';

import {initStorage} from 'storage/init';
import storage from 'storage/storage';
import {getText, getActiveTab} from 'utils/common';
import {getText, getActiveTab, isAndroid} from 'utils/common';
import {
getEnabledDataTypes,
showNotification,
Expand Down Expand Up @@ -80,28 +80,33 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {

let tempTabId;
const {id: activeTabId} = await getActiveTab();
const android = await isAndroid();

if (options.closeTabs !== 'false') {
if (['all', 'allButActive', 'exit'].includes(options.closeTabs)) {
const windows = await browser.windows.getAll({populate: true});
for (const window of windows) {
if (!window.focused) {
const tabIds = window.tabs.reduce((results, tab) => {
if (!tab.pinned || options.closePinnedTabs) {
results.push(tab.id);
}
return results;
}, []);
await browser.tabs.remove(tabIds);
const backgroundWindowTabs = await browser.tabs.query({
lastFocusedWindow: false
});
const tabIds = backgroundWindowTabs.reduce((results, tab) => {
if (
!tab.pinned ||
options.closePinnedTabs ||
options.closeTabs === 'exit'
) {
results.push(tab.id);
}
}
return results;
}, []);
await browser.tabs.remove(tabIds);
}

const activeWindow = await browser.windows.getLastFocused({populate: true});
const focusedWindowTabs = await browser.tabs.query({
lastFocusedWindow: true
});

let pinnedTabIds = [];
if (!options.closePinnedTabs) {
pinnedTabIds = activeWindow.tabs.reduce((results, tab) => {
if (!options.closePinnedTabs || options.closeTabs === 'exit') {
pinnedTabIds = focusedWindowTabs.reduce((results, tab) => {
if (tab.pinned) {
results.push(tab.id);
}
Expand All @@ -110,10 +115,10 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
}

if (options.closeTabs === 'all') {
if (!pinnedTabIds.length) {
if (!pinnedTabIds.length && !android) {
({id: tempTabId} = await browser.tabs.create({active: false}));
}
const tabIds = activeWindow.tabs.reduce((results, tab) => {
const tabIds = focusedWindowTabs.reduce((results, tab) => {
if (!pinnedTabIds.includes(tab.id)) {
results.push(tab.id);
}
Expand All @@ -122,15 +127,15 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {

await browser.tabs.remove(tabIds);
} else if (options.closeTabs === 'active') {
if (!pinnedTabIds.length && activeWindow.tabs.length === 1) {
if (!pinnedTabIds.length && focusedWindowTabs.length === 1 && !android) {
({id: tempTabId} = await browser.tabs.create({active: false}));
}

if (!pinnedTabIds.includes(activeTabId)) {
await browser.tabs.remove(activeTabId);
}
} else if (options.closeTabs === 'allButActive') {
const tabIds = activeWindow.tabs.reduce((results, tab) => {
const tabIds = focusedWindowTabs.reduce((results, tab) => {
if (!pinnedTabIds.includes(tab.id) && tab.id !== activeTabId) {
results.push(tab.id);
}
Expand All @@ -139,11 +144,14 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {

await browser.tabs.remove(tabIds);
} else if (options.closeTabs === 'exit') {
({id: tempTabId} = await browser.tabs.create({
url: 'about:blank',
active: false
}));
await browser.tabs.remove(activeWindow.tabs.map(tab => tab.id));
if (!android) {
({id: tempTabId} = await browser.tabs.create({
url: 'about:blank',
active: false
}));
}

await browser.tabs.remove(focusedWindowTabs.map(tab => tab.id));
}
}

Expand All @@ -164,7 +172,9 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
}

if (options.closeTabs === 'exit') {
browser.tabs.remove(tempTabId);
if (tempTabId) {
browser.tabs.remove(tempTabId);
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/options/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function init() {
await document.fonts.load('500 14px Roboto');
} catch (err) {}

const vm = new Vue({
new Vue({
el: '#app',
render: h => h(App)
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ async function isAndroid() {
return os === 'android';
}

export {getText, createTab, getActiveTab};
export {getText, createTab, getActiveTab, isAndroid};

0 comments on commit 30b5e88

Please sign in to comment.