Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 6d184f0

Browse files
committed
Fix legacy patch fields overriding explicit backgroundActivity and extract duplicated settings utilities
- Fix applyServerSettingsPatch: skip legacy-derived backgroundActivityPatch when an explicit backgroundActivity object is present in the patch, preventing silent override of new-style patches by legacy fields. - Extract shared background activity utilities (BackgroundActivityOverridePatch, durationToSeconds, normalizeIntervalSeconds, backgroundActivityOverrideSettings, BackgroundPolicyTooltip) into backgroundActivityUtils.tsx to eliminate duplication between SettingsPanels.tsx and SourceControlSettings.tsx.
1 parent 038e209 commit 6d184f0

4 files changed

Lines changed: 99 additions & 139 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import{
22
ArchiveIcon,
33
ArchiveX,
4-
InfoIcon,
54
LoaderIcon,
65
PlusIcon,
76
RefreshCwIcon,
@@ -106,6 +105,12 @@ import {
106105
SettingsSection,
107106
useRelativeTimeTick,
108107
}from"./settingsLayout";
108+
import{
109+
BackgroundPolicyTooltipasPolicyTooltip,
110+
backgroundActivityOverrideSettings,
111+
durationToSeconds,
112+
normalizeIntervalSeconds,
113+
}from"./backgroundActivityUtils";
109114
import{ProjectFavicon}from"../ProjectFavicon";
110115
import{useServerObservability,useServerProviders}from"../../rpc/serverState";
111116

@@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, stri
137142
};
138143

139144
typeBackgroundActivityProfileOption=BackgroundActivityProfile|"advanced";
140-
typeBackgroundActivityOverridePatch=Partial<{
141-
[KinkeyofBackgroundActivitySettings["overrides"]]:
142-
|BackgroundActivitySettings["overrides"][K]
143-
|undefined;
144-
}>;
145145

146146
constBACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption,string>={
147147
...BACKGROUND_ACTIVITY_PROFILE_LABELS,
@@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
174174
{key: "pauseWhenOnBattery",label: "Pause on battery"},
175175
];
176176

177-
functiondurationToSeconds(duration: Duration.Duration): number{
178-
returnMath.round(Duration.toMillis(duration)/1_000);
179-
}
180-
181-
functionnormalizeIntervalSeconds(value: number|null): number{
182-
if(value===null||!Number.isFinite(value)){
183-
return0;
184-
}
185-
returnMath.max(0,Math.round(value));
186-
}
187-
188177
functionresolveBackgroundActivityProfileOption(settings: {
189178
readonlybackgroundActivity: BackgroundActivitySettings;
190179
}): BackgroundActivityProfileOption{
@@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
209198
};
210199
}
211200

212-
functionbackgroundActivityOverrideSettings(
213-
current: BackgroundActivitySettings,
214-
overrides: BackgroundActivityOverridePatch,
215-
){
216-
constnextOverrides: BackgroundActivityOverridePatch={
217-
...current.overrides,
218-
...overrides,
219-
};
220-
for(const[key,value]ofObject.entries(nextOverrides)){
221-
if(value===undefined){
222-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
223-
}
224-
}
225-
return{
226-
backgroundActivity: {
227-
schemaVersion: 1asconst,
228-
profile: "custom"asconst,
229-
baseProfile: getBackgroundActivityBaseProfile(current),
230-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
231-
},
232-
};
233-
}
234-
235-
functionPolicyTooltip({ children }: {readonlychildren: string}){
236-
return(
237-
<Tooltip>
238-
<TooltipTrigger
239-
render={
240-
<button
241-
type="button"
242-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
243-
aria-label="Background policy details"
244-
>
245-
<InfoIconclassName="size-3.5"/>
246-
</button>
247-
}
248-
/>
249-
<TooltipPopupside="top"className="max-w-72">
250-
{children}
251-
</TooltipPopup>
252-
</Tooltip>
253-
);
254-
}
255-
256201
functionwithoutProviderInstanceKey<V>(
257202
record: Readonly<Record<ProviderInstanceId,V>>|undefined,
258203
key: ProviderInstanceId,

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import{ChevronDownIcon,GitPullRequestIcon,InfoIcon,RefreshCwIcon}from"lucide-react";
1+
import{ChevronDownIcon,GitPullRequestIcon,RefreshCwIcon}from"lucide-react";
22
import*asDurationfrom"effect/Duration";
33
import*asOptionfrom"effect/Option";
44
import{useState,typeReactNode}from"react";
55
importtype{
6-
BackgroundActivitySettings,
76
SourceControlProviderKind,
87
SourceControlDiscoveryResult,
98
SourceControlProviderAuth,
@@ -55,6 +54,12 @@ import {
5554
}from"../Icons";
5655
import{RedactedSensitiveText}from"./RedactedSensitiveText";
5756
import{SettingResetButton,SettingsPageContainer,SettingsSection}from"./settingsLayout";
57+
import{
58+
BackgroundPolicyTooltip,
59+
backgroundActivityOverrideSettings,
60+
durationToSeconds,
61+
normalizeIntervalSecondsasnormalizeFetchIntervalSeconds,
62+
}from"./backgroundActivityUtils";
5863

5964
constEMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult={
6065
versionControlSystems: [],
@@ -75,43 +80,6 @@ const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {
7580

7681
constSOURCE_CONTROL_SKELETON_ROWS=["primary","secondary"]asconst;
7782
constGIT_FETCH_INTERVAL_STEP_SECONDS=5;
78-
typeBackgroundActivityOverridePatch=Partial<{
79-
[KinkeyofBackgroundActivitySettings["overrides"]]:
80-
|BackgroundActivitySettings["overrides"][K]
81-
|undefined;
82-
}>;
83-
84-
functiondurationToSeconds(duration: Duration.Duration): number{
85-
returnMath.round(Duration.toMillis(duration)/1_000);
86-
}
87-
88-
functionnormalizeFetchIntervalSeconds(value: number|null): number{
89-
if(value===null||!Number.isFinite(value)){
90-
return0;
91-
}
92-
returnMath.max(0,Math.round(value));
93-
}
94-
95-
functionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
96-
return(
97-
<Tooltip>
98-
<TooltipTrigger
99-
render={
100-
<button
101-
type="button"
102-
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
103-
aria-label="Background policy details"
104-
>
105-
<InfoIconclassName="size-3.5"/>
106-
</button>
107-
}
108-
/>
109-
<TooltipPopupside="top"className="max-w-72">
110-
{children}
111-
</TooltipPopup>
112-
</Tooltip>
113-
);
114-
}
11583

11684
functionoptionLabel(value: Option.Option<string>): string|null{
11785
returnOption.getOrNull(value);
@@ -335,28 +303,6 @@ function GitFetchIntervalSettings() {
335303
);
336304
constcanResetFetchInterval=
337305
automaticGitFetchIntervalSeconds!==defaultAutomaticGitFetchIntervalSeconds;
338-
constbackgroundActivityOverrideSettings=(
339-
current: BackgroundActivitySettings,
340-
overrides: BackgroundActivityOverridePatch,
341-
)=>{
342-
constnextOverrides: BackgroundActivityOverridePatch={
343-
...current.overrides,
344-
...overrides,
345-
};
346-
for(const[key,value]ofObject.entries(nextOverrides)){
347-
if(value===undefined){
348-
deletenextOverrides[keyaskeyoftypeofnextOverrides];
349-
}
350-
}
351-
return{
352-
backgroundActivity: {
353-
schemaVersion: 1asconst,
354-
profile: "custom"asconst,
355-
baseProfile: getBackgroundActivityBaseProfile(current),
356-
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
357-
},
358-
};
359-
};
360306

361307
return(
362308
<divclassName="grid gap-3">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import{InfoIcon}from"lucide-react";
2+
import*asDurationfrom"effect/Duration";
3+
importtype{BackgroundActivitySettings}from"@t3tools/contracts";
4+
import{getBackgroundActivityBaseProfile}from"@t3tools/shared/backgroundActivitySettings";
5+
6+
import{Tooltip,TooltipPopup,TooltipTrigger}from"../ui/tooltip";
7+
8+
exporttypeBackgroundActivityOverridePatch=Partial<{
9+
[KinkeyofBackgroundActivitySettings["overrides"]]:
10+
|BackgroundActivitySettings["overrides"][K]
11+
|undefined;
12+
}>;
13+
14+
exportfunctiondurationToSeconds(duration: Duration.Duration): number{
15+
returnMath.round(Duration.toMillis(duration)/1_000);
16+
}
17+
18+
exportfunctionnormalizeIntervalSeconds(value: number|null): number{
19+
if(value===null||!Number.isFinite(value)){
20+
return0;
21+
}
22+
returnMath.max(0,Math.round(value));
23+
}
24+
25+
exportfunctionbackgroundActivityOverrideSettings(
26+
current: BackgroundActivitySettings,
27+
overrides: BackgroundActivityOverridePatch,
28+
){
29+
constnextOverrides: BackgroundActivityOverridePatch={
30+
...current.overrides,
31+
...overrides,
32+
};
33+
for(const[key,value]ofObject.entries(nextOverrides)){
34+
if(value===undefined){
35+
deletenextOverrides[keyaskeyoftypeofnextOverrides];
36+
}
37+
}
38+
return{
39+
backgroundActivity: {
40+
schemaVersion: 1asconst,
41+
profile: "custom"asconst,
42+
baseProfile: getBackgroundActivityBaseProfile(current),
43+
overrides: nextOverridesasBackgroundActivitySettings["overrides"],
44+
},
45+
};
46+
}
47+
48+
exportfunctionBackgroundPolicyTooltip({ children }: {readonlychildren: string}){
49+
return(
50+
<Tooltip>
51+
<TooltipTrigger
52+
render={
53+
<button
54+
type="button"
55+
className="inline-flex size-5 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
56+
aria-label="Background policy details"
57+
>
58+
<InfoIconclassName="size-3.5"/>
59+
</button>
60+
}
61+
/>
62+
<TooltipPopupside="top"className="max-w-72">
63+
{children}
64+
</TooltipPopup>
65+
</Tooltip>
66+
);
67+
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ export function applyServerSettingsPatch(
8989
...patchForMerge
9090
}=patch;
9191
constbackgroundActivityPatch=
92-
backgroundActivityProfile!==undefined
93-
? {
94-
schemaVersion: 1asconst,
95-
profile: backgroundActivityProfile,
96-
overrides: {},
97-
}
98-
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
92+
backgroundActivity!==undefined
93+
? undefined
94+
: backgroundActivityProfile!==undefined
9995
? {
10096
schemaVersion: 1asconst,
101-
profile: "custom"asconst,
102-
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
103-
overrides: {
104-
...current.backgroundActivity.overrides,
105-
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
106-
...(providerHealthRefreshInterval!==undefined
107-
? { providerHealthRefreshInterval }
108-
: {}),
109-
},
97+
profile: backgroundActivityProfile,
98+
overrides: {},
11099
}
111-
: undefined;
100+
: automaticGitFetchInterval!==undefined||providerHealthRefreshInterval!==undefined
101+
? {
102+
schemaVersion: 1asconst,
103+
profile: "custom"asconst,
104+
baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity),
105+
overrides: {
106+
...current.backgroundActivity.overrides,
107+
...(automaticGitFetchInterval!==undefined ? { automaticGitFetchInterval } : {}),
108+
...(providerHealthRefreshInterval!==undefined
109+
? { providerHealthRefreshInterval }
110+
: {}),
111+
},
112+
}
113+
: undefined;
112114
constnext=deepMerge(current,patchForMerge);
113115
constnextWithReplacementsBase={
114116
...next,

0 commit comments

Comments
 (0)