Skip to content

Commit

Permalink
Changing the system proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
r57zone committed Aug 18, 2024
1 parent e100b24 commit 13a558a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.RU.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![EN](https://user-images.githubusercontent.com/9499881/33184537-7be87e86-d096-11e7-89bb-f3286f752bc6.png)](https://github.com/r57zone/ProtonShell/blob/master/README.md)
[![RU](https://user-images.githubusercontent.com/9499881/27683795-5b0fbac6-5cd8-11e7-929c-057833e01fb1.png)](https://github.com/r57zone/ProtonShell/blob/master/README.RU.md)
# ProtonShell
Легковесная оболочка для веб-сайтов, простых веб-приложений, работающая на базе системного браузера Microsoft Edge. На её основе можно сделать отдельное окно для Google Docs, чата Twitch, клиента инстаграмма для ПК, с пользовательским js скриптом или какое-то веб-приложение в своём окне.
Легковесная оболочка для веб-сайтов, простых веб-приложений, работающая на базе системного браузера Microsoft Edge. На её основе можно сделать отдельное окно для Google Docs, ChatGPT, чата Twitch, клиента инстаграмма для ПК, с пользовательским js скриптом или какое-то веб-приложение в своём окне.

## Скриншоты
![](https://github.com/r57zone/ProtonShell/assets/9499881/ca14a06b-4c3f-420a-8ec8-a742a2ae5f8d)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
← Choose language | Выберите язык

# ProtonShell
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.
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.

## Screenshots
![](https://github.com/r57zone/ProtonShell/assets/9499881/ca14a06b-4c3f-420a-8ec8-a742a2ae5f8d)
Expand Down
11 changes: 9 additions & 2 deletions Source/Config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://github.com/r57zone/ProtonShell

[Main]
Title=Test App
# Application folder address - "%FULLPATH%/", clear the value of "File" if you want to load the website.
Expand All @@ -8,14 +10,19 @@ URL=https://google.ru
OpenExternalLinks=1
# Example of the path - "%FULLPATH%/UserScript.js"
UserScript=
# Change system proxy while using the app
SystemProxy=
# Return to previous system proxy after closing the app (if you use proxy), 1 - on, 0 - off
ReturnPreviousProxy=0

[Window]
Width=640
Height=360
Width=720
Height=480
SaveSize=0

# None = 0, Sizeable = 1, Single = 2, Dialog = 3, SizeToolWin = 4, ToolWindow = 5
BorderStyle=1
# 1 - on, 0 - off
HideMaximize=0

# Normal = 0, Maximized = 1, FullScreen = 2
Expand Down
11 changes: 5 additions & 6 deletions Source/Unit1.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object Main: TMain
Left = 0
Top = 0
Caption = 'Main'
ClientHeight = 480
ClientWidth = 640
ClientHeight = 479
ClientWidth = 636
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Expand All @@ -13,19 +13,18 @@ object Main: TMain
Position = poDefault
OnClose = FormClose
OnCreate = FormCreate
OnDestroy = FormDestroy
TextHeight = 13
object EdgeBrowser: TEdgeBrowser
Left = 0
Top = 0
Width = 640
Height = 480
Width = 636
Height = 479
Align = alClient
TabOrder = 0
UserDataFolder = '%LOCALAPPDATA%\bds.exe.WebView2'
OnCreateWebViewCompleted = EdgeBrowserCreateWebViewCompleted
OnNavigationCompleted = EdgeBrowserNavigationCompleted
OnNewWindowRequested = EdgeBrowserNewWindowRequested
ExplicitWidth = 792
ExplicitHeight = 467
end
end
61 changes: 58 additions & 3 deletions Source/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, WebView2, Winapi.ActiveX, Vcl.Edge, IniFiles, ShellAPI;
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, WebView2, Winapi.ActiveX, Vcl.Edge, IniFiles, ShellAPI,
Registry, WinInet;

const // https://stackoverflow.com/questions/66692031/how-to-set-useragent-in-new-delphi-tedgebrowser
IID_ICoreWebView2Settings2: TGUID = '{EE9A0F68-F46C-4E32-AC23-EF8CAC224D2A}';
Expand All @@ -27,6 +28,7 @@ TMain = class(TForm)
Args: TNewWindowRequestedEventArgs);
procedure EdgeBrowserNavigationCompleted(Sender: TCustomEdgeBrowser;
IsSuccess: Boolean; WebErrorStatus: TOleEnum);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
Expand All @@ -36,8 +38,8 @@ TMain = class(TForm)
var
Main: TMain;
WinOldWidth, WinOldHeight, WinOldTop, WinOldLeft: integer;
WinSaveSize, WinSavePos: boolean;
EdgeUserAgent: string;
WinSaveSize, WinSavePos, ReturnPrevSystemProxy: boolean;
EdgeUserAgent, SystemProxy, PrevSystemProxy: string;
OpenExternalLinks, LoadUserScript: boolean;
UserScriptFile: TStringList;

Expand Down Expand Up @@ -93,6 +95,42 @@ procedure TMain.EdgeBrowserNewWindowRequested(Sender: TCustomEdgeBrowser;
end;
end;

procedure ProxyActivate(Enable: boolean);
var
Reg: TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Internet Settings', False);
Reg.WriteBool('ProxyEnable', Enable);
Reg.CloseKey;
InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0);
finally
Reg.Free;
end;
end;

procedure SetProxy(const Server: String);
var
Reg: TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Internet Settings', False);
if ReturnPrevSystemProxy then begin
if Reg.ValueExists('ProxyServer') then
PrevSystemProxy:=Reg.ReadString('ProxyServer')
else
PrevSystemProxy:='';
ShowMessage(PrevSystemProxy);
end;
Reg.WriteString('ProxyServer', Server);
Reg.CloseKey;
finally
Reg.Free;
end;
end;

procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
var
Ini: TIniFile;
Expand Down Expand Up @@ -183,7 +221,24 @@ procedure TMain.FormCreate(Sender: TObject);
if Ini.ReadBool('Window', 'StayOnTop', false) then
FormStyle:=fsStayOnTop;

// System proxy
ReturnPrevSystemProxy:=Ini.ReadBool('Main', 'ReturnPreviousProxy', false);
SystemProxy:=Trim(Ini.ReadString('Main', 'SystemProxy', ''));
if SystemProxy <> '' then begin
SetProxy(SystemProxy);
ProxyActivate(true);
end;

Ini.Free;
end;

procedure TMain.FormDestroy(Sender: TObject);
begin
if ReturnPrevSystemProxy then begin
SetProxy(PrevSystemProxy);
ProxyActivate(true);
end else if SystemProxy <> '' then
ProxyActivate(false);
end;

end.

0 comments on commit 13a558a

Please sign in to comment.