Skip to content

Commit

Permalink
Add "Open in Incognito Window" URL action
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jan 8, 2020
1 parent 9a718ee commit c45d51e
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 1 deletion.
13 changes: 13 additions & 0 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func init() {
} {
tabActions[a.Name()] = a
}

a := openIncognito{}
urlActions[a.Name()] = a
}

func loadURLActions() error {
Expand Down Expand Up @@ -130,7 +133,17 @@ func (a uAction) Run(URL string) error {
return err
}

type openIncognito struct{}

func (a openIncognito) Name() string { return "Open in Incognito Window" }
func (a openIncognito) Icon() *aw.Icon { return iconIncognito }
func (a openIncognito) Run(URL string) error {
mustClient().OpenIncognito(URL)
return nil
}

var (
_ tabAction = (*tAction)(nil)
_ urlAction = (*uAction)(nil)
_ urlAction = openIncognito{}
)
13 changes: 13 additions & 0 deletions extension/alfred.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ const Background = function() {
case 'run-bookmarklet':
p = self.runBookmarklet(msg.params);
break;
case 'open-incognito':
p = self.openIncognito(msg.params);
break;
default:
console.error(`unknown command: ${msg.command}`);
self.sendError(msg.id, 'unknown command');
Expand Down Expand Up @@ -473,6 +476,16 @@ const Background = function() {
});
};

/**
* Handle "open-incognito" command.
* @param {string} url - URL to open in a new Incognito window.
* @return {Promise} - Promise that resolves to null.
*/
self.openIncognito = url => {
console.debug(`open-incognito ${url}`);
return browser.windows.create({ incognito: true, url: url });
};

/**
* Return active tab.
* @param {number} winId - ID of window to get active tab of.
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons.afdesign
Binary file not shown.
3 changes: 2 additions & 1 deletion icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ var (
iconDocs = &aw.Icon{Value: "icons/docs.png"}
iconError = &aw.Icon{Value: "icons/error.png"}
iconHistory = &aw.Icon{Value: "icons/history.png"}
iconIssue = &aw.Icon{Value: "icons/issue.png"}
iconIncognito = &aw.Icon{Value: "icons/incognito.png"}
iconInstall = &aw.Icon{Value: "icons/install.png"}
iconIssue = &aw.Icon{Value: "icons/issue.png"}
iconMore = &aw.Icon{Value: "icons/more.png"}
iconScript = &aw.Icon{Value: "icons/script.png"}
iconTab = &aw.Icon{Value: "icons/tab.png"}
Expand Down
Binary file modified icons/bookmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/bookmarklet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/incognito.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/install.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/more.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/update-available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/update-ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/url.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (c *rpcClient) CloseTabsOther(tabID int) error {
return c.client.Call("Firefox.CloseTabsOther", tabID, nil)
}

// OpenIncognito opens a URL in a new Incognito window.
func (c *rpcClient) OpenIncognito(URL string) error {
return c.client.Call("Firefox.OpenIncognito", URL, nil)
}

// func (c *rpcClient) RunJS(script string) error {
// return c.client.Call("Firefox.RunJS", script, nil)
// }
Expand Down
10 changes: 10 additions & 0 deletions rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ func (s *rpcServer) Downloads(query string, downloads *[]Download) error {
return nil
}

// OpenIncognito opens URL in a new incognito window.
func (s *rpcServer) OpenIncognito(URL string, _ *struct{}) error {
defer util.Timed(time.Now(), "open incognito")
var r responseNone
if err := s.ff.call("open-incognito", URL, &r); err != nil {
return err
}
return nil
}

// func (s *rpcServer) RunJS(script string, _ *struct{}) error {
// defer util.Timed(time.Now(), "execute JS")
// var r responseNone
Expand Down
Binary file modified scripts/Open in Default Application.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c45d51e

Please sign in to comment.