Skip to content

Commit 4db3c35

Browse files
Merge pull request #10537 from gitbutlerapp/setting-for-polling-frequency
Setting polling frequency
2 parents f6a0c49 + 9ddab59 commit 4db3c35

File tree

7 files changed

+121
-3
lines changed

7 files changed

+121
-3
lines changed

apps/desktop/src/components/profileSettings/GitSettings.svelte

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
<script lang="ts">
2+
import { SETTINGS_SERVICE } from '$lib/config/appSettingsV2';
23
import { GIT_CONFIG_SERVICE } from '$lib/config/gitConfigService';
34
import { inject } from '@gitbutler/core/context';
4-
import { Link, SectionCard, Toggle } from '@gitbutler/ui';
5+
import { Link, SectionCard, Toggle, Select, SelectItem } from '@gitbutler/ui';
56
import { onMount } from 'svelte';
67
78
const gitConfig = inject(GIT_CONFIG_SERVICE);
9+
const settingsService = inject(SETTINGS_SERVICE);
10+
const settings = settingsService.appSettings;
811
912
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;
1022
1123
function toggleCommitterSigning() {
1224
annotateCommits = !annotateCommits;
1325
gitConfig.set('gitbutler.gitbutlerCommitter', annotateCommits ? '1' : '0');
1426
}
1527
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+
1640
onMount(async () => {
1741
annotateCommits = (await gitConfig.get('gitbutler.gitbutlerCommitter')) === '1';
1842
});
43+
44+
$effect(() => {
45+
if ($settings?.fetch) {
46+
fetchFrequency = $settings.fetch.autoFetchIntervalMinutes;
47+
}
48+
});
1949
</script>
2050

2151
<SectionCard labelFor="committerSigning" orientation="row">
@@ -37,3 +67,23 @@
3767
<Toggle id="committerSigning" checked={annotateCommits} onclick={toggleCommitterSigning} />
3868
{/snippet}
3969
</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>

apps/desktop/src/lib/config/appSettingsV2.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export class SettingsService {
6363
await this.backend.invoke('update_reviews', { update });
6464
}
6565

66+
async updateFetch(update: Partial<Fetch>) {
67+
await this.backend.invoke('update_fetch', { update });
68+
}
69+
6670
private async nudge(): Promise<void> {
6771
await this.autoOptInWs3();
6872
await this.autoOptInRules();

crates/but-api/src/commands/settings.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! In place of commands.rs
22
use but_api_macros::api_cmd;
3-
use but_settings::api::{ClaudeUpdate, FeatureFlagsUpdate, ReviewsUpdate, TelemetryUpdate};
3+
use but_settings::api::{
4+
ClaudeUpdate, FeatureFlagsUpdate, FetchUpdate, ReviewsUpdate, TelemetryUpdate,
5+
};
46
use but_settings::{AppSettings, AppSettingsWithDiskSync};
57
use serde::Deserialize;
68
use tracing::instrument;
@@ -104,3 +106,18 @@ pub fn update_reviews(
104106
.update_reviews(params.update)
105107
.map_err(|e| e.into())
106108
}
109+
110+
#[derive(Deserialize)]
111+
#[serde(rename_all = "camelCase")]
112+
pub struct UpdateFetchParams {
113+
pub update: FetchUpdate,
114+
}
115+
116+
pub fn update_fetch(
117+
app_settings_sync: &AppSettingsWithDiskSync,
118+
params: UpdateFetchParams,
119+
) -> Result<(), Error> {
120+
app_settings_sync
121+
.update_fetch(params.update)
122+
.map_err(|e| e.into())
123+
}

crates/but-server/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ async fn handle_command(
221221
.and_then(|params| {
222222
settings::update_claude(&app_settings_sync, params).map(|r| json!(r))
223223
}),
224+
"update_fetch" => serde_json::from_value(request.params)
225+
.to_error()
226+
.and_then(|params| {
227+
settings::update_fetch(&app_settings_sync, params).map(|r| json!(r))
228+
}),
229+
"update_reviews" => serde_json::from_value(request.params)
230+
.to_error()
231+
.and_then(|params| {
232+
settings::update_reviews(&app_settings_sync, params).map(|r| json!(r))
233+
}),
224234
// Secret management
225235
"secret_get_global" => secret::secret_get_global_cmd(request.params),
226236
"secret_set_global" => secret::secret_set_global_cmd(request.params),

crates/but-settings/src/api.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ pub struct ReviewsUpdate {
4242
pub auto_fill_pr_description_from_commit: Option<bool>,
4343
}
4444

45+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
46+
#[serde(rename_all = "camelCase")]
47+
/// Update request for [`crate::app_settings::Fetch`].
48+
pub struct FetchUpdate {
49+
pub auto_fetch_interval_minutes: Option<isize>,
50+
}
51+
4552
/// Mutation, immediately followed by writing everything to disk.
4653
impl AppSettingsWithDiskSync {
4754
pub fn update_onboarding_complete(&self, update: bool) -> Result<()> {
@@ -136,4 +143,12 @@ impl AppSettingsWithDiskSync {
136143
}
137144
settings.save()
138145
}
146+
147+
pub fn update_fetch(&self, update: FetchUpdate) -> Result<()> {
148+
let mut settings = self.get_mut_enforce_save()?;
149+
if let Some(auto_fetch_interval_minutes) = update.auto_fetch_interval_minutes {
150+
settings.fetch.auto_fetch_interval_minutes = auto_fetch_interval_minutes;
151+
}
152+
settings.save()
153+
}
139154
}

crates/gitbutler-tauri/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ fn main() {
307307
settings::update_feature_flags,
308308
settings::update_telemetry_distinct_id,
309309
settings::update_claude,
310+
settings::update_fetch,
311+
settings::update_reviews,
310312
action::list_actions,
311313
action::handle_changes,
312314
action::list_workflows,

crates/gitbutler-tauri/src/settings.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(deprecated)]
22
use but_api::commands::settings;
3-
use but_settings::api::{ClaudeUpdate, FeatureFlagsUpdate, TelemetryUpdate};
3+
use but_settings::api::{
4+
ClaudeUpdate, FeatureFlagsUpdate, FetchUpdate, ReviewsUpdate, TelemetryUpdate,
5+
};
46
use but_settings::AppSettingsWithDiskSync;
57
use tauri::State;
68
use tracing::instrument;
@@ -63,3 +65,21 @@ pub fn update_claude(
6365
) -> Result<(), Error> {
6466
settings::update_claude(&app_settings_sync, settings::UpdateClaudeParams { update })
6567
}
68+
69+
#[tauri::command(async)]
70+
#[instrument(skip(app_settings_sync), err(Debug))]
71+
pub fn update_fetch(
72+
app_settings_sync: State<'_, AppSettingsWithDiskSync>,
73+
update: FetchUpdate,
74+
) -> Result<(), Error> {
75+
settings::update_fetch(&app_settings_sync, settings::UpdateFetchParams { update })
76+
}
77+
78+
#[tauri::command(async)]
79+
#[instrument(skip(app_settings_sync), err(Debug))]
80+
pub fn update_reviews(
81+
app_settings_sync: State<'_, AppSettingsWithDiskSync>,
82+
update: ReviewsUpdate,
83+
) -> Result<(), Error> {
84+
settings::update_reviews(&app_settings_sync, settings::UpdateReviewsParams { update })
85+
}

0 commit comments

Comments
 (0)