ADD: check if Full Disk Access permission has been granted, if so hide the Privilege Button on the ToolBar

This commit is contained in:
rich2014 2026-06-02 12:11:27 +08:00
commit a62f046a94
3 changed files with 41 additions and 7 deletions

View file

@ -225,7 +225,9 @@ begin
InitPasswordStore;
LoadPixMapManager;
{$IF DEFINED(DARWIN)}
initCocoaModernFormConfig;
{$if NOT defined(DisableCocoaModernForm)}
TDCCocoaModernFormUtils.initConfig;
{$endif}
iCloudDriveConfigUtil.load;
{$ENDIF}
Application.CreateForm(TfrmMain, frmMain); // main form

View file

@ -972,6 +972,9 @@ uses
uColumnsFileView, dmHigh, uFileSourceOperationMisc
{$IFDEF MSWINDOWS}
, uShellFileSource, uNetworkThread
{$ENDIF}
{$IFDEF DARWIN}
, uCocoaModernFormConfig
{$ENDIF}
;
@ -1270,6 +1273,9 @@ begin
TDarwinFileViewUtil.init( @ActiveNotebook, @ActiveFrame );
if gForceFunctionKey then
Application.OnIdle:= @installMacOSFNKeyTap;
{$if NOT defined(DisableCocoaModernForm)}
TDCCocoaModernFormUtils.checkAndSetPrivilegeItem;
{$endif}
{$ENDIF}
end;

View file

@ -18,7 +18,15 @@ uses
CocoaAll, CocoaConfig, CocoaToolBar, CocoaThemes, Cocoa_Extra,
LResources, uTranslator, Translations;
procedure initCocoaModernFormConfig;
type
{ TDCCocoaModernFormUtils }
TDCCocoaModernFormUtils = class
class procedure initConfig;
class function isEnabled: Boolean;
class procedure checkAndSetPrivilegeItem;
end;
implementation
@ -108,12 +116,9 @@ begin
];
end;
procedure initCocoaModernFormConfig;
class procedure TDCCocoaModernFormUtils.initConfig;
begin
if gModernUI = false then
Exit;
if NSAppKitVersionNumber < NSAppKitVersionNumber11_0 then
if NOT TDCCocoaModernFormUtils.isEnabled then
Exit;
fMain.onFileViewUpdated:= @onFileViewUpdated;
@ -122,5 +127,26 @@ begin
doInitConfig;
end;
class function TDCCocoaModernFormUtils.isEnabled: Boolean;
begin
Result:= gModernUI and TDarwinApplicationUtil.supportsModernForm;
end;
class procedure TDCCocoaModernFormUtils.checkAndSetPrivilegeItem;
var
toolBar: NSToolBar;
index: Integer;
begin
if NOT TDCCocoaModernFormUtils.isEnabled then
Exit;
if NOT TDarwinApplicationUtil.hasFullDiskAccess then
Exit;
toolBar:= TCocoaToolBarUtils.getToolBar( frmMain );
index:= TCocoaToolBarUtils.findItemIndexByIdentifier( toolBar, 'MainForm.Privilege' );
TCocoaToolBarUtils.removeItemByIndex( toolBar, index );
end;
end.