Skip to content

Commit

Permalink
render traffic lights space only when compact header is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
timche committed Mar 17, 2021
1 parent 42b262b commit a2eb2bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src-main/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from 'electron'
import { app, ipcMain } from 'electron'
import { is } from 'electron-util'

import Store = require('electron-store')
Expand Down Expand Up @@ -145,4 +145,8 @@ if (config.get(ConfigKey.ResetConfig)) {
config.set(ConfigKey.ResetConfig, false)
}

ipcMain.handle('is-compact-header-enabled', () =>
config.get(ConfigKey.CompactHeader)
)

export default config
6 changes: 4 additions & 2 deletions src-renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
useAccounts,
useAddAccount,
useDarkMode,
useEditAccount
useEditAccount,
useIsCompactHeaderEnabled
} from './hooks'
import { isMacOS } from './constants'

export default function App() {
const { isCompactHeaderEnabled } = useIsCompactHeaderEnabled()
const { accounts, selectAccount } = useAccounts()
const { isAddingAccount, addAccount, cancelAddAccount } = useAddAccount()
const {
Expand All @@ -34,7 +36,7 @@ export default function App() {
WebkitAppRegion: 'drag'
}}
>
{isMacOS && <TrafficLightsSpace />}
{isMacOS && isCompactHeaderEnabled && <TrafficLightsSpace />}
<AccountsTab
accounts={accounts}
onSelectAccount={selectAccount}
Expand Down
11 changes: 11 additions & 0 deletions src-renderer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export function useDarkMode() {
}, [])
}

export function useIsCompactHeaderEnabled() {
// Compact header is enabled by default in the app config
const [isCompactHeaderEnabled, setIsCompactHeaderEnabled] = useState(true)

useEffect(() => {
ipc.invoke('is-compact-header-enabled').then(setIsCompactHeaderEnabled)
}, [])

return { isCompactHeaderEnabled }
}

export function useAccounts() {
const [accounts, setAccounts] = useState<Account[]>([])
const [unreadCounts, setUnreadCounts] = useState<UnreadCounts>({})
Expand Down

0 comments on commit a2eb2bc

Please sign in to comment.