-
Notifications
You must be signed in to change notification settings - Fork 6
/
menu.pas
1139 lines (1008 loc) · 32.6 KB
/
menu.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
KNOWN BUGS: Sometimes closing a site the CardPanel activecard property fails
and might occur that switching to another site doesn't work well
until you create (open) a new site
}
unit menu;
interface
{.$I ProjectDefines.inc}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, Menus, StdCtrls, registry,
frmChatWebView, System.ImageList, Vcl.ImgList, VirtualDesktopManager,
AnyiQuack, AQPSystemTypesAnimations, uWVCoreWebView2Args,
Vcl.Imaging.pngimage, Skia, Skia.Vcl, Generics.Collections, Winapi.ShellAPI,
settingsHelper, JvComponentBase, JvAppHotKey, JvAppEvent, madExceptVcl,
System.Actions, Vcl.ActnList {$IFDEF EXPERIMENTAL} {$I experimental.uses.inc} {$IFEND};
const
APP_VERSION = '1.0.0';
type
TfrmMenu = class(TForm)
tmrMenu: TTimer;
pm1: TPopupMenu;
About1: TMenuItem;
Exit1: TMenuItem;
tmrHideMenu: TTimer;
tmrShowMenu: TTimer;
N2: TMenuItem;
ImageList1: TImageList;
imgMenu: TSkSvg;
pmCard: TPopupMenu;
pmCardCloseSite: TMenuItem;
Settings1: TMenuItem;
TrayIcon1: TTrayIcon;
JvApplicationHotKey1: TJvApplicationHotKey;
JvAppEvents1: TJvAppEvents;
AlternatURL1: TMenuItem;
MadExceptionHandler1: TMadExceptionHandler;
BalloonHint1: TBalloonHint;
askGPT1: TMenuItem;
JvApplicationHotKey2: TJvApplicationHotKey;
ActionList1: TActionList;
actSwitchAIChats: TAction;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure tmrMenuTimer(Sender: TObject);
procedure imgMenuClick(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure tmrHideMenuTimer(Sender: TObject);
procedure tmrShowMenuTimer(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure pmCardPopup(Sender: TObject);
procedure pmCardCloseSiteClick(Sender: TObject);
procedure Settings1Click(Sender: TObject);
procedure FormClick(Sender: TObject);
procedure pm1Popup(Sender: TObject);
procedure pm1Close(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure JvApplicationHotKey1HotKey(Sender: TObject);
procedure JvApplicationHotKey1HotKeyRegisterFailed(Sender: TObject;
var HotKey: TShortCut);
procedure JvAppEvents1Activate(Sender: TObject);
procedure pmCardClose(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure AlternatURL1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure askGPT1Click(Sender: TObject);
procedure JvApplicationHotKey2HotKeyRegisterFailed(Sender: TObject;
var HotKey: TShortCut);
procedure JvApplicationHotKey2HotKey(Sender: TObject);
procedure actSwitchAIChatsExecute(Sender: TObject);
// procedure FormPaint(Sender: TObject);
private
{ Private declarations }
FOnMenuArea: Boolean;
FCurrentPopupCardId: Integer;
FPopupMenuVisible: Boolean;
{$IFDEF EXPERIMENTAL}
{$I experimental.object.inc}
{$IFEND}
FHookWndHandle: THandle;
FHookMsg: Integer;
procedure CreateParams(var Params: TCreateParams); override;
procedure HideMenu(Sender: TObject);
procedure RestoreRequest(var message: TMessage); message WM_USER + $1000;
// restore after resolution change
procedure WMDisplayChange(var message: TMessage); message WM_DISPLAYCHANGE;
// windows session on end
procedure WMQueryEndSession(var message: TWMQueryEndSession); message WM_QUERYENDSESSION;
procedure WMEndSession(var message: TWMEndSession); message WM_ENDSESSION;
protected
procedure WMShellHook(var Msg: TMessage);
procedure WndMethod(var Msg: TMessage);
function IsStarteMenuVisible: Boolean;
procedure CurrentDesktopChanged(Sender: TObject; OldDesktop, NewDesktop: TVirtualDesktop);
procedure CurrentDesktopChangedW11(Sender: TObject; OldDesktop, NewDesktop: TVirtualDesktopW11);
public
{ Public declarations }
FFirstTimeBrowser: Boolean;
Settings: TSettings;
Icons: TObjectList<TSkSvg>;
PopupWindowRect: TRect;
// Menu's size
MenuTargetWidth: Integer;
MenuTargetHeight: Integer;
MenuTargetIconDimension: Integer;
MenuTargetIconSpan: Integer;
MenuMinWidth: Integer;
//constructor Create(AOwner: TComponent); override;
procedure buttonClick(btnID: Cardinal);
procedure ShowMenuAnimation(aLocation: Integer; aShow: Boolean = True; animated: Boolean = False);
procedure CreateNewCard(const aArgs : TCoreWebView2NewWindowRequestedEventArgs);
procedure CreateNewSite(Sender: TObject);
procedure SiteContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure IconMouseHover(Sender: TObject);
procedure FocusCurrentBrowser;
procedure SetDarkMode(Enable: Boolean = True);
procedure LoadSites;
property OnMenuArea: Boolean read FOnMenuArea write FOnMenuArea;
end;
var
frmMenu: TfrmMenu;
OriginalWorkArea: TRect;
frmMenuON: Boolean = False;
NewLeft, NewWidth: Integer;
NewAlphaBlend: Byte;
implementation
{$R *.dfm}
uses
functions,
Splash,
settings,
utils,
uBrowserCard,
ActiveX,
Vcl.Themes,
GDIPAPI, gdipobj, gdiputil, frmTaskGPT;
const
//https://stackoverflow.com/a/22105803/537347 Windows 8 or newer only
IID_AppVisibility: TGUID = '{2246EA2D-CAEA-4444-A3C4-6DE827E44313}';
CLSID_AppVisibility: TGUID = '{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}';
type
MONITOR_APP_VISIBILITY = (
MAV_UNKNOWN = 0,
MAV_NO_APP_VISIBLE = 1,
MAV_APP_VISIBLE = 2
);
// *********************************************************************//
// Interface: IAppVisibilityEvents
// Flags: (0)
// GUID: {6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}
// *********************************************************************//
IAppVisibilityEvents = interface(IUnknown)
['{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}']
function AppVisibilityOnMonitorChanged(hMonitor: HMONITOR;
previousMode: MONITOR_APP_VISIBILITY;
currentMode: MONITOR_APP_VISIBILITY):HRESULT; stdcall;
function LauncherVisibilityChange(currentVisibleState: BOOL): HRESULT; stdcall;
end;
// *********************************************************************//
// Interface: IAppVisibility
// Flags: (0)
// GUID: {2246EA2D-CAEA-4444-A3C4-6DE827E44313}
// *********************************************************************//
IAppVisibility = interface(IUnknown)
['{2246EA2D-CAEA-4444-A3C4-6DE827E44313}']
function GetAppVisibilityOnMonitor(monitor: HMONITOR; out pMode: MONITOR_APP_VISIBILITY): HRESULT; stdcall;
function IsLauncherVisible(out pfVisible: BOOL): HRESULT; stdcall;
function Advise(pCallBack: IAppVisibilityEvents; out pdwCookie: DWORD): HRESULT; stdcall;
function Unadvise(dwCookie: DWORD): HRESULT; stdcall;
end;
var
StartMenuVis: IAppVisibility;
function AccessibleChildren(paccContainer: Pointer; iChildStart: LONGINT;
cChildren: LONGINT; out rgvarChildren: OleVariant;
out pcObtained: LONGINT): HRESULT; stdcall;
external 'OLEACC.DLL' name 'AccessibleChildren';
function RegisterShellHookWindow( hWnd : HWND ) : BOOL; stdcall;
external user32 name 'RegisterShellHookWindow';
function DeregisterShellHookWindow( hWnd : HWND) : BOOL; stdcall;
external user32 name 'DeregisterShellHookWindow';
procedure TfrmMenu.RestoreRequest(var message: TMessage);
begin
// mostramos si está oculto
frmMenu.Show;
end;
procedure TfrmMenu.SetDarkMode(Enable: Boolean);
begin
{ if Enable then
begin
if TStyleManager.IsValidStyle('Windows11_Polar_Dark.vsf') then
TStyleManager.TrySetStyle('Windows11 Polar Dark')
end
else
TStyleManager.TrySetStyle('Windows');}
end;
procedure TfrmMenu.Settings1Click(Sender: TObject);
begin
frmSetting.Show;
end;
procedure TfrmMenu.ShowMenuAnimation(aLocation: Integer; aShow: Boolean = True; animated: Boolean = False);
var
TypesAniPlugin: TAQPSystemTypesAnimations;
begin
{// frmMenuX.Width := MulDiv(64, Self.PixelsPerInch, 96);
var wtf := MulDiv(264, Self.PixelsPerInch, 96);
frmMenuX.Left := Screen.Width - wtf;
frmMenuX.SetBounds(0, 0, 64, Screen.WorkAreaRect.Height);
// frmMenuX.Top := 0;
// frmMenuX.Height := Screen.WorkAreaRect.Height;
if not aShow and frmMenuX.Visible then
frmMenuX.Hide
else
frmMenuX.Show;
if frmMenuX.Icons.Count = 0 then
frmMenuX.LoadIcons(Settings);
frmMenuX.AnimateMenu(aLocation, aShow);
Exit;}
if animated and not isWindows11 then //Windows 10 is slow doing animations on blur windows
{$IFDEF EXPERIMENTAL}
{$I experimental.disable.blur.inc}
{$ELSE}
EnableBlur(Handle, False);
{$ENDIF}
if animated then
begin
TypesAniPlugin := Take(Self)
.FinishAnimations
.Plugin<TAQPSystemTypesAnimations>;
// Animate the BoundsRect (position and size) of the form
TypesAniPlugin
.RectAnimation(Rect(NewLeft, 0, NewLeft + NewWidth, Screen.WorkAreaHeight),
function(RefObject: TObject): TRect
begin
Result := TForm(RefObject).BoundsRect;
end,
procedure(RefObject: TObject; const NewRect: TRect)
var
I: Integer;
begin
TForm(RefObject).BoundsRect := NewRect;
// update icons position
for I := 0 to Icons.Count - 1 do
begin
if Settings.BarPosition = ABE_LEFT then
Icons[I].Left := MenuTargetWidth - Self.Width + MenuTargetIconSpan
else
Icons[I].Left := MenuTargetIconSpan;
end;
end,
250, 0, TAQ.Ease(etBack, emInSnake),
procedure(Sender: TObject)
begin
if NewWidth < MenuTargetWidth then
ShowWindow(Handle, SW_HIDE);
// if timer for icons animations is not enabled
{if not tmrShowMenu.Enabled then
begin
tmrShowMenu.Enabled := True;
tmrHideMenu.Enabled := False;
end
else
begin
tmrShowMenu.Enabled := False;
tmrHideMenu.Enabled := True;
ShowWindow(Handle, SW_HIDE);
end;}
if not isWindows11 then
{$IFDEF EXPERIMENTAL}
{$I experimental.enable.blur.inc}
{$ELSE}
EnableBlur(Handle, True);
{$ENDIF}
end
);
// Animate the AlphaBlendValue
TypesAniPlugin.IntegerAnimation(NewAlphaBlend,
function(RefObject: TObject): Integer
begin
Result := TForm(RefObject).AlphaBlendValue;
end,
procedure(RefObject: TObject; const NewValue: Integer)
begin
TForm(RefObject).AlphaBlendValue := Byte(NewValue);
end,
2000, 0, TAQ.Ease(etCircle, emInInverted));
end
else // no animation, just show the form in the meant position
begin
Left := NewLeft;
Top := 0;
Width := NewWidth;
Height := Screen.WorkAreaHeight;
if NewWidth < MenuTargetWidth then
begin
AlphaBlendValue := 0;
ShowWindow(Handle, SW_HIDE)
end
else
begin
AlphaBlendValue := 255;
for var I := 0 to Icons.Count - 1 do
begin
if Settings.BarPosition = ABE_LEFT then
Icons[I].Left := MenuTargetWidth - Self.Width + MenuTargetIconSpan
else
Icons[I].Left := MenuTargetIconSpan;
end;
end;
end;
end;
procedure TfrmMenu.SiteContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
begin
AlternatURL1.Visible := False;
if Sender is TSkSvg then
begin
//TODO needs better way for it to enable close site option
if not TSkSvg(Sender).Svg.GrayScale then
begin
FCurrentPopupCardId := Settings.Sites[TSkSvg(Sender).Tag].Id;
// show alternate URL once the broser is loaded
if Trim(Settings.Sites[TSkSvg(Sender).Tag].AltUrl) <> '' then
AlternatURL1.Visible := True;
end
else
FCurrentPopupCardId := 0; // hard coded way to say, site not started
end;
end;
procedure TfrmMenu.WMDisplayChange(var message: TMessage);
begin
// Resolution changed
Height := Screen.Height;
// TODO: realign icons
// imgMenu.Top := Height div 2 - 24;
// imgShare.Top := imgMenu.Top - 64;
// imgChatGPT.Top := imgMenu.Top - 64 * 2;
// imgConnect.Top := imgMenu.Top + 64;
// imgSettings.Top := imgMenu.Top + 64 * 2;
// imgClaude.Top := imgMenu.Top + 64 * 3;
inherited;
end;
// The Windows session is ending (shutdown or reboot)
procedure TfrmMenu.WMEndSession(var message: TWMEndSession);
var
TempCard: tbrowsercard;
I: Integer;
begin
// let's close all webview2 instances
if Assigned(mainBrowser.CardPanel1) then
begin
for I := 0 to mainBrowser.CardPanel1.CardCount - 1 do
begin
TempCard := TBrowserCard(mainBrowser.CardPanel1.Cards[I]);
TempCard.Free;
end;
mainBrowser.Visible := False;
end;
inherited;
end;
// The Windows session handler asks for session ending confirmation
procedure TfrmMenu.WMQueryEndSession(var message: TWMQueryEndSession);
begin
message.Result := 1; // allow the shutdown/reboot
end;
procedure TfrmMenu.WMShellHook(var Msg: TMessage);
begin
case Msg.WParam of
HSHELL_WINDOWCREATED, HSHELL_WINDOWDESTROYED:
begin
// if IsStarteMenuVisible then
// begin
// ShowWindow(Handle, SW_SHOWNOACTIVATE);
// if not OnMenuArea then
// begin
// OnMenuArea := True;
// NewWidth := 54;
// NewLeft := Screen.WorkAreaWidth - NewWidth +1;
// NewAlphaBlend := MAXBYTE;
// ShowMenuAnimation;
// end;
// end;
end;
HSHELL_WINDOWACTIVATED:
begin
end;
end;
end;
procedure TfrmMenu.WndMethod(var Msg: TMessage);
begin
if Msg.Msg = FHookMsg then
WMShellHook(Msg);
end;
procedure TfrmMenu.HideMenu(Sender: TObject);
begin
tmrHideMenu.Enabled := true;
end;
procedure TfrmMenu.IconMouseHover(Sender: TObject);
begin
if Sender is TSkSvg then
begin
BalloonHint1.ShowHint(TSkSvg(Sender));
end;
end;
procedure TfrmMenu.actSwitchAIChatsExecute(Sender: TObject);
begin
ShowMessage('Not implemented yet!');
end;
procedure TfrmMenu.AlternatURL1Click(Sender: TObject);
var
I, J: Integer;
begin
for I := 0 to mainBrowser.CardPanel1.CardCount - 1 do
begin
if mainBrowser.CardPanel1.Cards[I].Tag = FCurrentPopupCardId then
begin
for J := 0 to Icons.Count - 1 do
begin
if Settings.Sites[Icons[J].Tag].Id = FCurrentPopupCardId then
begin
TBrowserCard(mainBrowser.CardPanel1.Cards[I]).Navigate(Settings.Sites[Icons[J].Tag].AltUrl);
Break;
end;
end;
Break;
end;
end;
end;
procedure TfrmMenu.askGPT1Click(Sender: TObject);
begin
taskForm.Show;
end;
procedure TfrmMenu.buttonClick(btnID: Cardinal);
begin
end;
//constructor TfrmMenu.Create(AOwner: TComponent);
//var
// MyTaskbar: TAppBarData;
//begin
// inherited;
//
// FillChar(MyTaskbar, SizeOf(TAppBarData), 0);
// MyTaskbar.cbSize := SizeOf(TAppBarData);
// MyTaskbar.hWnd := Handle;
// MyTaskbar.uCallbackMessage := WM_USER + 888;
// MyTaskbar.uEdge := ABE_RIGHT;
// MyTaskbar.rc := ClientRect;
// SHAppBarMessage(ABM_NEW, MyTaskbar);
// SHAppBarMessage(ABM_ACTIVATE, MyTaskbar);
// SHAppBarMessage(ABM_SETPOS, MyTaskbar);
//
// Application.ProcessMessages;
//end;
procedure TfrmMenu.CreateNewCard(
const aArgs: TCoreWebView2NewWindowRequestedEventArgs);
begin
if Assigned(mainBrowser) then
mainBrowser.CreateNewCard(aArgs);
end;
procedure TfrmMenu.CreateNewSite(Sender: TObject);
var
SiteID: Integer;
SiteURL: string;
SiteUA: string;
I: Integer;
Found: Boolean;
begin
Found := False;
SiteID := Settings.Sites[TSkSvg(Sender).Tag].Id;
SiteURL := Settings.Sites[TSkSvg(Sender).Tag].Url;
SiteUA := Settings.Sites[TSkSvg(Sender).Tag].UA;
// check if there isn't already a card/tab with that site opened
for I := 0 to mainBrowser.CardPanel1.CardCount - 1 do
begin
if mainBrowser.CardPanel1.Cards[I].Tag = SiteID then
begin
Found := True;
Break;
end;
end;
if (Sender is TSkSvg) then
begin
if Found then
begin
if Assigned(mainBrowser.CardPanel1.ActiveCard) and
(mainBrowser.CardPanel1.ActiveCard.Tag <> SiteID)
then
begin
mainBrowser.CardPanel1.ActiveCardIndex := I;
mainBrowser.Visible := True;
SetForegroundWindow(mainBrowser.Handle);
FocusCurrentBrowser;
end
else
begin
if mainBrowser.Visible then
mainBrowser.Visible := False
else
begin
mainBrowser.Visible := True;
SetForegroundWindow(mainBrowser.Handle);
FocusCurrentBrowser;
end;
end;
end
else
begin
if FFirstTimeBrowser then
begin // use the predefined hard coded position mimicking the Windows Copilot location
FFirstTimeBrowser := False; // to avoid resetting the position on new calls so user keeps change position in this session
mainBrowser.Height := Screen.WorkAreaRect.Height;
if Settings.BarPosition = ABE_LEFT then
mainBrowser.Left := Screen.WorkAreaRect.Left
else
mainBrowser.Left := Screen.WorkAreaRect.Width - mainBrowser.Width;
mainBrowser.Top := Screen.WorkAreaRect.Top;
end;
mainBrowser.Visible := True;
mainBrowser.CreateNewSite(SiteID, SiteURL, SiteUA);
TSkSvg(Sender).Svg.GrayScale := False;
end;
end;
end;
procedure TfrmMenu.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WinClassName := 'AIChatbarWnd';
Params.WndParent := Application.Handle;
Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;
end;
procedure TfrmMenu.CurrentDesktopChanged(Sender: TObject; OldDesktop,
NewDesktop: TVirtualDesktop);
begin
if Assigned(mainBrowser) then
DesktopManager.MoveWindowToDesktop(mainBrowser.Handle, NewDesktop);
end;
procedure TfrmMenu.CurrentDesktopChangedW11(Sender: TObject; OldDesktop,
NewDesktop: TVirtualDesktopW11);
begin
if Assigned(mainBrowser) then
DesktopManagerW11.MoveWindowToDesktop(mainBrowser.Handle, NewDesktop);
end;
Function GetUserFromWindows: string;
Var
UserName: string;
UserNameLen: Dword;
Begin
UserNameLen := 255;
SetLength(UserName, UserNameLen);
If GetUserName(PChar(UserName), UserNameLen) Then
Result := Copy(UserName, 1, UserNameLen - 1)
Else
Result := 'Unknown';
End;
procedure TfrmMenu.FocusCurrentBrowser;
begin
if Assigned(mainBrowser) then
begin
if GetForegroundWindow = mainBrowser.Handle then
begin
if mainBrowser.CardPanel1.CardCount > 0 then
begin
if Assigned(mainBrowser.CardPanel1.ActiveCard) then
TBrowserCard(mainBrowser.CardPanel1.ActiveCard).FocusBrowser;
end;
end;
end;
end;
procedure TfrmMenu.FormClick(Sender: TObject);
begin
if Assigned(mainBrowser) then
begin
if mainBrowser.Visible then
SetForegroundWindow(mainBrowser.Handle);
end;
end;
procedure TfrmMenu.FormClose(Sender: TObject; var Action: TCloseAction);
//var
// MyTaskbar: TAppBarData;
begin
// FillChar(MyTaskbar, SizeOf(TAppBarData), 0);
// MyTaskbar.cbSize := SizeOf(TAppBarData);
// MyTaskbar.hWnd := Handle;
// SHAppBarMessage(ABM_REMOVE, MyTaskbar);
end;
procedure TfrmMenu.FormCreate(Sender: TObject);
const
SPI_SETDISPLAYDPI = $009F;
var
ReservedScreenArea: TRect;
begin
FFirstTimeBrowser := True; // to use the preset browser position for the first call
PopupWindowRect.Width := 0;
// SystemParametersInfo(SPI_SETDISPLAYDPI, 1, nil, 1);
OnMenuArea := False;
// SetPriorityClass(GetCurrentProcess, $4000);
// Application.OnDeactivate := HideMenu;
Color := clBlack; // $151515;//clBlack;
Width := 1;
Height := Screen.WorkAreaRect.Height;// - 164;
Top := 64;
Left := GetRightMost - 1;// + 10; // Screen.Width+10;//-48;
BorderStyle := bsNone;
Icons := TObjectList<TSKSvg>.Create;
// menu
imgMenu.Left := 40;
imgMenu.Top := Height div 2 - 24;
imgMenu.Cursor := crHandPoint;
{$IFDEF EXPERIMENTAL}
{$I experimental.create.menubar.inc}
{$ELSE}
EnableBlur(Handle, True);
{$IFEND}
SetWindowLong(frmMenu.Handle, GWL_EXSTYLE, GetWindowLong(frmMenu.Handle,
GWL_EXSTYLE) Or WS_EX_LAYERED or WS_EX_TOOLWINDOW);
SetLayeredWindowAttributes(frmMenu.Handle, 0, 0, LWA_ALPHA);
SetWindowPos(frmMenu.Handle, HWND_TOPMOST, Left, Top, Width, Height,
SWP_NOMOVE or SWP_NOACTIVATE or SWP_NOSIZE);
// save current workarea to restore later
SystemParametersInfo(SPI_GETWORKAREA, 0, @OriginalWorkArea, 0);
// now reserver screen area to work with
ReservedScreenArea := Rect(0, 0, 60, Screen.Height);
// SystemParametersInfo(SPI_SETWORKAREA, 0,@ReservedScreenArea, SPIF_SENDCHANGE);
Settings := TSettings.Create(ExtractFilePath(ParamStr(0))+'settings.db');
Settings.ReadSites;
Settings.LoadSettings;
LoadSites;
// Register ourselves as shell message instance receiver
FHookWndHandle := AllocateHWnd(WndMethod);
FHookMsg := RegisterWindowMessage('SHELLHOOK'#0);
RegisterShellHookWindow(FHookWndHandle);
JvApplicationHotKey1.HotKey := TextToShortCut(Settings.GlobalHotkey);
JvApplicationHotKey1.WindowsKey := Settings.RequireWinKey;
JvApplicationHotKey1.Active := True;
// TaskGPT Global Hotkey | Win+F11 hard code for now
JvApplicationHotKey2.HotKey := TextToShortCut('F11');
JvApplicationHotKey2.WindowsKey := True;
JvApplicationHotKey2.Active := True;
// Virtual Desktop Aware (Win10/11)
if TOSVersion.Build >= 22000 then
DesktopManagerW11.OnCurrentDesktopChanged := CurrentDesktopChangedW11
else
DesktopManager.OnCurrentDesktopChanged := CurrentDesktopChanged;
end;
procedure TfrmMenu.FormDestroy(Sender: TObject);
begin
DeregisterShellHookWindow(FHookWndHandle);
DeallocateHWnd(FHookWndHandle);
{$IFDEF EXPERIMENTAL}
{$I experimental.destroy.inc}
{$IFEND}
Icons.Free;
Settings.Free;
// restore reserved screenarea
SystemParametersInfo(SPI_SETWORKAREA, 0, @OriginalWorkArea, 0);
end;
procedure TfrmMenu.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
// TODO: as of now we assume right click is the context menu, needs fix for left hand users mouse settings
if Button = TMouseButton.mbRight then
begin
PopupMenu.Popup(Left + X, Top + Y);
end;
end;
procedure TfrmMenu.FormPaint(Sender: TObject);
begin
if TaskbarAccented then
begin
Canvas.Brush.Handle := CreateSolidBrushWithAlpha(BlendColors(GetAccentColor, clBlack,50), 200);
end
else
begin
if SystemUsesLightTheme then
Canvas.Brush.Handle := CreateSolidBrushWithAlpha($dddddd, 200) else
Canvas.Brush.Handle := CreateSolidBrushWithAlpha($222222, 200);
end;
Canvas.FillRect(Rect(0,0,Width,Height));
end;
procedure TfrmMenu.tmrMenuTimer(Sender: TObject);
var
pos: TPoint;
TypesAniPlugin: TAQPSystemTypesAnimations;
begin
if Settings.DisableOnFullScreenDirectX and DetectFullScreen3D then Exit;
if Settings.DisableOnFullScreen and DetectFullScreenApp(GetForegroundWindow) then Exit;
if FPopupMenuVisible then Exit;
try
pos := Mouse.CursorPos;
except
end;
// verificamos el borde
if (GetAsyncKeyState(VK_LBUTTON) = 0) and (GetAsyncKeyState(VK_RBUTTON) = 0) then
begin
case Settings.BarPosition of
ABE_LEFT:
begin
if (pos.X <= GetLeftMost + 1) then
begin
ShowWindow(Handle, SW_SHOWNOACTIVATE);
if not OnMenuArea then
begin
OnMenuArea := True;
NewWidth := MenuTargetWidth;
NewLeft := GetLeftMost - 1;
NewAlphaBlend := MAXBYTE;
ShowMenuAnimation(ABE_LEFT);
end;
end
else if (pos.X > frmMenu.Left + frmMenu.Width) and (tmrHideMenu.Enabled = False) then
begin
if OnMenuArea then
begin
OnMenuArea := False;
NewWidth := 1;
NewLeft := GetLeftMost;
NewAlphaBlend := 0;
ShowMenuAnimation(ABE_LEFT, False);
end;
end;
end;
ABE_TOP:
begin
end;
ABE_RIGHT:
begin
if (pos.X >= GetRightMost - 1) then
begin
ShowWindow(Handle, SW_SHOWNOACTIVATE);
if not OnMenuArea then
begin
OnMenuArea := True;
NewWidth := MenuTargetWidth;
NewLeft := Screen.WorkAreaWidth - NewWidth +1;
NewAlphaBlend := MAXBYTE;
ShowMenuAnimation(ABE_RIGHT);
end;
end
else if (pos.X < Left) and (tmrHideMenu.Enabled = False) then
// else if (pos.X < GetRightMost - frmMenuX.Width) then //and (tmrHideMenu.Enabled = False) then
begin
if OnMenuArea then
begin
OnMenuArea := False;
NewWidth := 1;
NewLeft := Screen.WorkAreaWidth - NewWidth;
NewAlphaBlend := 0;
ShowMenuAnimation(ABE_RIGHT, False);
end;
end;
end;
ABE_BOTTOM:
begin
end;
end;
end;
end;
procedure TfrmMenu.imgMenuClick(Sender: TObject);
var
winrect: TRect;
begin
if not IsStarteMenuVisible then
SendMessage(Handle, WM_SYSCOMMAND, SC_TASKLIST, 0);
end;
procedure TfrmMenu.Exit1Click(Sender: TObject);
begin
close
end;
procedure TfrmMenu.About1Click(Sender: TObject);
begin
// MessageDlg('Win8Menu v 1.3'#13'Written by vhanla'#13'http://apps.codigobit.info',mtInformation,[mbOK],0);
with TFormSplash.Create(Application) do
execute;
end;
procedure TfrmMenu.tmrHideMenuTimer(Sender: TObject);
begin
if not tmrShowMenu.Enabled then
begin
if Left < GetRightMost - 2 then
Left := Left + 10 // Screen.Width-2 then Left:=Left+10
else
begin
tmrHideMenu.Enabled := False;
// modificamos las posiciones de los iconos
imgMenu.Left := 40;
// imgShare.Left := 50;
// imgChatGPT.Left := 60;
// imgConnect.Left := 50;
// imgSettings.Left := 60;
// imgClaude.Left := 60;
Left := GetRightMost - 2; // Screen.Width-2;
frmMenuON := False;
end;
end;
end;
procedure TfrmMenu.tmrShowMenuTimer(Sender: TObject);
begin
// anima los iconos
if imgMenu.Left > 0 then
imgMenu.Left := imgMenu.Left - 10
else
imgMenu.Left := 0;
// if imgShare.Left > 0 then
// imgShare.Left := imgShare.Left - 10
// else
// imgShare.Left := 0;
//
// if imgChatGPT.Left > 0 then
// imgChatGPT.Left := imgChatGPT.Left - 10
// else
// imgChatGPT.Left := 0;
//
// if imgConnect.Left > 0 then
// imgConnect.Left := imgConnect.Left - 10
// else
// imgConnect.Left := 0;
//
// if imgSettings.Left > 0 then
// imgSettings.Left := imgSettings.Left - 10
// else
// imgSettings.Left := 0;
//
// if imgClaude.Left > 0 then
// imgClaude.Left := imgClaude.Left - 10
// else
// imgClaude.Left := 0;
end;
procedure TfrmMenu.FormShow(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
function TfrmMenu.IsStarteMenuVisible: Boolean;
var
startMenuOn: BOOL;
begin
startMenuOn := False;
var res := CoCreateInstance(CLSID_AppVisibility, nil, CLSCTX_ALL, IID_AppVisibility, StartMenuVis);
if Succeeded(res) then
begin
if Succeeded(StartMenuVis.IsLauncherVisible(startMenuOn)) then
begin
end;
end;
Result := startMenuOn;
end;
procedure TfrmMenu.JvAppEvents1Activate(Sender: TObject);
begin
FocusCurrentBrowser;
end;
procedure TfrmMenu.JvApplicationHotKey1HotKey(Sender: TObject);
begin
if Assigned(mainBrowser) then
begin
if mainBrowser.Visible then
begin
if GetForegroundWindow <> mainBrowser.Handle then
begin
SetForegroundWindow(mainBrowser.Handle);
FocusCurrentBrowser;
end
else
mainBrowser.Hide;
end
else
begin
mainBrowser.Show;
if GetForegroundWindow <> mainBrowser.Handle then
begin
SetForegroundWindow(mainBrowser.Handle);
FocusCurrentBrowser;
end
else
FocusCurrentBrowser;
end;
end;
end;
procedure TfrmMenu.JvApplicationHotKey1HotKeyRegisterFailed(Sender: TObject;
var HotKey: TShortCut);
var
win: string;