Skip to content

Commit

Permalink
Merge pull request #24 from Tech-Nest-Ventures/20-not-getting-titlesu…
Browse files Browse the repository at this point in the history
…rls-in-firefox

fix: enable getting URLs for firefox
  • Loading branch information
timeowilliams authored Nov 2, 2024
2 parents adae973 + 6031e5c commit 788e209
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,9 @@ This will whitelist the app for future use.


```

4. For Firefox users, there's addditional setup to get the URL of the active tab.

First enable Firefox support for VoiceOver by going to about:config and setting the accessibility.force_disabled property to -1

Source: https://apple.stackexchange.com/questions/404841/get-url-of-opened-firefox-tabs-from-terminal
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export function startActivityMonitoring() {
let URL = ''

if (isBrowser(appName)) {

URL = getBaseURL(await getBrowserURL(appName))
}

Expand Down Expand Up @@ -401,7 +402,7 @@ app.on('browser-window-focus', () => {
mainWindow.webContents.send('deep-work-data-response', chartData)
}
})
export function handleUserLogout() {
export function handleUserLogout(): void {
log.info('Handling user logout')
store.delete('user')
store.set('lastResetDate', dayjs().toISOString())
Expand Down
9 changes: 7 additions & 2 deletions src/productivityUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,16 @@ export function getBrowserURL(browser: browser): Promise<string> {
let script = `osascript -e 'tell application "${browser}" to get URL of active tab of front window'`
if (browser === 'Safari') {
script = `osascript -e 'tell application "${browser}" to get URL of front document'`
} else if (browser.toLowerCase() === 'firefox') {
script = `
osascript -e 'tell application "System Events" to get value of UI element 1 of combo box 1 of toolbar "Navigation" of first group of front window of application process "Firefox"'
`
}

exec(script, (err, stdout, stderr) => {
if (err) {
console.error(`Error getting URL for ${browser}: ${stderr}`)
resolve('') // Return an empty string if there's an error
resolve('')
} else {
resolve(stdout.trim())
}
Expand Down Expand Up @@ -244,6 +248,7 @@ export function isBrowser(appName: string): appName is browser {
'Vivaldi',
'Opera',
'Safari',
'Firefox'
'Firefox',
'firefox'
].includes(appName)
}
2 changes: 1 addition & 1 deletion src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const App = (props: ComponentProps<typeof Router>) => {
// Initialize the tour for new users
createEffect(() => {
console.log('checking if logged in and new user')
if(localStorage.getItem('onboarded') === 'false' || !localStorage.getItem('onboarded')) {
if((localStorage.getItem('onboarded') === 'false' || !localStorage.getItem('onboarded')) && localStorage.getItem('token') && localStorage.getItem('user')) {
initializeTour()
localStorage.setItem('onboarded', 'true')
setIsNewUser(false)
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export type browser =
| 'Opera'
| 'Safari'
| 'Firefox'
| 'firefox'

export interface WorkContext {
type: 'URL' | 'appName'
Expand Down

0 comments on commit 788e209

Please sign in to comment.