Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Add openAtLogin option #893

Merged
merged 1 commit into from
Dec 5, 2021
Merged
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
28 changes: 28 additions & 0 deletions __tests__/src/renderer/pages/settings/general.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,32 @@ describe('General', () => {
expect(global.electron.mixpanel.syncConfig).toHaveBeenCalled()
})
})

describe('when click open-at-login', () => {
beforeEach(() => {
wrapper = factory()
wrapper.find(testId('open-at-login')).trigger('click')
})

it('toggles openAtLogin', () => {
expect(global.electron.config.set).toHaveBeenCalledWith(
'openAtLogin',
true
)
})

it('sends mixpanel event', () => {
expect(global.electron.mixpanel.sendEvent).toHaveBeenCalledWith(
'Toggle openAtLogin',
{
component: 'general',
enabled: true,
}
)
})

it('syncs mixpanel config', () => {
expect(global.electron.mixpanel.syncConfig).toHaveBeenCalled()
})
})
})
17 changes: 15 additions & 2 deletions src/main/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import * as Store from 'electron-store'
import Store from 'electron-store'
import { sort as semverSort } from 'semver'
import { TypedStore } from '~/config/migrations/1.4.0'
import { TypedStore } from '~/config/migrations/1.5.0'

const schema: Store.Schema<TypedStore> = {
stopTimerOnSuspend: {
Expand All @@ -19,6 +19,9 @@ const schema: Store.Schema<TypedStore> = {
showMiniTimer: {
type: 'boolean',
},
openAtLogin: {
type: 'boolean',
},
}

const defaults: TypedStore = {
Expand All @@ -27,8 +30,18 @@ const defaults: TypedStore = {
remindTimerOnUnlocked: true,
alwaysOnTop: false,
showMiniTimer: true,
openAtLogin: true,
}

export const trackingConfigKeys: (keyof TypedStore)[] = [
'stopTimerOnSuspend',
'stopTimerOnShutdown',
'remindTimerOnUnlocked',
'alwaysOnTop',
'showMiniTimer',
'openAtLogin',
]

function getMigrationVersions(filePaths: string[]): string[] {
const versions = filePaths.map((filePath) => path.parse(filePath).name)
return semverSort(versions)
Expand Down
17 changes: 17 additions & 0 deletions src/main/config/migrations/1.5.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Conf from 'conf/dist/source'
import { TypedStore as PrevTypedStore } from './1.4.0'

export type TypedStore = {
stopTimerOnSuspend: boolean
stopTimerOnShutdown: boolean
remindTimerOnUnlocked: boolean
alwaysOnTop: boolean
showMiniTimer: boolean
openAtLogin: boolean
}

export const migration = (
store: Conf<TypedStore & Partial<PrevTypedStore>>
): void => {
store.set('openAtLogin', true)
}
12 changes: 12 additions & 0 deletions src/main/handlers/auto-launcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { app } from 'electron'
import { config } from '~/config'

async function syncEnabled() {
app.setLoginItemSettings({
openAtLogin: config.get('openAtLogin'),
})
}

app.on('ready', syncEnabled)

config.onDidChange('openAtLogin', syncEnabled)
10 changes: 2 additions & 8 deletions src/main/modules/mixpanel-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Mixpanel from 'mixpanel'
import { v4 as uuidv4 } from 'uuid'
import { config } from '../config'
import { trackingConfigKeys, config } from '~/config'

export class MixpanelClient {
private uuid: string
Expand Down Expand Up @@ -36,13 +36,7 @@ export class MixpanelClient {

public syncConfig(): void {
const props = {
...this.generateConfigProps([
'stopTimerOnSuspend',
'stopTimerOnShutdown',
'remindTimerOnUnlocked',
'alwaysOnTop',
'showMiniTimer',
]),
...this.generateConfigProps(trackingConfigKeys),
release: process.env.npm_package_version,
platform: process.platform,
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/universal-analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ua from 'universal-analytics'
import ua from 'universal-analytics'
import { v4 as uuidv4 } from 'uuid'

export function createVisitor(): ua.Visitor {
Expand Down
15 changes: 4 additions & 11 deletions src/main/preloads/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@ const namespace = 'config'
const prefix = createPrefixer(namespace)
const missingKeyError = new Error('Requested key is missing')

const readables = [
'stopTimerOnSuspend',
'stopTimerOnShutdown',
'remindTimerOnUnlocked',
'alwaysOnTop',
'showMiniTimer',
]

const settables = [
const accessibleKeys = [
'stopTimerOnSuspend',
'stopTimerOnShutdown',
'remindTimerOnUnlocked',
'alwaysOnTop',
'showMiniTimer',
'openAtLogin',
]

export const config = {
get(key: string): Promise<unknown> {
if (!readables.includes(key)) throw missingKeyError
if (!accessibleKeys.includes(key)) throw missingKeyError
return invoke(prefix('get'), key)
},
set(key: string, value: string): void {
if (!settables.includes(key)) throw missingKeyError
if (!accessibleKeys.includes(key)) throw missingKeyError
invoke(prefix('set'), key, value)
},
}
1 change: 1 addition & 0 deletions src/main/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"strict": true,
"typeRoots": ["./types"],
"types": ["node", "webpack-env"],
"esModuleInterop": true,
"paths": {
"~/*": ["./*"]
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/windows/mini-timer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserWindow } from 'electron'
import * as Positioner from 'electron-positioner'
import Positioner from 'electron-positioner'
import { getWindowUrl, buildWindowOptions } from '~/modules/window'

let window: BrowserWindow | undefined
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/assets/locales/pages/settings/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"stopTimerOnShutdown": "Stop a timer on shutdown",
"remindTimerOnUnlocked": "Show reminder notification on resumed",
"alwaysOnTop": "Keep the window always on top",
"showMiniTimer": "Show the timer at the bottom right of the screen"
"showMiniTimer": "Show the timer at the bottom right of the screen",
"openAtLogin": "Open the app at login"
},
"ja": {
"title": "一般",
"stopTimerOnSuspend": "PCのスリープ時に計測を停止",
"stopTimerOnShutdown": "PCのシャットダウン時に計測を停止",
"remindTimerOnUnlocked": "PCの再開時に計測のリマインドを通知",
"alwaysOnTop": "ウィンドウを最前面に表示",
"showMiniTimer": "画面右下に経過時間を表示"
"showMiniTimer": "画面右下に経過時間を表示",
"openAtLogin": "ログイン時にアプリを自動的に起動"
}
}
10 changes: 10 additions & 0 deletions src/renderer/pages/settings/general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
/>{{ $t('showMiniTimer') }}
<text-label class="purple">BETA</text-label>
</label>
<label>
<input
:checked="openAtLogin"
data-test-id="open-at-login"
type="checkbox"
@click="toggleChecked('openAtLogin')"
/>{{ $t('openAtLogin') }}
</label>
</div>
</section>
</template>
Expand All @@ -67,6 +75,7 @@ export default {
remindTimerOnUnlocked: false,
alwaysOnTop: false,
showMiniTimer: false,
openAtLogin: false,
}
},
async mounted() {
Expand All @@ -77,6 +86,7 @@ export default {
)
this.alwaysOnTop = await electron.config.get('alwaysOnTop')
this.showMiniTimer = await electron.config.get('showMiniTimer')
this.openAtLogin = await electron.config.get('openAtLogin')
},
methods: {
toggleChecked(key) {
Expand Down