-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New unit for NetHTTP #33
Open
p-samuel
wants to merge
20
commits into
main
Choose a base branch
from
net-http
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
35e2545
:construction: Demos
p-samuel 610ebe5
:recycle: Refactoring
p-samuel bee8d43
:construction: Refactoring
p-samuel e15201a
:construction: NetHTTP
p-samuel c9647a8
:recycle: Refactoring
p-samuel 5ba5381
🚧 Removing WinAPI
p-samuel 8561b67
:construction: Android Publisher
p-samuel d28f699
:recycle: Small refactoring
p-samuel b556413
Merge branch 'main' into net-http
p-samuel 23798e7
:recycle: Refactoring after merged with main
p-samuel d9824b6
:construction: Compatibility with older versions
p-samuel 2fdd718
:construction: Warnings
p-samuel 93cec1e
:construction: Final modifications
p-samuel 89b8870
:recycle: Removing Compiler Directive
p-samuel 114f21e
Merge branch 'main' into net-http
p-samuel c46946e
:ant: : Retro-compatibility bug
p-samuel 66ac058
:bug: Event Stream Bug
p-samuel 6c09f15
Merge branch 'main' into net-http
p-samuel 0b7b308
:arrow_up: Delphi 11
p-samuel e4f41fe
:recycle: Android Kaput
p-samuel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
program NtfyService; | ||
|
||
uses | ||
Vcl.SvcMgr, | ||
Service.Module in 'src\Service.Module.pas' {NtfyModule: TService}; | ||
|
||
{$R *.RES} | ||
|
||
begin | ||
// Windows 2003 Server requires StartServiceCtrlDispatcher to be | ||
// called before CoRegisterClassObject, which can be called indirectly | ||
// by Application.Initialize. TServiceApplication.DelayInitialize allows | ||
// Application.Initialize to be called from TService.Main (after | ||
// StartServiceCtrlDispatcher has been called). | ||
// | ||
// Delayed initialization of the Application object may affect | ||
// events which then occur prior to initialization, such as | ||
// TService.OnCreate. It is only recommended if the ServiceApplication | ||
// registers a class object with OLE and is intended for use with | ||
// Windows 2003 Server. | ||
// | ||
// Application.DelayInitialize := True; | ||
// | ||
if not Application.DelayInitialize or Application.Installing then | ||
Application.Initialize; | ||
Application.CreateForm(TNtfyModule, NtfyModule); | ||
Application.Run; | ||
end. |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
object NtfyModule: TNtfyModule | ||
OldCreateOrder = False | ||
DisplayName = 'NtfyService' | ||
AfterInstall = ServiceAfterInstall | ||
OnStart = ServiceStart | ||
OnStop = ServiceStop | ||
Height = 150 | ||
Width = 215 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
unit Service.Module; | ||
|
||
interface | ||
|
||
uses | ||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, | ||
Vcl.Graphics, Vcl.Controls, Vcl.SvcMgr, Vcl.Dialogs, Notify; | ||
|
||
type | ||
TNtfyModule = class(TService) | ||
procedure ServiceAfterInstall(Sender: TService); | ||
procedure ServiceStart(Sender: TService; var Started: Boolean); | ||
procedure ServiceStop(Sender: TService; var Stopped: Boolean); | ||
public | ||
function GetServiceController: TServiceController; override; | ||
end; | ||
|
||
var | ||
NtfyModule: TNtfyModule; | ||
|
||
implementation | ||
|
||
uses | ||
System.Win.Registry; | ||
|
||
{$R *.dfm} | ||
|
||
procedure ServiceController(CtrlCode: DWord); stdcall; | ||
begin | ||
NtfyModule.Controller(CtrlCode); | ||
end; | ||
function TNtfyModule.GetServiceController: TServiceController; | ||
begin | ||
Result := ServiceController; | ||
end; | ||
|
||
procedure TNtfyModule.ServiceAfterInstall(Sender: TService); | ||
var | ||
Reg: TRegistry; | ||
begin | ||
Reg := TRegistry.Create(KEY_READ or KEY_WRITE); | ||
try | ||
Reg.RootKey := HKEY_LOCAL_MACHINE; | ||
if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\' + Name, False) then | ||
begin | ||
Reg.WriteString('Description', 'Ntfy Client Service'); | ||
Reg.CloseKey; | ||
end; | ||
finally | ||
Reg.Free; | ||
end; | ||
end; | ||
|
||
procedure TNtfyModule.ServiceStart(Sender: TService; var Started: Boolean); | ||
begin | ||
// You can log your messages with a service. I could not find a solution | ||
// for pushing windows notifications on win services. | ||
Ntfy.Subscribe('your-very-secret-topic',procedure (AEvent: INotifyEvent) | ||
var LPath: TStringStream; | ||
begin | ||
LPath := TStringStream.Create(AEvent.MessageContent); | ||
try | ||
LPath.SaveToFile(ExtractFilePath(ParamStr(0)) + 'ntfy-logs.txt'); | ||
finally | ||
LPath.Free; | ||
end; | ||
end); | ||
end; | ||
|
||
procedure TNtfyModule.ServiceStop(Sender: TService; var Stopped: Boolean); | ||
begin | ||
Ntfy.Unsubscribe; | ||
end; | ||
|
||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
unit Notify.Api.Factory; | ||
|
||
interface | ||
|
||
uses | ||
Notify.Api.Contract; | ||
|
||
type | ||
TNotifyApiFactory = class(TInterfacedObject, INotifyApiFactory) | ||
public | ||
class function New: INotifyApiFactory; | ||
function Api: INotifyApi; | ||
end; | ||
|
||
implementation | ||
|
||
uses | ||
Notify.Api.NetHTTP, | ||
Notify.Api.Indy; | ||
|
||
{ TNotifyApiFactory } | ||
|
||
function TNotifyApiFactory.Api: INotifyApi; | ||
begin | ||
{$IFDEF INDY} | ||
Result := TNotifyApiIndy.New | ||
{$ELSE} | ||
Result := TNotifyApiNetHTTP.New; | ||
{$IFEND} | ||
end; | ||
|
||
class function TNotifyApiFactory.New: INotifyApiFactory; | ||
begin | ||
Result := Self.Create; | ||
end; | ||
|
||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs documenting in the README.md. It's effectively a part of your public interface "how to switch between Indy/NetHTTP".
Also, consider renaming this compiler define to
NTFY_INDY
. Consider, with such a generic define based on the name of a very popular network component set, what would happen if your library was included in other large projects that may have libraries with the same defines for other purposes? You may even consider having a more descriptive nameNTFY_DO_A_THING_WITH_INDY
so it becomes self-documenting when people include it in their projects.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking out for improvement. I'll make the necessary changes. I think
NTFY_INDY
is more descriptive name as you mentioned as it avoids clashing with other name that a large library might have. I'll also provide documentation of that in the README.md file. I'll update the files with the above review before merging.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhatherall, your review has been submitted. Thanks for your contribution.