Skip to content

Commit

Permalink
add progress bar on load joplin
Browse files Browse the repository at this point in the history
+ add progress bar on load joplin
- fixed bug in loop
  • Loading branch information
shaoziyang committed Nov 28, 2022
1 parent 812bb11 commit 968149a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
22 changes: 18 additions & 4 deletions sources/Unit1.dfm
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
object FormMain: TFormMain
Left = 0
Top = 0
AlphaBlend = True
AlphaBlendValue = 150
BorderStyle = bsNone
Caption = 'FormMain'
ClientHeight = 202
ClientWidth = 333
ClientHeight = 241
ClientWidth = 387
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
Expand All @@ -23,6 +28,14 @@ object FormMain: TFormMain
TabOrder = 0
Visible = False
end
object pbBar: TProgressBar
Left = 8
Top = 177
Width = 360
Height = 36
Position = 50
TabOrder = 1
end
object tray: TTrayIcon
Icon.Data = {
000001000300101000000100080068050000360000003030000001002000A825
Expand Down Expand Up @@ -2641,7 +2654,7 @@ object FormMain: TFormMain
AutoHotkeys = maManual
Left = 184
Top = 56
object pmNotes: TMenuItem
object pmJoplinPortable: TMenuItem
Bitmap.Data = {
36100000424D3610000000000000360000002800000020000000200000000100
2000000000000010000000000000000000000000000000000000D3700F00CD6A
Expand Down Expand Up @@ -2773,7 +2786,8 @@ object FormMain: TFormMain
1B48EF8C1B48EE8B1A49EC891A49EB881949E9861949E8851849E6831549E582
1649E3801649E27F1549E17E1549E07D1448DE7B1248DD7A1349DB7812432B18
CF2CDB781102DE7B1100D8750F00D9761200DC791500D3700F00}
Caption = 'Joplin Portable'
Caption = 'JoplinPortable v2'
OnClick = pmJoplinPortableClick
end
object N2: TMenuItem
Caption = '-'
Expand Down
32 changes: 28 additions & 4 deletions sources/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ interface
IniFiles,
TLHelp32,
Menus,
StdCtrls;
StdCtrls,
ComCtrls;

const
GITHUB_URL = 'https://github.com/shaoziyang/JoplinPortable';


type
TFormMain = class(TForm)
Expand All @@ -27,20 +32,22 @@ TFormMain = class(TForm)
pmTray: TPopupMenu;
N1: TMenuItem;
pmExit: TMenuItem;
pmNotes: TMenuItem;
pmJoplinPortable: TMenuItem;
pmAdd: TMenuItem;
N3: TMenuItem;
pmnote: TMenuItem;
N2: TMenuItem;
mmoNotes: TMemo;
tmrWDG: TTimer;
pbBar: TProgressBar;
procedure pmExitClick(Sender: TObject);
procedure pmAddClick(Sender: TObject);
procedure pmnoteClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure tmrWDGTimer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure trayClick(Sender: TObject);
procedure pmJoplinPortableClick(Sender: TObject);
private
{ Private declarations }
WDGen: Boolean;
Expand Down Expand Up @@ -123,6 +130,7 @@ procedure TFormMain.CloseJoplin;
n := 100;
while n > 0 do
begin
n := n - 1;
Application.ProcessMessages;
Sleep(10);
joplin := FindWindow(nil, 'Joplin');
Expand Down Expand Up @@ -154,6 +162,8 @@ procedure TFormMain.FindNotes;

procedure TFormMain.FormCreate(Sender: TObject);
begin
pbBar.Position:=0;
FormMain.AutoSize:=True;
app_path := ExtractFilePath(Application.ExeName);
joplin_app := app_path + 'App\Joplin\Joplin.exe';
joplin_notes_path := app_path + 'Notes\';
Expand Down Expand Up @@ -234,6 +244,9 @@ procedure TFormMain.pmnoteClick(Sender: TObject);
begin
WDGen := False;
CloseJoplin;
Application.ShowMainForm := True;
FormMain.Show;
FormMain.BringToFront;

TMenuItem(Sender).Checked := True;
curNote := TMenuItem(Sender).Hint;
Expand All @@ -245,20 +258,31 @@ procedure TFormMain.pmnoteClick(Sender: TObject);
if n > 9 then n := 9;
tray.IconIndex := n;

n := 100;
pbBar.Max:=1000;
n := pbBar.Max;
while n > 0 do
begin
pbBar.Position := pbBar.Max - n;
n := n - 1;
Application.ProcessMessages;
Sleep(10);
if FindWindow(nil, 'Joplin') <> 0 then
begin
n := 0;
if n > pbBar.Max div 3 then
n := pbBar.Max div 3;
end;
end;
FormMain.Hide;
Application.ShowMainForm := False;
WDGen := True;
end;
end;

procedure TFormMain.pmJoplinPortableClick(Sender: TObject);
begin
ShellExecute(Handle, '',GITHUB_URL, '', '', SW_SHOW);
end;

procedure TFormMain.tmrWDGTimer(Sender: TObject);
begin
if WDGen then
Expand Down

0 comments on commit 968149a

Please sign in to comment.