mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-09 16:55:55 +02:00
* Allow to specify module for web program
This commit is contained in:
parent
7485ac827a
commit
67a95d4f7f
@ -204,4 +204,17 @@ object WebBrowserProjectOptionsForm: TWebBrowserProjectOptionsForm
|
|||||||
TabOrder = 13
|
TabOrder = 13
|
||||||
TextHint = 'Name of your webassembly file'
|
TextHint = 'Name of your webassembly file'
|
||||||
end
|
end
|
||||||
|
object CBUseModule: TCheckBox
|
||||||
|
AnchorSideLeft.Control = CBCreateHTML
|
||||||
|
AnchorSideTop.Control = CBServerURL
|
||||||
|
AnchorSideTop.Side = asrBottom
|
||||||
|
Left = 6
|
||||||
|
Height = 23
|
||||||
|
Top = 391
|
||||||
|
Width = 293
|
||||||
|
BorderSpacing.Top = 6
|
||||||
|
Caption = 'Create a javascript module instead of a script'
|
||||||
|
OnChange = CBUseHTTPServerChange
|
||||||
|
TabOrder = 14
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,7 @@ type
|
|||||||
BPHelpOptions: TButtonPanel;
|
BPHelpOptions: TButtonPanel;
|
||||||
CBCreateHTML: TCheckBox;
|
CBCreateHTML: TCheckBox;
|
||||||
CBUseBrowserApp: TCheckBox;
|
CBUseBrowserApp: TCheckBox;
|
||||||
|
CBUseModule: TCheckBox;
|
||||||
CBUseWASI: TCheckBox;
|
CBUseWASI: TCheckBox;
|
||||||
CBUseBrowserConsole: TCheckBox;
|
CBUseBrowserConsole: TCheckBox;
|
||||||
CBUseHTTPServer: TCheckBox;
|
CBUseHTTPServer: TCheckBox;
|
||||||
@ -52,6 +53,7 @@ type
|
|||||||
property UseRunOnReady : Boolean Index 6 read GetB Write SetB;
|
property UseRunOnReady : Boolean Index 6 read GetB Write SetB;
|
||||||
property ShowUncaughtExceptions : Boolean Index 7 read GetB Write SetB;
|
property ShowUncaughtExceptions : Boolean Index 7 read GetB Write SetB;
|
||||||
property UseWASI : Boolean Index 8 read GetB Write SetB;
|
property UseWASI : Boolean Index 8 read GetB Write SetB;
|
||||||
|
property UseModule : Boolean Index 9 read GetB Write SetB;
|
||||||
Property ServerPort : Word Read GetServerPort Write SetServerPort;
|
Property ServerPort : Word Read GetServerPort Write SetServerPort;
|
||||||
Property URL : String Read GetURL Write SetURL;
|
Property URL : String Read GetURL Write SetURL;
|
||||||
Property WasmProgramURL : String Read GetWasmProgramURL Write SetWasmProgramURL;
|
Property WasmProgramURL : String Read GetWasmProgramURL Write SetWasmProgramURL;
|
||||||
@ -148,6 +150,7 @@ begin
|
|||||||
6 : Result:=CBRunOnReady.Checked;
|
6 : Result:=CBRunOnReady.Checked;
|
||||||
7 : Result:=cbShowUncaughtExceptions.Checked;
|
7 : Result:=cbShowUncaughtExceptions.Checked;
|
||||||
8 : Result:=cbUseWASI.Checked;
|
8 : Result:=cbUseWASI.Checked;
|
||||||
|
9 : Result:=cbUseModule.Checked;
|
||||||
else
|
else
|
||||||
Result:=False;
|
Result:=False;
|
||||||
end;
|
end;
|
||||||
@ -195,6 +198,7 @@ begin
|
|||||||
6 : CBRunOnReady.Checked:=Avalue;
|
6 : CBRunOnReady.Checked:=Avalue;
|
||||||
7 : cbShowUncaughtExceptions.Checked:=aValue;
|
7 : cbShowUncaughtExceptions.Checked:=aValue;
|
||||||
8 : cbUseWASI.Checked:=aValue;
|
8 : cbUseWASI.Checked:=aValue;
|
||||||
|
9 : cbUseModule.Checked:=aValue;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ type
|
|||||||
baoStartServer, // Start simple server
|
baoStartServer, // Start simple server
|
||||||
baoUseURL, // Use this URL to run/show project in browser
|
baoUseURL, // Use this URL to run/show project in browser
|
||||||
baoShowException, // let RTL show uncaught exceptions
|
baoShowException, // let RTL show uncaught exceptions
|
||||||
baoUseWASI // Use WASI browser app object
|
baoUseWASI, // Use WASI browser app object
|
||||||
|
baoUseModule // include as module as opposed to regular script
|
||||||
);
|
);
|
||||||
TBrowserApplicationOptions = set of TBrowserApplicationOption;
|
TBrowserApplicationOptions = set of TBrowserApplicationOption;
|
||||||
|
|
||||||
@ -783,6 +784,7 @@ begin
|
|||||||
StartHTTPServer:=CO(baoStartServer);
|
StartHTTPServer:=CO(baoStartServer);
|
||||||
UseRunOnReady:=CO(baoRunOnReady);
|
UseRunOnReady:=CO(baoRunOnReady);
|
||||||
UseWASI:=CO(baoUseWASI);
|
UseWASI:=CO(baoUseWASI);
|
||||||
|
UseModule:=CO(baoUseModule);
|
||||||
ShowUncaughtExceptions:=CO(baoShowException);
|
ShowUncaughtExceptions:=CO(baoShowException);
|
||||||
// We allocate the new port in all cases.
|
// We allocate the new port in all cases.
|
||||||
ServerPort:=GetNextPort;
|
ServerPort:=GetNextPort;
|
||||||
@ -801,6 +803,7 @@ begin
|
|||||||
SO(UseRunOnReady,baoRunOnReady);
|
SO(UseRunOnReady,baoRunOnReady);
|
||||||
SO(ShowUncaughtExceptions,baoShowException);
|
SO(ShowUncaughtExceptions,baoShowException);
|
||||||
SO(UseWASI,baoUseWASI);
|
SO(UseWASI,baoUseWASI);
|
||||||
|
SO(UseModule,baoUseModule);
|
||||||
SO(StartHTTPServer,baoStartServer);
|
SO(StartHTTPServer,baoStartServer);
|
||||||
Self.ProjectPort:=ServerPort;
|
Self.ProjectPort:=ServerPort;
|
||||||
SO(UseURL,baoUseURL);
|
SO(UseURL,baoUseURL);
|
||||||
@ -851,12 +854,10 @@ Const
|
|||||||
+' <meta http-equiv="Content-type" content="text/html; charset=utf-8">'+LineEnding
|
+' <meta http-equiv="Content-type" content="text/html; charset=utf-8">'+LineEnding
|
||||||
+' <meta name="viewport" content="width=device-width, initial-scale=1">'+LineEnding
|
+' <meta name="viewport" content="width=device-width, initial-scale=1">'+LineEnding
|
||||||
+' <title>Project1</title>'+LineEnding
|
+' <title>Project1</title>'+LineEnding
|
||||||
+' <script src="%s"></script>'+LineEnding
|
+' <script %s src="%s"></script>'+LineEnding
|
||||||
+'</head>'+LineEnding
|
+'</head>'+LineEnding
|
||||||
+'<body>'+LineEnding
|
+'<body>'+LineEnding
|
||||||
+' <script>'+LineEnding
|
|
||||||
+' %s'+LineEnding
|
+' %s'+LineEnding
|
||||||
+' </script>'+LineEnding
|
|
||||||
+' %s'+LineEnding
|
+' %s'+LineEnding
|
||||||
+'</body>'+LineEnding
|
+'</body>'+LineEnding
|
||||||
+'</html>'+LineEnding;
|
+'</html>'+LineEnding;
|
||||||
@ -865,7 +866,7 @@ Const
|
|||||||
Var
|
Var
|
||||||
HTMLFile : TLazProjectFile;
|
HTMLFile : TLazProjectFile;
|
||||||
HTMLSource : String;
|
HTMLSource : String;
|
||||||
RunScript,Content : String;
|
ScriptType, RunScript,Content : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
HTMLFile:=AProject.CreateProjectFile('project1.html');
|
HTMLFile:=AProject.CreateProjectFile('project1.html');
|
||||||
@ -873,17 +874,29 @@ begin
|
|||||||
AProject.CustomData.Values[PJSProjectHTMLFile]:=HTMLFile.Filename;
|
AProject.CustomData.Values[PJSProjectHTMLFile]:=HTMLFile.Filename;
|
||||||
AProject.AddFile(HTMLFile,false);
|
AProject.AddFile(HTMLFile,false);
|
||||||
Content:='';
|
Content:='';
|
||||||
|
ScriptType:='';
|
||||||
|
RunScript:='';
|
||||||
if baoUseBrowserConsole in Options then
|
if baoUseBrowserConsole in Options then
|
||||||
Content:=ConsoleDiv;
|
Content:=ConsoleDiv;
|
||||||
if baoShowException in Options then
|
if baoUseModule in Options then
|
||||||
Runscript:='rtl.showUncaughtExceptions=true;'+LineEnding+' '
|
begin
|
||||||
|
ScriptType:='type="module"';
|
||||||
|
end
|
||||||
else
|
else
|
||||||
RunScript:='';
|
begin
|
||||||
if baoRunOnReady in Options then
|
if baoShowException in Options then
|
||||||
RunScript:=Runscript+'window.addEventListener("load", rtl.run);'+LineEnding
|
Runscript:='rtl.showUncaughtExceptions=true;'+LineEnding+' '
|
||||||
else
|
else
|
||||||
RunScript:=Runscript+'rtl.run();'+LineEnding;
|
RunScript:='';
|
||||||
HTMLSource:=Format(TemplateHTMLSource,[aFileName,RunScript,Content]);
|
if baoRunOnReady in Options then
|
||||||
|
RunScript:=Runscript+'window.addEventListener("load", rtl.run);'+LineEnding
|
||||||
|
else
|
||||||
|
RunScript:=Runscript+'rtl.run();'+LineEnding;
|
||||||
|
RunScript:=' <script>'+LineEnding
|
||||||
|
+RunScript
|
||||||
|
+' </script>'+LineEnding
|
||||||
|
end;
|
||||||
|
HTMLSource:=Format(TemplateHTMLSource,[ScriptType,aFileName,RunScript,Content]);
|
||||||
HTMLFile.SetSourceText(HTMLSource);
|
HTMLFile.SetSourceText(HTMLSource);
|
||||||
Result:=HTMLFile;
|
Result:=HTMLFile;
|
||||||
end;
|
end;
|
||||||
@ -991,6 +1004,8 @@ begin
|
|||||||
CompOpts:=AProject.LazCompilerOptions;
|
CompOpts:=AProject.LazCompilerOptions;
|
||||||
SetDefaultWebCompileOptions(CompOpts);
|
SetDefaultWebCompileOptions(CompOpts);
|
||||||
CompOpts.TargetFilename:='project1';
|
CompOpts.TargetFilename:='project1';
|
||||||
|
if baoUseModule in Options then
|
||||||
|
CompOpts.TargetOS:='module';
|
||||||
SetDefaultWebRunParams(AProject.RunParameters.GetOrCreate('Default'));
|
SetDefaultWebRunParams(AProject.RunParameters.GetOrCreate('Default'));
|
||||||
AProject.MainFile.SetSourceText(CreateProjectSource,true);
|
AProject.MainFile.SetSourceText(CreateProjectSource,true);
|
||||||
AProject.CustomData.Values[PJSProject]:='1';
|
AProject.CustomData.Values[PJSProject]:='1';
|
||||||
|
Loading…
Reference in New Issue
Block a user