|
1 | 1 | <script lang="ts">
|
| 2 | + import { SETTINGS_SERVICE } from '$lib/config/appSettingsV2'; |
2 | 3 | import { GIT_CONFIG_SERVICE } from '$lib/config/gitConfigService';
|
3 | 4 | import { inject } from '@gitbutler/core/context';
|
4 |
| - import { Link, SectionCard, Toggle } from '@gitbutler/ui'; |
| 5 | + import { Link, SectionCard, Toggle, Select, SelectItem } from '@gitbutler/ui'; |
5 | 6 | import { onMount } from 'svelte';
|
6 | 7 |
|
7 | 8 | const gitConfig = inject(GIT_CONFIG_SERVICE);
|
| 9 | + const settingsService = inject(SETTINGS_SERVICE); |
| 10 | + const settings = settingsService.appSettings; |
8 | 11 |
|
9 | 12 | let annotateCommits = $state(true);
|
| 13 | + let fetchFrequency = $state<number>(-1); |
| 14 | +
|
| 15 | + const fetchFrequencyOptions = [ |
| 16 | + { label: '1 minute', value: '1', minutes: 1 }, |
| 17 | + { label: '5 minutes', value: '5', minutes: 5 }, |
| 18 | + { label: '10 minutes', value: '10', minutes: 10 }, |
| 19 | + { label: '15 minutes', value: '15', minutes: 15 }, |
| 20 | + { label: 'None', value: 'none', minutes: -1 } |
| 21 | + ] as const; |
10 | 22 |
|
11 | 23 | function toggleCommitterSigning() {
|
12 | 24 | annotateCommits = !annotateCommits;
|
13 | 25 | gitConfig.set('gitbutler.gitbutlerCommitter', annotateCommits ? '1' : '0');
|
14 | 26 | }
|
15 | 27 |
|
| 28 | + async function updateFetchFrequency(value: string) { |
| 29 | + const option = fetchFrequencyOptions.find((opt) => opt.value === value); |
| 30 | + if (option) { |
| 31 | + fetchFrequency = option.minutes; |
| 32 | + await settingsService.updateFetch({ autoFetchIntervalMinutes: option.minutes }); |
| 33 | + } |
| 34 | + } |
| 35 | +
|
| 36 | + const selectedValue = $derived( |
| 37 | + fetchFrequencyOptions.find((opt) => opt.minutes === fetchFrequency)?.value ?? 'none' |
| 38 | + ); |
| 39 | +
|
16 | 40 | onMount(async () => {
|
17 | 41 | annotateCommits = (await gitConfig.get('gitbutler.gitbutlerCommitter')) === '1';
|
18 | 42 | });
|
| 43 | +
|
| 44 | + $effect(() => { |
| 45 | + if ($settings?.fetch) { |
| 46 | + fetchFrequency = $settings.fetch.autoFetchIntervalMinutes; |
| 47 | + } |
| 48 | + }); |
19 | 49 | </script>
|
20 | 50 |
|
21 | 51 | <SectionCard labelFor="committerSigning" orientation="row">
|
|
37 | 67 | <Toggle id="committerSigning" checked={annotateCommits} onclick={toggleCommitterSigning} />
|
38 | 68 | {/snippet}
|
39 | 69 | </SectionCard>
|
| 70 | + |
| 71 | +<SectionCard labelFor="fetchFrequency" orientation="row" centerAlign> |
| 72 | + {#snippet title()} |
| 73 | + Auto-fetch frequency |
| 74 | + {/snippet} |
| 75 | + {#snippet actions()} |
| 76 | + <Select |
| 77 | + id="fetchFrequency" |
| 78 | + options={fetchFrequencyOptions} |
| 79 | + value={selectedValue} |
| 80 | + onselect={updateFetchFrequency} |
| 81 | + > |
| 82 | + {#snippet itemSnippet({ item, highlighted })} |
| 83 | + <SelectItem selected={item.value === selectedValue} {highlighted}> |
| 84 | + {item.label} |
| 85 | + </SelectItem> |
| 86 | + {/snippet} |
| 87 | + </Select> |
| 88 | + {/snippet} |
| 89 | +</SectionCard> |
0 commit comments