Skip to content

Commit 25fa519

Browse files
committed
uniqueinstanceraw.pas, uniqueinstancebase.pas und 6 weitere dateien aktualisiert...
opsi_client_systray 4.1.2.0 * switch to lazarus 2.0.8 * added uniqueinstance -- Detlef Oertel <[email protected]> Tue, 12 May 2020:15:00:00 +0200
1 parent 9e3b69c commit 25fa519

File tree

11 files changed

+448
-2
lines changed

11 files changed

+448
-2
lines changed

helper/opsi-client-systray/oca_systray.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11

22
[changelog]
3+
opsi_client_systray 4.1.2.0
4+
5+
* switch to lazarus 2.0.8
6+
* added uniqueinstance
7+
8+
-- Detlef Oertel <[email protected]> Tue, 12 May 2020:15:00:00 +0200
9+
310
opsi_client_systray 4.1.1.0
411

512
* switch to lazarus 2.0.6 / oswebservice with synapse and opsi 4.2 compatibility

helper/opsi-client-systray/oca_systray_dm.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface
1616
lcltranslator,
1717
windows,
1818
osprocesses,
19+
uniqueinstanceraw,
1920
jwawinbase;
2021

2122
type
@@ -29,6 +30,7 @@ TDataModule1 = class(TDataModule)
2930
PopupMenu1: TPopupMenu;
3031
Timer1: TTimer;
3132
TrayIcon1: TTrayIcon;
33+
//uniqueinstance1 : Tuniqueinstance;
3234
procedure DataModuleCreate(Sender: TObject);
3335
procedure MI_exitClick(Sender: TObject);
3436
procedure MI_pull_for_action_requestClick(Sender: TObject);
@@ -287,6 +289,7 @@ procedure TDataModule1.DataModuleCreate(Sender: TObject);
287289
service_url_port : string;
288290
mylang : string;
289291
begin
292+
if InstanceRunning then Application.Terminate;
290293
checkIntervall := 0;
291294
myNotifyFormat := 'productid : request';
292295
myservice_url := 'https://localhost:4441/kiosk';

helper/opsi-client-systray/opsi_client_systray.lpi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<UseVersionInfo Value="True"/>
2323
<MajorVersionNr Value="4"/>
2424
<MinorVersionNr Value="1"/>
25-
<RevisionNr Value="1"/>
25+
<RevisionNr Value="2"/>
2626
<StringTable CompanyName="uib gmbh / opsi.org" InternalName="opsi-client-systray" LegalCopyright="AGPLv3" LegalTrademarks="opsi, opsi.org, open pc server integration" OriginalFilename="opsi-client-systray" ProductName="opsi / opsi.org" ProductVersion="4.1.0.0"/>
2727
</VersionInfo>
2828
<BuildModes Count="3">
@@ -85,7 +85,7 @@
8585
</Target>
8686
<SearchPaths>
8787
<IncludeFiles Value="$(ProjOutDir)"/>
88-
<OtherUnitFiles Value="..\..\common;..\..\external_libraries\misc;..\..\external_libraries\synapse"/>
88+
<OtherUnitFiles Value="..\..\common;..\..\external_libraries\misc;..\..\external_libraries\synapse;..\..\lazlib\uniqueinstance"/>
8989
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
9090
</SearchPaths>
9191
<CodeGeneration>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
unit registeruniqueinstance;
2+
3+
{$Mode ObjFpc}
4+
{$H+}
5+
6+
interface
7+
8+
uses
9+
Classes, SysUtils, LResources, LazarusPackageIntf,uniqueinstance;
10+
11+
procedure Register;
12+
13+
implementation
14+
15+
procedure RegisterUnitUniqueInstance;
16+
begin
17+
RegisterComponents('System',[TUniqueInstance]);
18+
end;
19+
20+
procedure Register;
21+
22+
begin
23+
RegisterUnit('uniqueinstance',@RegisterUnitUniqueInstance);
24+
end;
25+
26+
initialization
27+
{$i uniqueicon.lrs}
28+
29+
end.
388 Bytes
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
LazarusResources.Add('tuniqueinstance','PNG',[
2+
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
3+
+#0#0#9'pHYs'#0#0#14#195#0#0#14#195#1#199'o'#168'd'#0#0#1'6IDATH'#137#157#148
4+
+'1'#18#132' '#12'E'#131'C'#165#167#176#183#247'T'#244#30'a{'#251'='#202#246
5+
+#158#194'S'#172'-['#184'q'#146#240#131#236'f'#134#17#16#255#251#137'@'#160
6+
+#198#200#203#146#233#253#190#198'a]C'#203'w'#213'E9'#165#172'&'#4#128#134#161
7+
+#9#6'_('#183'R'#212#1'p'#31#129#138#137#203#245#31#0#26#134#2#162#6'J'#252'O'
8+
+#128#133't'#151#248#178'`q'#219'^/</'#214#203#127#23#149';$.'#157'o'#27#206
9+
+#132#199#178'/KT'#148#198#194'X'#152'c'#154#220#242#200#22#214'5'#224#12'l'
10+
+#221#199#241#236#239#187#206#128#29'3'#196#184'''"'#138#246#0#221#2#29'!'#149
11+
+#205'7rJ9'#226#149' Zv'#19#136#8#235#142'\'#203'8'#14#162#190#247#13'('#192
12+
+#157'kn'#199'QBd8'#153#212#1#181#244#251'^'#239#26'''bU'#196'+'#147'-'#15#155
13+
+#1#173#11#143'G'#211#181'[\'#13'7'#206#137#200#156#131#154#160#247#206#30'2'
14+
+#4#225'NN)7'#159'd'#142'irOrx>'#3#145#247#147#173#155'y>'#159'v'#255'K'#231
15+
+'N'#22#229'u'#237']x'#8'`a'#223'>'#187'/'#0'.'#164#5#0#196'!@A~'#4'Xq'#23#0
16+
+'A'#21#0#18'n'#2#212'`5Q'#25#31'('#18#253#217#188'R'#195'&'#0#0#0#0'IEND'#174
17+
+'B`'#130
18+
]);
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
unit UniqueInstance;
2+
3+
{
4+
UniqueInstance is a component to allow only a instance by program
5+
6+
Copyright (C) 2006 Luiz Americo Pereira Camara
7+
8+
9+
This library is free software; you can redistribute it and/or modify it
10+
under the terms of the GNU Library General Public License as published by
11+
the Free Software Foundation; either version 2 of the License, or (at your
12+
option) any later version with the following modification:
13+
14+
As a special exception, the copyright holders of this library give you
15+
permission to link this library with independent modules to produce an
16+
executable, regardless of the license terms of these independent modules,and
17+
to copy and distribute the resulting executable under terms of your choice,
18+
provided that you also meet, for each linked independent module, the terms
19+
and conditions of the license of that module. An independent module is a
20+
module which is not derived from or based on this library. If you modify
21+
this library, you may extend this exception to your version of the library,
22+
but you are not obligated to do so. If you do not wish to do so, delete this
23+
exception statement from your version.
24+
25+
This program is distributed in the hope that it will be useful, but WITHOUT
26+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
28+
for more details.
29+
30+
You should have received a copy of the GNU Library General Public License
31+
along with this library; if not, write to the Free Software Foundation,
32+
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33+
}
34+
35+
36+
{$mode objfpc}{$H+}
37+
{$if not defined(Windows) or (FPC_FULLVERSION >= 30001)}
38+
{$define PollIPCMessage}
39+
{$endif}
40+
41+
interface
42+
43+
uses
44+
Forms, Classes, SysUtils, simpleipc, ExtCtrls;
45+
46+
type
47+
48+
TOnOtherInstance = procedure (Sender : TObject; ParamCount: Integer; const Parameters: array of String) of object;
49+
50+
{ TUniqueInstance }
51+
52+
TUniqueInstance = class(TComponent)
53+
private
54+
FIdentifier: String;
55+
FOnOtherInstance: TOnOtherInstance;
56+
FUpdateInterval: Cardinal;
57+
FEnabled: Boolean;
58+
FPriorInstanceRunning: Boolean;
59+
procedure ReceiveMessage(Sender: TObject);
60+
{$ifdef PollIPCMessage}
61+
procedure CheckMessage(Sender: TObject);
62+
{$endif}
63+
protected
64+
procedure Loaded; override;
65+
public
66+
constructor Create(AOwner: TComponent); override;
67+
property PriorInstanceRunning: Boolean read FPriorInstanceRunning;
68+
published
69+
property Enabled: Boolean read FEnabled write FEnabled default False;
70+
property Identifier: String read FIdentifier write FIdentifier;
71+
property UpdateInterval: Cardinal read FUpdateInterval write FUpdateInterval default 1000;
72+
property OnOtherInstance: TOnOtherInstance read FOnOtherInstance write FOnOtherInstance;
73+
end;
74+
75+
implementation
76+
77+
uses
78+
StrUtils, UniqueInstanceBase;
79+
80+
{ TUniqueInstance }
81+
82+
procedure TUniqueInstance.ReceiveMessage(Sender: TObject);
83+
var
84+
ParamsArray: array of String;
85+
Params: String;
86+
Count, i: Integer;
87+
begin
88+
if Assigned(FOnOtherInstance) then
89+
begin
90+
//MsgType stores ParamCount
91+
Count := FIPCServer.MsgType;
92+
SetLength(ParamsArray, Count);
93+
Params := FIPCServer.StringMessage;
94+
for i := 1 to Count do
95+
ParamsArray[i - 1] := ExtractWord(i, Params, [ParamsSeparator]);
96+
FOnOtherInstance(Self, Count, ParamsArray);
97+
end;
98+
end;
99+
100+
{$ifdef PollIPCMessage}
101+
procedure TUniqueInstance.CheckMessage(Sender: TObject);
102+
begin
103+
FIPCServer.PeekMessage(1, True);
104+
end;
105+
{$endif}
106+
107+
procedure TUniqueInstance.Loaded;
108+
var
109+
IPCClient: TSimpleIPCClient;
110+
{$ifdef PollIPCMessage}
111+
Timer: TTimer;
112+
{$endif}
113+
begin
114+
if not (csDesigning in ComponentState) and FEnabled then
115+
begin
116+
IPCClient := TSimpleIPCClient.Create(Self);
117+
IPCClient.ServerId := GetServerId(FIdentifier);
118+
if not Assigned(FIPCServer) and IPCClient.ServerRunning then
119+
begin
120+
//A older instance is running.
121+
FPriorInstanceRunning := True;
122+
//A instance is already running
123+
//Send a message and then exit
124+
if Assigned(FOnOtherInstance) then
125+
begin
126+
IPCClient.Active := True;
127+
IPCClient.SendStringMessage(ParamCount, GetFormattedParams);
128+
end;
129+
Application.ShowMainForm := False;
130+
Application.Terminate;
131+
end
132+
else
133+
begin
134+
if not Assigned(FIPCServer) then
135+
InitializeUniqueServer(IPCClient.ServerID);
136+
FIPCServer.OnMessage := @ReceiveMessage;
137+
//there's no more need for IPCClient
138+
IPCClient.Destroy;
139+
{$ifdef PollIPCMessage}
140+
if Assigned(FOnOtherInstance) then
141+
begin
142+
Timer := TTimer.Create(Self);
143+
Timer.Interval := FUpdateInterval;
144+
Timer.OnTimer := @CheckMessage;
145+
end;
146+
{$endif}
147+
end;
148+
end;//if
149+
inherited;
150+
end;
151+
152+
constructor TUniqueInstance.Create(AOwner: TComponent);
153+
begin
154+
inherited Create(AOwner);
155+
FUpdateInterval := 1000;
156+
end;
157+
158+
end.
159+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<Package Version="4">
4+
<PathDelim Value="\"/>
5+
<Name Value="uniqueinstance_package"/>
6+
<Type Value="RunAndDesignTime"/>
7+
<Author Value="Luiz Américo Pereira Câmara"/>
8+
<CompilerOptions>
9+
<Version Value="11"/>
10+
<PathDelim Value="\"/>
11+
<SearchPaths>
12+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)"/>
13+
</SearchPaths>
14+
<Parsing>
15+
<SyntaxOptions>
16+
<UseAnsiStrings Value="False"/>
17+
</SyntaxOptions>
18+
</Parsing>
19+
<CodeGeneration>
20+
<Optimizations>
21+
<OptimizationLevel Value="2"/>
22+
</Optimizations>
23+
</CodeGeneration>
24+
</CompilerOptions>
25+
<Description Value="UniqueInstance provides a component to limits one instance per application"/>
26+
<License Value="Modified LGPL"/>
27+
<Version Major="1" Minor="1"/>
28+
<Files Count="4">
29+
<Item1>
30+
<Filename Value="uniqueinstance.pas"/>
31+
<UnitName Value="UniqueInstance"/>
32+
</Item1>
33+
<Item2>
34+
<Filename Value="uniqueinstanceraw.pas"/>
35+
<UnitName Value="UniqueInstanceRaw"/>
36+
</Item2>
37+
<Item3>
38+
<Filename Value="registeruniqueinstance.pas"/>
39+
<HasRegisterProc Value="True"/>
40+
<UnitName Value="registeruniqueinstance"/>
41+
</Item3>
42+
<Item4>
43+
<Filename Value="uniqueinstancebase.pas"/>
44+
<UnitName Value="UniqueInstanceBase"/>
45+
</Item4>
46+
</Files>
47+
<RequiredPkgs Count="1">
48+
<Item1>
49+
<PackageName Value="LCL"/>
50+
</Item1>
51+
</RequiredPkgs>
52+
<UsageOptions>
53+
<UnitPath Value="$(PkgOutDir)"/>
54+
</UsageOptions>
55+
<PublishOptions>
56+
<Version Value="2"/>
57+
<IgnoreBinaries Value="False"/>
58+
</PublishOptions>
59+
</Package>
60+
</CONFIG>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ This file was automatically created by Lazarus. Do not edit!
2+
This source is only used to compile and install the package.
3+
}
4+
5+
unit uniqueinstance_package;
6+
7+
interface
8+
9+
uses
10+
UniqueInstance, UniqueInstanceRaw, registeruniqueinstance,
11+
UniqueInstanceBase, LazarusPackageIntf;
12+
13+
implementation
14+
15+
procedure Register;
16+
begin
17+
RegisterUnit('registeruniqueinstance', @registeruniqueinstance.Register);
18+
end;
19+
20+
initialization
21+
RegisterPackage('uniqueinstance_package', @Register);
22+
end.

0 commit comments

Comments
 (0)