Skip to content
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

more git filters and notification center initialization for Windows OS #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,17 @@ __astcache/

# Boss dependency manager vendor folder https://github.com/HashLoad/boss
modules/

# Mac Finder and Windows Explorer files
.DS_Store
Thumbs.db

# Default Delphi compiler directories
Win32/
Win64/
OSX64/
OSXARM64/
Android/
Android64/
iOSDevice64/
Linux64/
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ object NotificationsForm: TNotificationsForm
FormFactor.Width = 1920
FormFactor.Height = 1022
FormFactor.Devices = [Desktop]
OnCreate = FormCreate
DesignerMasterStyle = 2
object btnSendScheduledNotification: TButton
Action = ActionSendScheduledNotification
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Copyright (c) 2016 Embarcadero Technologies, Inc. All rights reserved.
//
// This software is the copyrighted property of Embarcadero Technologies, Inc.
Expand All @@ -10,14 +10,14 @@
// as such term is defined thereunder. Your use of this software constitutes
// your acknowledgement of your agreement to the foregoing software license
// and support agreement.
//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
unit uMain;

interface

uses
System.Actions, System.Classes, System.Notification,
FMX.ActnList, FMX.Controls, FMX.Controls.Presentation, FMX.Forms, FMX.Memo,
FMX.ActnList, FMX.Controls, FMX.Controls.Presentation, FMX.Forms, FMX.Memo,
FMX.Memo.Types, FMX.ScrollBox, FMX.StdCtrls, FMX.Types;

type
Expand All @@ -37,13 +37,16 @@ TNotificationsForm = class(TForm)
ActionCancelScheduled: TAction;
ActionCancelAllNotifications: TAction;

procedure NotificationCPermissionRequestResult(Sender: TObject; const AIsGranted: Boolean);
procedure NotificationCReceiveLocalNotification(Sender: TObject; ANotification: TNotification);
procedure NotificationCPermissionRequestResult(Sender: TObject;
const AIsGranted: Boolean);
procedure NotificationCReceiveLocalNotification(Sender: TObject;
ANotification: TNotification);
procedure ActionListExecute(Action: TBasicAction; var Handled: Boolean);
procedure ActionSendScheduledNotificationExecute(Sender: TObject);
procedure ActionSendNotificationImmediatelyExecute(Sender: TObject);
procedure ActionCancelScheduledExecute(Sender: TObject);
procedure ActionCancelAllNotificationsExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FPendingAction: TBasicAction;
end;
Expand All @@ -57,8 +60,9 @@ implementation

uses
System.SysUtils;

procedure TNotificationsForm.NotificationCPermissionRequestResult(Sender: TObject; const AIsGranted: Boolean);

procedure TNotificationsForm.NotificationCPermissionRequestResult
(Sender: TObject; const AIsGranted: Boolean);
begin
if AIsGranted and (FPendingAction <> nil) then
begin
Expand All @@ -68,12 +72,14 @@ procedure TNotificationsForm.NotificationCPermissionRequestResult(Sender: TObjec
FPendingAction := nil;
end;

procedure TNotificationsForm.NotificationCReceiveLocalNotification(Sender: TObject; ANotification: TNotification);
procedure TNotificationsForm.NotificationCReceiveLocalNotification
(Sender: TObject; ANotification: TNotification);
begin
Memo1.Lines.Add(ANotification.AlertBody);
end;

procedure TNotificationsForm.ActionListExecute(Action: TBasicAction; var Handled: Boolean);
procedure TNotificationsForm.ActionListExecute(Action: TBasicAction;
var Handled: Boolean);
begin
if NotificationC.AuthorizationStatus <> TAuthorizationStatus.Authorized then
begin
Expand All @@ -84,9 +90,11 @@ procedure TNotificationsForm.ActionListExecute(Action: TBasicAction; var Handled
end;
end;

procedure TNotificationsForm.ActionSendScheduledNotificationExecute(Sender: TObject);
procedure TNotificationsForm.ActionSendScheduledNotificationExecute
(Sender: TObject);
begin
var Notification := NotificationC.CreateNotification;
var
Notification := NotificationC.CreateNotification;
try
Notification.Name := 'MyNotification';
Notification.AlertBody := 'Delphi for Mobile is here!';
Expand All @@ -100,9 +108,21 @@ procedure TNotificationsForm.ActionSendScheduledNotificationExecute(Sender: TObj
end;
end;

procedure TNotificationsForm.ActionSendNotificationImmediatelyExecute(Sender: TObject);
procedure TNotificationsForm.FormCreate(Sender: TObject);
begin
{$IFDEF MSWINDOWS}
// Windows needs a delay (some seconds) between initialization and presenting
// a notification to have the good title in first notification displayed in
// the life of a program
NotificationC.PlatformInitialize;
{$ENDIF}
end;

procedure TNotificationsForm.ActionSendNotificationImmediatelyExecute
(Sender: TObject);
begin
var Notification := NotificationC.CreateNotification;
var
Notification := NotificationC.CreateNotification;
try
Notification.AlertBody := 'Delphi for Mobile is here!';
Notification.FireDate := Now;
Expand All @@ -120,7 +140,8 @@ procedure TNotificationsForm.ActionCancelScheduledExecute(Sender: TObject);
NotificationC.CancelNotification('MyNotification');
end;

procedure TNotificationsForm.ActionCancelAllNotificationsExecute(Sender: TObject);
procedure TNotificationsForm.ActionCancelAllNotificationsExecute
(Sender: TObject);
begin
NotificationC.CancelAll;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object Notify: TNotify
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
ShowHint = False
OnCreate = FormCreate
OnShow = FormShow
DesignerMasterStyle = 0
object btnShow: TButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

// This software is Copyright (c) 2015 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
Expand All @@ -7,16 +7,18 @@
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.

//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

unit NotificationsForm;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls,
System.Notification, FMX.ScrollBox, FMX.Memo;
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls,
System.Notification, FMX.ScrollBox, FMX.Memo, FMX.Memo.Types;

type
TNotify = class(TForm)
Expand All @@ -30,15 +32,17 @@ TNotify = class(TForm)
lblLog: TLabel;
StyleBook1: TStyleBook;
procedure btnShowClick(Sender: TObject);
procedure NotificationCenter1ReceiveLocalNotification(Sender: TObject; ANotification: TNotification);
procedure NotificationCenter1ReceiveLocalNotification(Sender: TObject;
ANotification: TNotification);
procedure btnCancelAllClick(Sender: TObject);
procedure btnShowAnotherClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnCancelAnotherClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
//FNotificationCenter: TNotificationCenter;
// FNotificationCenter: TNotificationCenter;
public
{ Public declarations }
end;
Expand Down Expand Up @@ -66,13 +70,24 @@ procedure TNotify.btnShowClick(Sender: TObject);
end;
end;

procedure TNotify.FormCreate(Sender: TObject);
begin
{$IFDEF MSWINDOWS}
// Windows needs a delay (some seconds) between initialization and presenting
// a notification to have the good title in first notification displayed in
// the life of a program
NotificationCenter1.PlatformInitialize;
{$ENDIF}
end;

procedure TNotify.FormShow(Sender: TObject);
begin
OnShow := nil;
{$IFDEF MSWINDOWS}
if not TOSVersion.Check(6, 2) then // Windows 8
begin
ShowMessage('This demo is designed to show Notification feature in Windows 8 or higher. Bye.');
ShowMessage
('This demo is designed to show Notification feature in Windows 8 or higher. Bye.');
Application.Terminate;
end;
{$ENDIF MSWINDOWS}
Expand Down Expand Up @@ -109,7 +124,8 @@ procedure TNotify.btnCancelClick(Sender: TObject);
NotificationCenter1.CancelNotification('Windows10Notification');
end;

procedure TNotify.NotificationCenter1ReceiveLocalNotification(Sender: TObject; ANotification: TNotification);
procedure TNotify.NotificationCenter1ReceiveLocalNotification(Sender: TObject;
ANotification: TNotification);
begin
mmLog.Lines.Add('Notification received: ' + ANotification.Name);
end;
Expand Down
3 changes: 1 addition & 2 deletions Object Pascal/VCL/Windows 10 Notifications/Notifications.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ object NotificationsForm: TNotificationsForm
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object mmLog: TMemo
Left = 24
Expand Down
24 changes: 18 additions & 6 deletions Object Pascal/VCL/Windows 10 Notifications/Notifications.pas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

// This software is Copyright (c) 2015 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
Expand All @@ -7,14 +7,15 @@
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.

//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

unit Notifications;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Notification, Vcl.StdCtrls;

type
Expand All @@ -34,6 +35,7 @@ TNotificationsForm = class(TForm)
procedure btnShowAnotherClick(Sender: TObject);
procedure btnCancelAnotherClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
Expand Down Expand Up @@ -94,21 +96,31 @@ procedure TNotificationsForm.btnShowClick(Sender: TObject);
end;
end;

procedure TNotificationsForm.FormCreate(Sender: TObject);
begin
{$IFDEF MSWINDOWS}
// Windows needs a delay (some seconds) between initialization and presenting
// a notification to have the good title in first notification displayed in
// the life of a program
NotificationCenter1.PlatformInitialize;
{$ENDIF}
end;

procedure TNotificationsForm.FormShow(Sender: TObject);
begin
OnShow := nil;
{$IFDEF MSWINDOWS}
if not TOSVersion.Check(6, 2) then // Windows 8
begin
ShowMessage('This demo is designed to show Notification feature in Windows 8 or higher. Bye.');
ShowMessage
('This demo is designed to show Notification feature in Windows 8 or higher. Bye.');
Application.Terminate;
end;
{$ENDIF MSWINDOWS}
end;

procedure TNotificationsForm.NotificationCenter1ReceiveLocalNotification(Sender: TObject;
ANotification: TNotification);
procedure TNotificationsForm.NotificationCenter1ReceiveLocalNotification
(Sender: TObject; ANotification: TNotification);
begin
mmLog.Lines.Add('Notification received: ' + ANotification.Name);
end;
Expand Down