fix: Add a message about permissions command on startup in untrusted … (#10755)

This commit is contained in:
shrutip90
2025-10-08 22:17:58 -07:00
committed by GitHub
parent 3d24575239
commit a044c25981
3 changed files with 46 additions and 12 deletions
+16 -2
View File
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { useState, useCallback, useEffect } from 'react';
import { useState, useCallback, useEffect, useRef } from 'react';
import type { LoadedSettings } from '../../config/settings.js';
import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
import {
@@ -13,14 +13,17 @@ import {
isWorkspaceTrusted,
} from '../../config/trustedFolders.js';
import * as process from 'node:process';
import { type HistoryItemWithoutId, MessageType } from '../types.js';
export const useFolderTrust = (
settings: LoadedSettings,
onTrustChange: (isTrusted: boolean | undefined) => void,
addItem: (item: HistoryItemWithoutId, timestamp: number) => number,
) => {
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
const [isRestarting, setIsRestarting] = useState(false);
const startupMessageSent = useRef(false);
const folderTrust = settings.merged.security?.folderTrust?.enabled;
@@ -29,7 +32,18 @@ export const useFolderTrust = (
setIsTrusted(trusted);
setIsFolderTrustDialogOpen(trusted === undefined);
onTrustChange(trusted);
}, [folderTrust, onTrustChange, settings.merged]);
if (trusted === false && !startupMessageSent.current) {
addItem(
{
type: MessageType.INFO,
text: 'This folder is not trusted. Some features may be disabled. Use the `/permissions` command to change the trust level.',
},
Date.now(),
);
startupMessageSent.current = true;
}
}, [folderTrust, onTrustChange, settings.merged, addItem]);
const handleFolderTrustSelect = useCallback(
(choice: FolderTrustChoice) => {