Skip to content

Commit

Permalink
Settings: User can change the max count of tab at startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kisspeace committed Jul 1, 2023
1 parent d6a65ea commit 44475d1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
15 changes: 15 additions & 0 deletions source/NsfwBox.Settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ TNsfwBoxSettings = class
{$ENDIF}
FDownloadAllMode: TDownloadAllMode;
FBookmarksOrder: TBookmarksOrderList;
FMaxTabsAtStartup: integer;
private
procedure SetF<T>(var AVariable: T; const ANewValue: T);
procedure GetF<T>(var AVariable: T; out AOut: T);
Expand Down Expand Up @@ -178,6 +179,8 @@ TNsfwBoxSettings = class
{$ENDIF}
function GetAttribute(AName: string): variant;
procedure SetAttribute(AName: string; const Value: variant);
function GetMaxTabsAtStartup: integer;
procedure SetMaxTabsAtStartup(const Value: integer);
public
property SemVer: TSemVer read GetSemVer write SetSemVer;
property DefaultUseragent: string read GetDefaultUseragent write SetDefaultUseragent;
Expand Down Expand Up @@ -216,6 +219,7 @@ TNsfwBoxSettings = class
property PlayExterWhenCantInter: boolean read GetPlayExterWhenCantInter write SetPlayExterWhenCantInter;
property DefaultBackupPath: string read GetDefaultBackupPath write SetDefaultBackupPath;
property DownloadAllMode: TDownloadAllMode read GetDownloadAllMode write SetDownloadAllMode;
property MaxTabsAtStartup: integer read GetMaxTabsAtStartup write SetMaxTabsAtStartup;
{$IFDEF MSWINDOWS}
property UseNewAppTitlebar: boolean read GetUseNewAppTitlebar write SetUseNewAppTitlebar;
property ContentPlayApp: string read GetContentPlayApp write SetContentPlayApp;
Expand Down Expand Up @@ -318,6 +322,7 @@ constructor TNsfwBoxSettings.Create;
FYDWSyncLoadFromFile := False;
FBookmarksOrder := TBookmarksOrderList.Create;
FDownloadAllMode := TDownloadAllMode.damHighResVersion;
FMaxTabsAtStartup := 100;
end;

destructor TNsfwBoxSettings.Destroy;
Expand Down Expand Up @@ -513,6 +518,11 @@ function TNsfwBoxSettings.GetMaxDownloadThreads: integer;
GetF<integer>(FMaxDownloadThreads, Result);
end;

function TNsfwBoxSettings.GetMaxTabsAtStartup: integer;
begin
GetF<integer>(FMaxTabsAtStartup, Result);
end;

function TNsfwBoxSettings.GetPlayExterWhenCantInter: boolean;
begin
GetF<boolean>(FPlayExterWhenCantInter, Result);
Expand Down Expand Up @@ -752,6 +762,11 @@ procedure TNsfwBoxSettings.SetMaxDownloadThreads(const Value: integer);
SetF<integer>(FMaxDownloadThreads, Value);
end;

procedure TNsfwBoxSettings.SetMaxTabsAtStartup(const Value: integer);
begin
SetF<integer>(FMaxTabsAtStartup, Value);
end;

procedure TNsfwBoxSettings.SetPlayExterWhenCantInter(const Value: boolean);
begin
SetF<boolean>(FPlayExterWhenCantInter, Value);
Expand Down
61 changes: 40 additions & 21 deletions source/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,8 @@ procedure TForm1.FormCreate(Sender: TObject);

if (Settings.SemVer < TSemVer.Create(3, 0, 0)) then
Settings.DefaultBackupPath := TNBoxPath.GetDefaultBackupPath;
if (Settings.SemVer < TSemVer.Create(3, 2, 0)) then
Settings.MaxTabsAtStartup := 100;
SaveSettings;
end;
end;
Expand Down Expand Up @@ -2826,6 +2828,7 @@ procedure TForm1.FormCreate(Sender: TObject);
CheckSetAutoAcceptAllCertificates := AddSettingsCheck('Accept all SSL\TLS certificates', 'AutoAcceptAllCertificates'); { issues on ANDROID }
CheckSetEnableAllContent := AddSettingsCheck('Enable all content (Gelbooru)', 'EnableAllContent');
CheckSetAutoSaveSession := AddSettingsCheck('Auto save session', 'AutoSaveSession');
AddSettingsEdit('Max tabs count at startup', 'MaxTabsAtStartup', '', EDIT_STYLE_INT);
CheckSetSaveSearchHistory := AddSettingsCheck('Save search history', 'SaveSearchHistory');
CheckSetSaveDownloadHistory := AddSettingsCheck('Save download history', 'SaveDownloadHistory');
CheckSetSaveTapHistory := AddSettingsCheck('Save tap history', 'SaveTapHistory');
Expand Down Expand Up @@ -4146,53 +4149,69 @@ function TForm1.LoadSession: boolean;
LBookmarks: TBookmarkAr;
LBookmark: TNBoxBookmark;
I: integer;
LPage: integer;
LTab: TNBoxTab;
LHitLimit: boolean;
begin
Result := false;
NowLoadingSession := true;
Result := False;
LHitLimit := False;
NowLoadingSession := True;
try
try
Groups := Session.GetBookmarksGroups;
if Length(Groups) < 1 then
exit;

Group := Groups[0];
LBookmarks := Group.GetPage;
for I := High(LBookmarks) Downto Low(LBookmarks) do
begin
LBookmark := LBookmarks[I];
LPage := Group.GetMaxPage;
if LPage = 0 then Exit;
repeat
LBookmarks := Group.GetPage(LPage);
if (not Result) and (Length(LBookmarks) > 0) then
Result := True;

for I := High(LBookmarks) downto Low(LBookmarks) do
begin
if Tabs.Count >= Settings.MaxTabsAtStartup then
begin
LHitLimit := True;
Break;
end;

if not ( LBookmark.BookmarkType = SearchRequest ) then
continue;
LBookmark := LBookmarks[I];
if not (LBookmark.BookmarkType = SearchRequest) then
continue;

try
var LReq := LBookmark.AsRequest;
AddBrowser(LReq);
LTab := AddBrowser(LReq);
Browsers.Last.Tag := LBookmark.Id;
LReq := Nil;
except
On E: Exception do Log('LoadSession addBrowser', E);
end;

try
LReq := Nil;
LBookmarks[I] := Nil;
LBookmark.FreeObj;
FreeAndNil(LBookmark);
except
On E: Exception do Log('LoadSession free item', E);
end;
Dec(LPage);
until (LPage <= 0) or (LHitLimit);

{ Free garbage }
if LHitLimit then
begin
For I := I downto Low(LBookmarks) do
begin
LBookmarks[I].FreeObj;
FreeAndNil(LBookmarks[I]);
end;
end;

if Length(LBookmarks) > 0 then
Result := true;
except
On E: Exception do begin
Log('LoadSession', E);
Result := false;
Result := False;
end;
end;
finally
NowLoadingSession := false;
NowLoadingSession := False;
end;
end;

Expand Down

0 comments on commit 44475d1

Please sign in to comment.