Skip to content

Commit 13a558a

Browse files
committed
Changing the system proxy
1 parent e100b24 commit 13a558a

File tree

5 files changed

+74
-13
lines changed

5 files changed

+74
-13
lines changed

README.RU.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![EN](https://user-images.githubusercontent.com/9499881/33184537-7be87e86-d096-11e7-89bb-f3286f752bc6.png)](https://github.com/r57zone/ProtonShell/blob/master/README.md)
22
[![RU](https://user-images.githubusercontent.com/9499881/27683795-5b0fbac6-5cd8-11e7-929c-057833e01fb1.png)](https://github.com/r57zone/ProtonShell/blob/master/README.RU.md)
33
# ProtonShell
4-
Легковесная оболочка для веб-сайтов, простых веб-приложений, работающая на базе системного браузера Microsoft Edge. На её основе можно сделать отдельное окно для Google Docs, чата Twitch, клиента инстаграмма для ПК, с пользовательским js скриптом или какое-то веб-приложение в своём окне.
4+
Легковесная оболочка для веб-сайтов, простых веб-приложений, работающая на базе системного браузера Microsoft Edge. На её основе можно сделать отдельное окно для Google Docs, ChatGPT, чата Twitch, клиента инстаграмма для ПК, с пользовательским js скриптом или какое-то веб-приложение в своём окне.
55

66
## Скриншоты
77
![](https://github.com/r57zone/ProtonShell/assets/9499881/ca14a06b-4c3f-420a-8ec8-a742a2ae5f8d)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
← Choose language | Выберите язык
44

55
# ProtonShell
6-
Lightweight shell for websites, simple web applications, built on the Microsoft Edge system browser. Based on it you can make a separate window for Google Docs, Twitch chat, instagram client for PC, with js userscript or some web application in its own window.
6+
Lightweight shell for websites, simple web applications, built on the Microsoft Edge system browser. Based on it you can make a separate window for Google Docs, ChatGPT, Twitch chat, Instagram client for PC, with js userscript or some web application in its own window.
77

88
## Screenshots
99
![](https://github.com/r57zone/ProtonShell/assets/9499881/ca14a06b-4c3f-420a-8ec8-a742a2ae5f8d)

Source/Config.ini

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# https://github.com/r57zone/ProtonShell
2+
13
[Main]
24
Title=Test App
35
# Application folder address - "%FULLPATH%/", clear the value of "File" if you want to load the website.
@@ -8,14 +10,19 @@ URL=https://google.ru
810
OpenExternalLinks=1
911
# Example of the path - "%FULLPATH%/UserScript.js"
1012
UserScript=
13+
# Change system proxy while using the app
14+
SystemProxy=
15+
# Return to previous system proxy after closing the app (if you use proxy), 1 - on, 0 - off
16+
ReturnPreviousProxy=0
1117

1218
[Window]
13-
Width=640
14-
Height=360
19+
Width=720
20+
Height=480
1521
SaveSize=0
1622

1723
# None = 0, Sizeable = 1, Single = 2, Dialog = 3, SizeToolWin = 4, ToolWindow = 5
1824
BorderStyle=1
25+
# 1 - on, 0 - off
1926
HideMaximize=0
2027

2128
# Normal = 0, Maximized = 1, FullScreen = 2

Source/Unit1.dfm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ object Main: TMain
22
Left = 0
33
Top = 0
44
Caption = 'Main'
5-
ClientHeight = 480
6-
ClientWidth = 640
5+
ClientHeight = 479
6+
ClientWidth = 636
77
Color = clBtnFace
88
Font.Charset = DEFAULT_CHARSET
99
Font.Color = clWindowText
@@ -13,19 +13,18 @@ object Main: TMain
1313
Position = poDefault
1414
OnClose = FormClose
1515
OnCreate = FormCreate
16+
OnDestroy = FormDestroy
1617
TextHeight = 13
1718
object EdgeBrowser: TEdgeBrowser
1819
Left = 0
1920
Top = 0
20-
Width = 640
21-
Height = 480
21+
Width = 636
22+
Height = 479
2223
Align = alClient
2324
TabOrder = 0
2425
UserDataFolder = '%LOCALAPPDATA%\bds.exe.WebView2'
2526
OnCreateWebViewCompleted = EdgeBrowserCreateWebViewCompleted
2627
OnNavigationCompleted = EdgeBrowserNavigationCompleted
2728
OnNewWindowRequested = EdgeBrowserNewWindowRequested
28-
ExplicitWidth = 792
29-
ExplicitHeight = 467
3029
end
3130
end

Source/Unit1.pas

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ interface
44

55
uses
66
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
7-
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, WebView2, Winapi.ActiveX, Vcl.Edge, IniFiles, ShellAPI;
7+
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, WebView2, Winapi.ActiveX, Vcl.Edge, IniFiles, ShellAPI,
8+
Registry, WinInet;
89

910
const // https://stackoverflow.com/questions/66692031/how-to-set-useragent-in-new-delphi-tedgebrowser
1011
IID_ICoreWebView2Settings2: TGUID = '{EE9A0F68-F46C-4E32-AC23-EF8CAC224D2A}';
@@ -27,6 +28,7 @@ TMain = class(TForm)
2728
Args: TNewWindowRequestedEventArgs);
2829
procedure EdgeBrowserNavigationCompleted(Sender: TCustomEdgeBrowser;
2930
IsSuccess: Boolean; WebErrorStatus: TOleEnum);
31+
procedure FormDestroy(Sender: TObject);
3032
private
3133
{ Private declarations }
3234
public
@@ -36,8 +38,8 @@ TMain = class(TForm)
3638
var
3739
Main: TMain;
3840
WinOldWidth, WinOldHeight, WinOldTop, WinOldLeft: integer;
39-
WinSaveSize, WinSavePos: boolean;
40-
EdgeUserAgent: string;
41+
WinSaveSize, WinSavePos, ReturnPrevSystemProxy: boolean;
42+
EdgeUserAgent, SystemProxy, PrevSystemProxy: string;
4143
OpenExternalLinks, LoadUserScript: boolean;
4244
UserScriptFile: TStringList;
4345

@@ -93,6 +95,42 @@ procedure TMain.EdgeBrowserNewWindowRequested(Sender: TCustomEdgeBrowser;
9395
end;
9496
end;
9597

98+
procedure ProxyActivate(Enable: boolean);
99+
var
100+
Reg: TRegistry;
101+
begin
102+
Reg:=TRegistry.Create;
103+
try
104+
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Internet Settings', False);
105+
Reg.WriteBool('ProxyEnable', Enable);
106+
Reg.CloseKey;
107+
InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0);
108+
finally
109+
Reg.Free;
110+
end;
111+
end;
112+
113+
procedure SetProxy(const Server: String);
114+
var
115+
Reg: TRegistry;
116+
begin
117+
Reg:=TRegistry.Create;
118+
try
119+
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Internet Settings', False);
120+
if ReturnPrevSystemProxy then begin
121+
if Reg.ValueExists('ProxyServer') then
122+
PrevSystemProxy:=Reg.ReadString('ProxyServer')
123+
else
124+
PrevSystemProxy:='';
125+
ShowMessage(PrevSystemProxy);
126+
end;
127+
Reg.WriteString('ProxyServer', Server);
128+
Reg.CloseKey;
129+
finally
130+
Reg.Free;
131+
end;
132+
end;
133+
96134
procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
97135
var
98136
Ini: TIniFile;
@@ -183,7 +221,24 @@ procedure TMain.FormCreate(Sender: TObject);
183221
if Ini.ReadBool('Window', 'StayOnTop', false) then
184222
FormStyle:=fsStayOnTop;
185223

224+
// System proxy
225+
ReturnPrevSystemProxy:=Ini.ReadBool('Main', 'ReturnPreviousProxy', false);
226+
SystemProxy:=Trim(Ini.ReadString('Main', 'SystemProxy', ''));
227+
if SystemProxy <> '' then begin
228+
SetProxy(SystemProxy);
229+
ProxyActivate(true);
230+
end;
231+
186232
Ini.Free;
187233
end;
188234

235+
procedure TMain.FormDestroy(Sender: TObject);
236+
begin
237+
if ReturnPrevSystemProxy then begin
238+
SetProxy(PrevSystemProxy);
239+
ProxyActivate(true);
240+
end else if SystemProxy <> '' then
241+
ProxyActivate(false);
242+
end;
243+
189244
end.

0 commit comments

Comments
 (0)