Skip to content

Commit

Permalink
refactor: move initial default browser check to be included in redux …
Browse files Browse the repository at this point in the history
…pipeline
  • Loading branch information
will-stone committed Jan 2, 2022
1 parent 1556a0c commit 30ac0e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@ import type { AnyAction } from '@reduxjs/toolkit'
import electron, { app } from 'electron'

import { Channel } from '../shared/state/channels'
import { database } from './database'
import { readiedApp } from './state/actions'
import { dispatch } from './state/store'
import { urlOpener } from './state/thunk.url-opener'

// Attempt to fix this bug: https://github.com/electron/electron/issues/20944
app.commandLine.appendArgument('--enable-features=Metal')

if (database.get('firstRun')) {
// Prompt to set as default browser
app.setAsDefaultProtocolClient('http')
app.setAsDefaultProtocolClient('https')
}

database.set('firstRun', false)

app.on('ready', () => dispatch(readiedApp()))

// App doesn't always close on ctrl-c in console, this fixes that
Expand Down
7 changes: 7 additions & 0 deletions src/main/state/middleware.action-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export const actionHubMiddleware =
(action) => {
const previousState = getState()

// Initial request to prompt to become default browser
// Check must happen before reducer run, before firstRun set to false
if (readiedApp.match(action) && previousState.storage.firstRun !== false) {
app.setAsDefaultProtocolClient('http')
app.setAsDefaultProtocolClient('https')
}

// Move to next middleware
const result = next(action)

Expand Down
5 changes: 5 additions & 0 deletions src/shared/state/reducer.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { AppId } from '../../config/apps'
import {
changedPickerWindowBounds,
installedAppsRetrieved,
readiedApp,
syncReducers,
} from '../../main/state/actions'
import {
Expand Down Expand Up @@ -31,6 +32,10 @@ export const defaultStorage: Storage = {

export const storage = createReducer<Storage>(defaultStorage, (builder) =>
builder
.addCase(readiedApp, (state) => {
state.firstRun = false
})

.addCase(syncReducers, (_, action) => action.payload.storage)

.addCase(installedAppsRetrieved, (state, action) => {
Expand Down

0 comments on commit 30ac0e1

Please sign in to comment.