mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 10:01:39 -05:00
Autocontainers only contain the domains specified.
Added comments and documentation notifying people that autocontainers are experimental. Removed autocontainer section from the containers tutor page. Autocontainers will now correctly open external links in the default container. Removed a couple of config checks that were unnecessary.
This commit is contained in:
parent
6278346c39
commit
1de3f76d21
5 changed files with 33 additions and 45 deletions
|
@ -115,6 +115,7 @@ browser.tabs.onActivated.addListener(ev => {
|
|||
})
|
||||
|
||||
// {{{ AUTOCONTAINERS
|
||||
|
||||
let aucon = new AutoContain()
|
||||
|
||||
// Handle cancelled requests as a result of autocontain.
|
||||
|
|
|
@ -316,9 +316,6 @@ const DEFAULTS = o({
|
|||
// AutoContain directives create a container if it doesn't exist already.
|
||||
auconcreatecontainer: "true",
|
||||
|
||||
// Does not close the tab that navigated to the autocontained domain.
|
||||
auconpreservetab: "true",
|
||||
|
||||
// Performance related settings
|
||||
|
||||
// number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones.
|
||||
|
|
|
@ -2358,11 +2358,10 @@ export function autocmd(event: string, url: string, ...excmd: string[]) {
|
|||
@param domain The domain which will trigger the autoContain directive. Includes all subdomains.
|
||||
@param container The container to open the url in.
|
||||
|
||||
* Note: This is an experimental feature, if you encounter issues please create an issue on github. *
|
||||
For declaring containers that do not yet exist, consider using `auconscreatecontainer true` in your tridactylrc.
|
||||
This allows tridactyl to automatically create containers from your autocontain directives. Note that they will be random icons and colors.
|
||||
|
||||
Use `auconspreservetab true` to keep the uncontained tab open. The use case here is for example to keep your reddit tab open even if you click a youtube link.
|
||||
|
||||
*/
|
||||
//#background
|
||||
export function autocontain(domain: string, container: string) {
|
||||
|
|
|
@ -8,7 +8,13 @@
|
|||
A lot of the inspiration for this code was drawn from the Mozilla `contain facebook` Extension.
|
||||
https://github.com/mozilla/contain-facebook/
|
||||
|
||||
This feature is experimental and can cause heavy CPU usage.
|
||||
|
||||
Issue in MAC that is seemingly caused by the same thing:
|
||||
https://github.com/mozilla/multi-account-containers/issues/572
|
||||
|
||||
*/
|
||||
|
||||
import * as Config from "../config"
|
||||
import * as Container from "./containers"
|
||||
import * as Logging from "../logging"
|
||||
|
@ -47,18 +53,16 @@ interface IAutoContain {
|
|||
cancelRequest(tab: browser.tabs.Tab, details: IDetails): void
|
||||
clearCancelledRequests(tabId: number): void
|
||||
getCancelledRequest(tabId: number): ICancelledRequest
|
||||
parseAucons(details: IDetails): string
|
||||
parseAucons(details: IDetails): Promise<string>
|
||||
}
|
||||
|
||||
export class AutoContain implements IAutoContain {
|
||||
private enabled: boolean
|
||||
private cancelledRequests: ICancelledRequest[] = []
|
||||
|
||||
constructor() {}
|
||||
|
||||
autoContain = async (
|
||||
details: IDetails,
|
||||
): Promise<browser.webRequest.BlockingResponse> => {
|
||||
|
||||
// Do not handle private tabs or invalid tabIds.
|
||||
if (details.tabId === -1) return
|
||||
let tab = await browser.tabs.get(details.tabId)
|
||||
|
@ -67,25 +71,9 @@ export class AutoContain implements IAutoContain {
|
|||
// Only handle http requests.
|
||||
if (details.url.search("^https?://") < 0) return
|
||||
|
||||
// Get container name from Config. Return if containerName is the empty string.
|
||||
// TODO: refactor to return firefox-default in order to comply with behaviour described in conversation in #754
|
||||
let containerName = this.parseAucons(details)
|
||||
if (!containerName) return
|
||||
|
||||
// Checks if containerName exists and creates it if it does not.
|
||||
let containerExists = await Container.exists(containerName)
|
||||
if (!containerExists) {
|
||||
if (Config.get("auconcreatecontainer")) {
|
||||
await Container.create(containerName)
|
||||
} else {
|
||||
logger.error(
|
||||
"Specified container doesn't exist. consider setting 'auconcreatecontainer' to true",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Silently return if we're already in the correct container.
|
||||
let cookieStoreId = await Container.getId(containerName)
|
||||
let cookieStoreId = await this.parseAucons(details)
|
||||
if (tab.cookieStoreId === cookieStoreId) return
|
||||
|
||||
if (this.cancelEarly(tab, details)) return { cancel: true }
|
||||
|
@ -98,8 +86,7 @@ export class AutoContain implements IAutoContain {
|
|||
windowId: tab.windowId,
|
||||
})
|
||||
.then(_ => {
|
||||
let preserveTab = Config.get("auconpreservetab")
|
||||
if (preserveTab && details.originUrl) {
|
||||
if (details.originUrl) {
|
||||
window.history.back()
|
||||
} else {
|
||||
browser.tabs.remove(details.tabId)
|
||||
|
@ -157,19 +144,31 @@ export class AutoContain implements IAutoContain {
|
|||
}
|
||||
}
|
||||
|
||||
parseAucons = (details): string => {
|
||||
// Parses autocontain directives and returns valid cookieStoreIds or errors.
|
||||
parseAucons = async (details): Promise<string> => {
|
||||
let aucons = Config.get("autocontain")
|
||||
const ausites = Object.keys(aucons)
|
||||
const aukeyarr = ausites.filter(
|
||||
e => details.url.search("^https?://.*" + e + "/") >= 0,
|
||||
)
|
||||
if (aukeyarr.length > 1) {
|
||||
logger.error("Too many autocontain directives match this url.")
|
||||
return ""
|
||||
logger.error("Too many autocontain directives match this url. Not containing.")
|
||||
return "firefox-default"
|
||||
} else if (aukeyarr.length === 0) {
|
||||
return ""
|
||||
return "firefox-default"
|
||||
} else {
|
||||
return aucons[aukeyarr[0]]
|
||||
let containerExists = await Container.exists(aucons[aukeyarr[0]])
|
||||
if (!containerExists) {
|
||||
if (Config.get("auconcreatecontainer")) {
|
||||
await Container.create(aucons[aukeyarr[0]])
|
||||
} else {
|
||||
logger.error(
|
||||
"Specified container doesn't exist. consider setting 'auconcreatecontainer' to true",
|
||||
)
|
||||
}
|
||||
}
|
||||
console.log(aucons[aukeyarr[0]])
|
||||
return await Container.getId(aucons[aukeyarr[0]])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,17 +8,9 @@ The perceived benefits of this feature are as described by the Firefox Test Pilo
|
|||
* **Organization:** For heavy tab users, Containers add a layer of visual organization to the Firefox interface.
|
||||
|
||||
### Container related commands
|
||||
* `containercreate name [color] [icon]` Takes 3 arguments with the first one being mandatory. Executing it having only supplied `name` will create a container with that name, a random color and the fingerprint icon.
|
||||
* `containerupdate`
|
||||
* `containerdelete name` Deletes a container, calls `containerclose` before doing so.
|
||||
* `containercreate name [color] [icon]` Creates a new container. Supplying `name` only will create a container called `name`, a random color and the fingerprint icon.
|
||||
* `containerupdate name newname color icon` Updates the container.
|
||||
* `containerclose name` Closes all tabs in a specified container.
|
||||
* `autocontain domain containername` Opens all requests for `domain` in the specified `containername`
|
||||
|
||||
### Auto containers
|
||||
|
||||
Auto containers are directives that live in your `tridactylrc` or your live config and function very much like autocommands.
|
||||
|
||||
Example: `autocontain emacs.org shameful-secrets` will make sure that all tabs visiting `emacs.org` are safely stowed away in the `shameful-secrets` container.
|
||||
The `auconcreatecontainer` setting aims to make configuration of auto containers easier by allowing autocontain directives to create the containers they point to if they do not exist.
|
||||
* `containerdelete name` Deletes a container, calls `containerclose` before deletion
|
||||
|
||||
The <a href='./help.html' rel='next'>final page</a> describes how you can get further help. <a href='./settings.html' rel="prev"></a>
|
||||
|
|
Loading…
Add table
Reference in a new issue