diff options
Diffstat (limited to 'packages/main/src/controllers')
3 files changed, 33 insertions, 16 deletions
diff --git a/packages/main/src/controllers/__tests__/initConfig.spec.ts b/packages/main/src/controllers/__tests__/initConfig.spec.ts index e386a07..7b6d6ab 100644 --- a/packages/main/src/controllers/__tests__/initConfig.spec.ts +++ b/packages/main/src/controllers/__tests__/initConfig.spec.ts | |||
@@ -60,8 +60,12 @@ describe('when initializing', () => { | |||
60 | }); | 60 | }); |
61 | 61 | ||
62 | it('should bail if there is an an error creating the config file', async () => { | 62 | it('should bail if there is an an error creating the config file', async () => { |
63 | mocked(persistenceService.writeConfig).mockRejectedValue(new Error('boo')); | 63 | mocked(persistenceService.writeConfig).mockRejectedValue( |
64 | await expect(() => initConfig(config, persistenceService)).rejects.toBeInstanceOf(Error); | 64 | new Error('boo'), |
65 | ); | ||
66 | await expect(() => | ||
67 | initConfig(config, persistenceService), | ||
68 | ).rejects.toBeInstanceOf(Error); | ||
65 | }); | 69 | }); |
66 | }); | 70 | }); |
67 | 71 | ||
@@ -85,7 +89,9 @@ describe('when initializing', () => { | |||
85 | mocked(persistenceService.watchConfig).mockImplementationOnce(() => { | 89 | mocked(persistenceService.watchConfig).mockImplementationOnce(() => { |
86 | throw new Error('boo'); | 90 | throw new Error('boo'); |
87 | }); | 91 | }); |
88 | await expect(() => initConfig(config, persistenceService)).rejects.toBeInstanceOf(Error); | 92 | await expect(() => |
93 | initConfig(config, persistenceService), | ||
94 | ).rejects.toBeInstanceOf(Error); | ||
89 | }); | 95 | }); |
90 | }); | 96 | }); |
91 | 97 | ||
@@ -102,7 +108,9 @@ describe('when initializing', () => { | |||
102 | 108 | ||
103 | it('should bail if it cannot determine whether there is a config file', async () => { | 109 | it('should bail if it cannot determine whether there is a config file', async () => { |
104 | mocked(persistenceService.readConfig).mockRejectedValue(new Error('boo')); | 110 | mocked(persistenceService.readConfig).mockRejectedValue(new Error('boo')); |
105 | await expect(() => initConfig(config, persistenceService)).rejects.toBeInstanceOf(Error); | 111 | await expect(() => |
112 | initConfig(config, persistenceService), | ||
113 | ).rejects.toBeInstanceOf(Error); | ||
106 | }); | 114 | }); |
107 | }); | 115 | }); |
108 | 116 | ||
@@ -118,7 +126,9 @@ describe('when it has loaded the config', () => { | |||
118 | }); | 126 | }); |
119 | mocked(persistenceService.watchConfig).mockReturnValueOnce(watcherDisposer); | 127 | mocked(persistenceService.watchConfig).mockReturnValueOnce(watcherDisposer); |
120 | sutDisposer = await initConfig(config, persistenceService, throttleMs); | 128 | sutDisposer = await initConfig(config, persistenceService, throttleMs); |
121 | [[configChangedCallback]] = mocked(persistenceService.watchConfig).mock.calls; | 129 | [[configChangedCallback]] = mocked( |
130 | persistenceService.watchConfig, | ||
131 | ).mock.calls; | ||
122 | jest.resetAllMocks(); | 132 | jest.resetAllMocks(); |
123 | }); | 133 | }); |
124 | 134 | ||
diff --git a/packages/main/src/controllers/__tests__/initNativeTheme.spec.ts b/packages/main/src/controllers/__tests__/initNativeTheme.spec.ts index bd33f48..d4068af 100644 --- a/packages/main/src/controllers/__tests__/initNativeTheme.spec.ts +++ b/packages/main/src/controllers/__tests__/initNativeTheme.spec.ts | |||
@@ -58,14 +58,18 @@ it('should synchronize themeSource changes to the nativeTheme', () => { | |||
58 | }); | 58 | }); |
59 | 59 | ||
60 | it('should synchronize shouldUseDarkColors changes to the store', () => { | 60 | it('should synchronize shouldUseDarkColors changes to the store', () => { |
61 | const listener = mocked(nativeTheme.on).mock.calls.find(([event]) => event === 'updated')![1]; | 61 | const listener = mocked(nativeTheme.on).mock.calls.find( |
62 | ([event]) => event === 'updated', | ||
63 | )![1]; | ||
62 | shouldUseDarkColors = true; | 64 | shouldUseDarkColors = true; |
63 | listener(); | 65 | listener(); |
64 | expect(store.shared.shouldUseDarkColors).toBe(true); | 66 | expect(store.shared.shouldUseDarkColors).toBe(true); |
65 | }); | 67 | }); |
66 | 68 | ||
67 | it('should remove the listener on dispose', () => { | 69 | it('should remove the listener on dispose', () => { |
68 | const listener = mocked(nativeTheme.on).mock.calls.find(([event]) => event === 'updated')![1]; | 70 | const listener = mocked(nativeTheme.on).mock.calls.find( |
71 | ([event]) => event === 'updated', | ||
72 | )![1]; | ||
69 | disposeSut(); | 73 | disposeSut(); |
70 | expect(nativeTheme.off).toBeCalledWith('updated', listener); | 74 | expect(nativeTheme.off).toBeCalledWith('updated', listener); |
71 | }); | 75 | }); |
diff --git a/packages/main/src/controllers/initConfig.ts b/packages/main/src/controllers/initConfig.ts index 1d40762..e83b8da 100644 --- a/packages/main/src/controllers/initConfig.ts +++ b/packages/main/src/controllers/initConfig.ts | |||
@@ -59,20 +59,23 @@ export default async function initConfig( | |||
59 | lastSnapshotOnDisk = snapshot; | 59 | lastSnapshotOnDisk = snapshot; |
60 | } | 60 | } |
61 | 61 | ||
62 | if (!await readConfig()) { | 62 | if (!(await readConfig())) { |
63 | log.info('Config file was not found'); | 63 | log.info('Config file was not found'); |
64 | await writeConfig(); | 64 | await writeConfig(); |
65 | log.info('Created config file'); | 65 | log.info('Created config file'); |
66 | } | 66 | } |
67 | 67 | ||
68 | const disposeOnSnapshot = onSnapshot(config, debounce((snapshot) => { | 68 | const disposeOnSnapshot = onSnapshot( |
69 | // We can compare snapshots by reference, since it is only recreated on store changes. | 69 | config, |
70 | if (lastSnapshotOnDisk !== snapshot) { | 70 | debounce((snapshot) => { |
71 | writeConfig().catch((err) => { | 71 | // We can compare snapshots by reference, since it is only recreated on store changes. |
72 | log.error('Failed to write config on config change', err); | 72 | if (lastSnapshotOnDisk !== snapshot) { |
73 | }); | 73 | writeConfig().catch((err) => { |
74 | } | 74 | log.error('Failed to write config on config change', err); |
75 | }, debounceTime)); | 75 | }); |
76 | } | ||
77 | }, debounceTime), | ||
78 | ); | ||
76 | 79 | ||
77 | const disposeWatcher = persistenceService.watchConfig(async () => { | 80 | const disposeWatcher = persistenceService.watchConfig(async () => { |
78 | try { | 81 | try { |