Skip to content

feat: add option to exit after launch #690

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/state/middleware.action-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,18 @@ export const actionHubMiddleware =

// Clicked app
else if (clickedApp.match(action)) {
const { appName, isAlt, isShift } = action.payload
const { appName, isAlt, isShift, exitMode } = action.payload

// Ignore if app's bundle id is missing
if (appName) {
openApp(appName, nextState.data.url, isAlt, isShift)
const spawn = openApp(appName, nextState.data.url, isAlt, isShift)
if (exitMode === 'on-launch') {
spawn.then(() => {
pickerWindow?.close()
prefsWindow?.close()
app.exit()
})
}
pickerWindow?.hide()
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/utils/open-app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { execFile } from 'node:child_process'
import { promisify } from 'node:util'

import type { AppName } from '../../config/apps.js'
import { apps } from '../../config/apps.js'

const pExecFile = promisify(execFile)

export function openApp(
appName: AppName,
url: string,
isAlt: boolean,
isShift: boolean,
): void {
): ReturnType<typeof pExecFile> {
const selectedApp = apps[appName]

const convertedUrl =
Expand All @@ -28,5 +31,5 @@ export function openApp(
.filter(Boolean)
.flat()

execFile('open', openArguments)
return pExecFile('open', openArguments)
}
2 changes: 1 addition & 1 deletion src/main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function createWindows(): Promise<void> {
center: true,
fullscreen: false,
fullscreenable: false,
height: 500,
height: 600,
maximizable: false,
minimizable: false,
resizable: false,
Expand Down
3 changes: 3 additions & 0 deletions src/renderers/picker/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux'
import { Spinner } from '../../shared/components/atoms/spinner.js'
import {
useDeepEqualSelector,
useExitMode,
useInstalledApps,
useKeyCodeMap,
useSelector,
Expand Down Expand Up @@ -41,6 +42,7 @@ const App: React.FC = () => {
const apps = useInstalledApps()
const url = useSelector((state) => state.data.url)
const icons = useDeepEqualSelector((state) => state.data.icons)
const exitMode = useExitMode()

const keyCodeMap = useKeyCodeMap()

Expand Down Expand Up @@ -87,6 +89,7 @@ const App: React.FC = () => {
dispatch(
clickedApp({
appName: app.name,
exitMode,
isAlt: event.altKey,
isShift: event.shiftKey,
}),
Expand Down
8 changes: 8 additions & 0 deletions src/renderers/picker/components/organisms/apps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test('kitchen sink', async () => {
name: 'Brave Browser',
},
],
exitMode: 'none',
height: 200,
isSetup: true,
supportMessage: -1,
Expand All @@ -95,6 +96,7 @@ test('kitchen sink', async () => {
addChannelToAction(
clickedApp({
appName: 'Firefox',
exitMode: 'none',
isAlt: false,
isShift: false,
}),
Expand All @@ -113,6 +115,7 @@ test('kitchen sink', async () => {
addChannelToAction(
clickedApp({
appName: 'Brave Browser',
exitMode: 'none',
isAlt: true,
isShift: false,
}),
Expand All @@ -136,6 +139,7 @@ test('should show spinner when no installed apps are found', async () => {
name: 'Safari',
},
],
exitMode: 'none',
height: 200,
isSetup: true,
supportMessage: -1,
Expand All @@ -161,6 +165,7 @@ test('should use hotkey', async () => {
name: 'Safari',
},
],
exitMode: 'none',
height: 200,
isSetup: true,
supportMessage: -1,
Expand Down Expand Up @@ -203,6 +208,7 @@ test('should use hotkey with alt', async () => {
name: 'Safari',
},
],
exitMode: 'none',
height: 200,
isSetup: true,
supportMessage: -1,
Expand Down Expand Up @@ -246,6 +252,7 @@ test('should hold shift', async () => {
addChannelToAction(
clickedApp({
appName: 'Firefox',
exitMode: 'none',
isAlt: false,
isShift: true,
}),
Expand All @@ -265,6 +272,7 @@ test('should order tiles', async () => {
data: defaultData,
storage: {
apps: [],
exitMode: 'none',
height: 200,
isSetup: true,
supportMessage: -1,
Expand Down
1 change: 1 addition & 0 deletions src/renderers/picker/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type OpenAppArguments = {
appName: AppName | undefined
isAlt: boolean
isShift: boolean
exitMode: 'none' | 'on-launch'
}

const startedPicker = picker('started')
Expand Down
26 changes: 25 additions & 1 deletion src/renderers/prefs/components/organisms/pane-general.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useDispatch } from 'react-redux'

import Button from '../../../shared/components/atoms/button.js'
import { useSelector } from '../../../shared/state/hooks.js'
import { useExitMode, useSelector } from '../../../shared/state/hooks.js'
import {
changedExitMode,
clickedRescanApps,
clickedSetAsDefaultBrowserButton,
clickedUpdateButton,
Expand Down Expand Up @@ -43,6 +44,7 @@ export const GeneralPane = (): JSX.Element => {
)

const updateStatus = useSelector((state) => state.data.updateStatus)
const exitMode = useExitMode()

const numberOfInstalledApps = useSelector(
(state) => state.storage.apps.filter((app) => app.isInstalled).length,
Expand Down Expand Up @@ -119,6 +121,28 @@ export const GeneralPane = (): JSX.Element => {
</p>
</Right>
</Row>

<Row>
<Left>Exit on selection:</Left>
<Right>
<input
checked={exitMode === 'on-launch' ? true : undefined}
onChange={(ev) => {
const isChecked = ev.target.checked
if (isChecked) {
dispatch(changedExitMode('on-launch'))
} else {
dispatch(changedExitMode('none'))
}
}}
type="checkbox"
/>
<p className="mt-2 text-sm opacity-70">
Exiting Browserosaurus after selecting a browser can reduce memory
usage and fix issues when using fullscreen apps.
</p>
</Right>
</Row>
</Pane>
)
}
3 changes: 3 additions & 0 deletions src/renderers/prefs/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ const reorderedApp = prefs<{ sourceName: AppName; destinationName: AppName }>(
const clickedHomepageButton = prefs('homepage-button/clicked')
const clickedOpenIssueButton = prefs('open-issue-button/clicked')

const changedExitMode = prefs<'none' | 'on-launch'>('exit-mode/changed')

export {
changedExitMode,
clickedHomepageButton,
clickedOpenIssueButton,
clickedRescanApps,
Expand Down
4 changes: 4 additions & 0 deletions src/renderers/shared/state/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ const useIsSupportMessageHidden = (): boolean => {
const useKeyCodeMap = (): Record<string, string> =>
useShallowEqualSelector((state) => state.data.keyCodeMap)

const useExitMode = (): 'none' | 'on-launch' =>
useShallowEqualSelector((state) => state.storage.exitMode)

export {
InstalledApp,
useDeepEqualSelector,
useExitMode,
useInstalledApps,
useIsSupportMessageHidden,
useKeyCodeMap,
Expand Down
7 changes: 7 additions & 0 deletions src/shared/state/reducer.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
clickedMaybeLater,
} from '../../renderers/picker/state/actions.js'
import {
changedExitMode,
confirmedReset,
reorderedApp,
updatedHotCode,
Expand All @@ -26,10 +27,12 @@ type Storage = {
supportMessage: number
isSetup: boolean
height: number
exitMode: 'none' | 'on-launch'
}

const defaultStorage: Storage = {
apps: [],
exitMode: 'none',
height: 200,
isSetup: false,
supportMessage: 0,
Expand Down Expand Up @@ -111,6 +114,10 @@ const storage = createReducer<Storage>(defaultStorage, (builder) =>

const [removed] = state.apps.splice(sourceIndex, 1)
state.apps.splice(destinationIndex, 0, removed)
})

.addCase(changedExitMode, (state, action) => {
state.exitMode = action.payload
}),
)

Expand Down
Loading