mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-09-04 18:10:12 +02:00
fcl-base: service worker: removed env
This commit is contained in:
parent
3891ead506
commit
4c991bb050
@ -9,7 +9,7 @@ unit ServiceWorkerApp;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Types, JS, web, CustApp;
|
SysUtils, Types, JS, web, Classes, CustApp;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ type
|
|||||||
function GetConsoleApplication: boolean; override;
|
function GetConsoleApplication: boolean; override;
|
||||||
function GetLocation: String; override;
|
function GetLocation: String; override;
|
||||||
public
|
public
|
||||||
procedure GetEnvironmentList(List: TStrings; NamesOnly: Boolean); override;
|
procedure GetEnvironmentList(List{%H-}: TStrings; NamesOnly{%H-}: Boolean); override;
|
||||||
procedure ShowException(E: Exception); override;
|
procedure ShowException(E: Exception); override;
|
||||||
procedure HandleException(Sender: TObject); override;
|
procedure HandleException(Sender: TObject); override;
|
||||||
|
|
||||||
@ -45,62 +45,8 @@ type
|
|||||||
property Resources: TStringDynArray read FResources;
|
property Resources: TStringDynArray read FResources;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ReloadEnvironmentStrings;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
var
|
|
||||||
EnvNames: TJSObject;
|
|
||||||
|
|
||||||
procedure ReloadEnvironmentStrings;
|
|
||||||
|
|
||||||
var
|
|
||||||
I : Integer;
|
|
||||||
S,N : String;
|
|
||||||
A,P : TStringDynArray;
|
|
||||||
begin
|
|
||||||
if not jsvalue(Window) then exit;
|
|
||||||
if not jsvalue(Window.location) then exit;
|
|
||||||
if Assigned(EnvNames) then
|
|
||||||
FreeAndNil(EnvNames);
|
|
||||||
EnvNames:=TJSObject.new;
|
|
||||||
S:=Window.Location.search;
|
|
||||||
S:=Copy(S,2,Length(S)-1);
|
|
||||||
A:=TJSString(S).split('&');
|
|
||||||
for I:=0 to Length(A)-1 do
|
|
||||||
begin
|
|
||||||
P:=TJSString(A[i]).split('=');
|
|
||||||
N:=LowerCase(decodeURIComponent(P[0]));
|
|
||||||
if Length(P)=2 then
|
|
||||||
EnvNames[N]:=decodeURIComponent(P[1])
|
|
||||||
else if Length(P)=1 then
|
|
||||||
EnvNames[N]:=''
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function MyGetEnvironmentVariable(Const EnvVar: String): String;
|
|
||||||
|
|
||||||
Var
|
|
||||||
aName : String;
|
|
||||||
|
|
||||||
begin
|
|
||||||
aName:=Lowercase(EnvVar);
|
|
||||||
if EnvNames.hasOwnProperty(aName) then
|
|
||||||
Result:=String(EnvNames[aName])
|
|
||||||
else
|
|
||||||
Result:='';
|
|
||||||
end;
|
|
||||||
|
|
||||||
function MyGetEnvironmentVariableCount: Integer;
|
|
||||||
begin
|
|
||||||
Result:=length(TJSOBject.getOwnPropertyNames(envNames));
|
|
||||||
end;
|
|
||||||
|
|
||||||
function MyGetEnvironmentString(Index: Integer): String;
|
|
||||||
begin
|
|
||||||
Result:=String(EnvNames[TJSOBject.getOwnPropertyNames(envNames)[Index]]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TServiceWorkerApplication }
|
{ TServiceWorkerApplication }
|
||||||
|
|
||||||
procedure TServiceWorkerApplication.SetFallbackURL(const AValue: string);
|
procedure TServiceWorkerApplication.SetFallbackURL(const AValue: string);
|
||||||
@ -233,18 +179,8 @@ end;
|
|||||||
|
|
||||||
procedure TServiceWorkerApplication.GetEnvironmentList(List: TStrings;
|
procedure TServiceWorkerApplication.GetEnvironmentList(List: TStrings;
|
||||||
NamesOnly: Boolean);
|
NamesOnly: Boolean);
|
||||||
var
|
|
||||||
Names: TStringDynArray;
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
Names:=TJSObject.getOwnPropertyNames(EnvNames);
|
|
||||||
for i:=0 to length(Names)-1 do
|
|
||||||
begin
|
|
||||||
if NamesOnly then
|
|
||||||
List.Add(Names[i])
|
|
||||||
else
|
|
||||||
List.Add(Names[i]+'='+String(EnvNames[Names[i]]));
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TServiceWorkerApplication.ShowException(E: Exception);
|
procedure TServiceWorkerApplication.ShowException(E: Exception);
|
||||||
@ -269,10 +205,6 @@ end;
|
|||||||
|
|
||||||
initialization
|
initialization
|
||||||
IsConsole:=true;
|
IsConsole:=true;
|
||||||
ReloadEnvironmentStrings;
|
|
||||||
OnGetEnvironmentVariable:=@MyGetEnvironmentVariable;
|
|
||||||
OnGetEnvironmentVariableCount:=@MyGetEnvironmentVariableCount;
|
|
||||||
OnGetEnvironmentString:=@MyGetEnvironmentString;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user