Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle more gmail links within gmail-desktop #379

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const appName = 'Gmail Desktop'
// Keep in sync with `build.appId` in `package.json`
export const appId = 'io.cheung.gmail-desktop'

export const gmailUrl = 'https://mail.google.com/mail/u/0/'
export const gmailUrl = 'https://mail.google.com/mail/u/'

export const googleAccountsUrl = 'https://accounts.google.com'

Expand Down
113 changes: 63 additions & 50 deletions src/main/account-views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function selectAccountView(accountId: string) {
const mainWindow = getMainWindow()

mainWindow.setTopBrowserView(accountView)
accountView.webContents.focus()
// AccountView.webContents.focus()
accountView.webContents.send('account-selected')
}

Expand Down Expand Up @@ -247,65 +247,78 @@ export function createAccountView(accountId: string, setAsTopView?: boolean) {
}
})

accountView.webContents.on(
'new-window',
// eslint-disable-next-line max-params
(event: any, url, _1, _2, options) => {
event.preventDefault()
const onNewWindowHandler = function (
event: any,
url: string,
_1: string,
_2:
| 'default'
| 'new-window'
| 'foreground-tab'
| 'background-tab'
| 'save-to-disk'
| 'other',
options: Electron.BrowserWindowConstructorOptions
) {
event.preventDefault()

// `Add account` opens `accounts.google.com`
if (url.startsWith(googleAccountsUrl)) {
sendToMainWindow('add-account-request')
hideAccountViews()
return
}

// `Add account` opens `accounts.google.com`
if (url.startsWith(googleAccountsUrl)) {
sendToMainWindow('add-account-request')
hideAccountViews()
if (url.startsWith(gmailUrl)) {
selectAccount(accountId)

// Is a link to download a email
if (url.includes('&view=att&')) {
event.sender.downloadURL(url)
return
}

if (url.startsWith(gmailUrl)) {
selectAccount(accountId)

// Center the new window on the screen
event.newGuest = new BrowserWindow({
...options,
titleBarStyle: 'default',
x: undefined,
y: undefined
})

event.newGuest.webContents.on('dom-ready', () => {
addCustomCSS(event.newGuest)
})

event.newGuest.webContents.on(
'new-window',
(event: Event, url: string) => {
event.preventDefault()
openExternalUrl(url)
}
)
// Center the new window on the screen
event.newGuest = new BrowserWindow({
...options,
titleBarStyle: 'default',
x: undefined,
y: undefined
})

// Workaround for dark mode initialization
event.newGuest.webContents.send('account-selected')
event.newGuest.webContents.on('dom-ready', () => {
addCustomCSS(event.newGuest)
})

return
}
event.newGuest.webContents.on('new-window', onNewWindowHandler)

// Workaround for dark mode initialization
event.newGuest.webContents.send('account-selected')

if (url.startsWith('about:blank')) {
const win = new BrowserWindow({
...options,
show: false
})
// Add context menu to sub windows
addContextMenu(event.newGuest)

win.webContents.once('will-redirect', (_event, url) => {
openExternalUrl(url)
win.destroy()
})
return
}

event.newGuest = win
if (url.startsWith('about:blank')) {
const win = new BrowserWindow({
...options,
show: false
})

return
}
win.webContents.once('will-redirect', (_event, url) => {
openExternalUrl(url)
win.destroy()
})

openExternalUrl(url)
event.newGuest = win

return
}
)

openExternalUrl(url)
}

accountView.webContents.on('new-window', onNewWindowHandler)
}