Skip to content

Commit 6c8812c

Browse files
committed
Added command line argument to launch to tray
The argument is just "tray"
1 parent 07cb9ae commit 6c8812c

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

LightroomSync.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.6.33712.159
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightroomSync", "LightroomSync\LightroomSync.csproj", "{FD159443-4A90-46B8-A81A-6A80E96DBB79}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LightroomSync", "LightroomSync\LightroomSync.csproj", "{FD159443-4A90-46B8-A81A-6A80E96DBB79}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

LightroomSync/Form1.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private async Task UploadCatalogs()
243243
Log("Sucessfully updated all " + files.Length.ToString() + " catalog(s) to network share.");
244244
}
245245

246-
public Form1()
246+
public Form1(bool startMinimized)
247247
{
248248
InitializeComponent();
249249

@@ -263,13 +263,23 @@ public Form1()
263263
// Handle the form's Resize event
264264
this.Resize += OnResize;
265265
trayIcon.Click += OnRestore;
266+
267+
if (startMinimized)
268+
{
269+
this.WindowState = FormWindowState.Minimized;
270+
this.Hide();
271+
this.ShowInTaskbar = false;
272+
trayIcon.Visible = true;
273+
}
266274
}
267275

268276
private void OnRestore(object sender, EventArgs e)
269277
{
270278
// Restore the form from the system tray
271279
this.Show();
280+
this.ShowInTaskbar = true;
272281
this.WindowState = FormWindowState.Normal;
282+
trayIcon.Visible = false;
273283
}
274284

275285
private void OnExit(object sender, EventArgs e)

LightroomSync/Program.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ internal static class Program
66
/// The main entry point for the application.
77
/// </summary>
88
[STAThread]
9-
static void Main()
9+
static void Main(string[] args)
1010
{
1111
// To customize application configuration such as set high DPI settings or default font,
1212
// see https://aka.ms/applicationconfiguration.
1313
ApplicationConfiguration.Initialize();
14-
Application.Run(new Form1());
14+
15+
bool startMinimized = false;
16+
foreach (string argument in args)
17+
{
18+
if (argument == "tray")
19+
{
20+
startMinimized = true;
21+
}
22+
}
23+
24+
Application.Run(new Form1(startMinimized));
1525
}
1626
}
1727
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"LightroomSync": {
4+
"commandName": "Project"
5+
},
6+
"Launch To Tray": {
7+
"commandName": "Project",
8+
"commandLineArgs": "tray",
9+
"hotReloadEnabled": false
10+
}
11+
}
12+
}

LightroomSync/Utils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static void CreateShortcutInStartupFolder(string appPath)
2020
shortcut.TargetPath = appPath;
2121
shortcut.WorkingDirectory = Path.GetDirectoryName(appPath);
2222
shortcut.Description = "LightroomSync";
23+
shortcut.Arguments = "tray";
2324
shortcut.Save();
2425
}
2526

0 commit comments

Comments
 (0)