Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Add auto start option to open all profiles when Windows starts
Browse files Browse the repository at this point in the history
  • Loading branch information
TonCunha committed May 26, 2020
1 parent ed6d801 commit c5f72d4
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 21 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ Launcher to manage profiles and open multiple instances of Microsoft Teams deskt
* .NET Core
* WPF
* [MahApps](https://mahapps.com/)
* [WPF NotifyIcon](https://github.com/hardcodet/wpf-notifyicon)

## Prerequisites

* Microsoft Teams
* .NET Core

## Releases
You can download the latest version in [Releases](https://github.com/TonCunha/multi-microsoft-teams/releases)

## Deployment

1. Open project in Visual Studio
Expand All @@ -31,12 +35,9 @@ Launcher to manage profiles and open multiple instances of Microsoft Teams deskt
### Configure Multi Teams
1. Open Multi Microsoft Teams
2. Create all the profiles you need by clicking the New profile button
3. Select a profile or check All profiles and Launch Teams
3. Select a profile and Launch Teams
4. Uncheck the options auto-start application in all Microsoft Teams

## After initial configurations
1. Open Multi Microsoft Teams
2. Select a profile or check All profiles and Launch Teams
5. You can check Auto Start option to launch all profiles when Windows starts

## Authors

Expand Down
4 changes: 4 additions & 0 deletions src/MMT.Core/MMT.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/MMT.Core/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Delete(string profileName)
string path = Path.Combine(_customProfilesPath, profileName);

if (Directory.Exists(path))
Directory.Delete(path);
Directory.Delete(path, true);
}
}
}
30 changes: 30 additions & 0 deletions src/MMT.Core/RegistryMananger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Win32;
using System.Diagnostics;

namespace MMT.Core
{
public class RegistryManager
{
private readonly RegistryKey _registryKey;

public RegistryManager()
{
_registryKey = Registry.CurrentUser.OpenSubKey(StaticResources.StartupApplications, true);
}

public bool IsApplicationInStartup(string name)
{
return _registryKey.GetValue(name) != null;
}

public void AddApplicationInStartup(string name)
{
_registryKey.SetValue(name, Process.GetCurrentProcess().MainModule.FileName); //AppDomain.CurrentDomain.BaseDirectory);
}

public void RemoveApplicationFromStartup(string appName)
{
_registryKey.DeleteValue(appName, false);
}
}
}
16 changes: 16 additions & 0 deletions src/MMT.Core/StaticResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,21 @@ public static string UpdateExe
return @"AppData\Local\Microsoft\Teams\Update.exe";
}
}

public static string StartupApplications
{
get
{
return @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
}
}

public static string AppName
{
get
{
return "Multi MS Teams";
}
}
}
}
22 changes: 21 additions & 1 deletion src/MMT.UI/MMT.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
<PackageProjectUrl>https://github.com/TonCunha/multi-microsoft-teams</PackageProjectUrl>
<Copyright>Cleriton Cunha</Copyright>
<Description>Launcher to manage profiles and open multiple instances of Microsoft Teams</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyVersion>1.0.0.1</AssemblyVersion>
<FileVersion>1.0.0.1</FileVersion>
<Version>1.0.0.1</Version>
<Win32Resource />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf.NetCore" Version="1.0.10" />
<PackageReference Include="MahApps.Metro" Version="2.0.0-alpha0821" />
</ItemGroup>

Expand All @@ -30,4 +35,19 @@
</None>
</ItemGroup>

<ItemGroup>
<Compile Update="Resource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
11 changes: 5 additions & 6 deletions src/MMT.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:MMT.UI"
mc:Ignorable="d"
Title="Multi Microsoft Teams" Height="250" Width="400" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize">
Title="Multi Microsoft Teams" Height="250" Width="400" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" StateChanged="MetroWindow_StateChanged">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" HorizontalAlignment="Right" Margin="10">
<Hyperlink NavigateUri="https://github.com/TonCunha/multi-microsoft-teams" RequestNavigate="Hyperlink_RequestNavigate">
Github
</Hyperlink>
</TextBlock>

<TabControl Grid.RowSpan="2" Name="tbcMain">
<TabControl Grid.RowSpan="1" Name="tbcMain">
<TabItem Name="tbiProfiles" Header="Profiles">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -32,7 +31,7 @@
<Grid Grid.Row="1" Margin="5" Height="Auto">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Button Name="btnLaunchTeams" Width="100" Content="Launch Teams" Click="BtnLaunchTeams_Click"/>
<CheckBox Name="chkAllProfiles" Margin="8,0,0,0" HorizontalAlignment="Left" Content="All profiles"/>
<CheckBox Name="chkAutoStart" Margin="8,0,0,0" HorizontalAlignment="Left" Content="Auto start" Click="ChkAutoStart_Click"/>
</StackPanel>
<Button Name="btnNewProfile" HorizontalAlignment="Right" Width="100" Content="New profile" Click="BtnNewProfile_Click"/>
</Grid>
Expand Down
78 changes: 70 additions & 8 deletions src/MMT.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using MahApps.Metro.Controls;
using Hardcodet.Wpf.TaskbarNotification;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using MMT.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Navigation;
Expand All @@ -13,14 +15,19 @@ namespace MMT.UI
public partial class MainWindow : MetroWindow
{
private readonly ProfileManager _profileManager;
private TeamsLauncher _teamsLauncher;
private readonly TeamsLauncher _teamsLauncher;
private readonly RegistryManager _registryManager;
private TaskbarIcon _tray;

public MainWindow()
{
InitializeComponent();
_profileManager = new ProfileManager();
_teamsLauncher = new TeamsLauncher();
_registryManager = new RegistryManager();
ChangeTabVisibility();
CreateTray();
AutoStartCheck();
}

private void ChangeTabVisibility()
Expand All @@ -47,6 +54,64 @@ private void LoadProfiles()
profiles.ForEach(p => lstProfiles.Items.Add(p));
}

private void CreateTray()
{
_tray = new TaskbarIcon();
_tray.Icon = Resource.Taskbar;
_tray.TrayMouseDoubleClick += TrayMouseDoubleClick;
_tray.ToolTipText = StaticResources.AppName;
_tray.Visibility = Visibility.Collapsed;
}

private void TrayMouseDoubleClick(object sender, RoutedEventArgs e)
{
Show();
WindowState = WindowState.Normal;
MetroWindow_StateChanged(sender, e);
}

private void AutoStartCheck()
{
chkAutoStart.IsChecked = _registryManager.IsApplicationInStartup(StaticResources.AppName);

if (chkAutoStart.IsChecked.HasValue && chkAutoStart.IsChecked.Value)
{
Show();
WindowState = WindowState.Minimized;
MetroWindow_StateChanged(null, null);

var thread = new Thread(() =>
{
foreach (var item in lstProfiles.Items)
_teamsLauncher.Start(item.ToString());
});
thread.Start();
}
}

private void MetroWindow_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
Visibility = Visibility.Collapsed;
_tray.Visibility = Visibility.Visible;
_tray.ShowBalloonTip(StaticResources.AppName, "This app is running", BalloonIcon.Info);
}
else
{
_tray.Visibility = Visibility.Collapsed;
Visibility = Visibility.Visible;
}
}

private void ChkAutoStart_Click(object sender, RoutedEventArgs e)
{
if (chkAutoStart.IsChecked.HasValue && chkAutoStart.IsChecked.Value)
_registryManager.AddApplicationInStartup(StaticResources.AppName);
else if (_registryManager.IsApplicationInStartup(StaticResources.AppName))
_registryManager.RemoveApplicationFromStartup(StaticResources.AppName);
}

private void BtnNewProfile_Click(object sender, RoutedEventArgs e)
{
txtProfileName.Clear();
Expand Down Expand Up @@ -76,10 +141,7 @@ private void BtnLaunchTeams_Click(object sender, RoutedEventArgs e)
{
try
{
if (chkAllProfiles.IsChecked.HasValue && chkAllProfiles.IsChecked.Value)
foreach (var item in lstProfiles.Items)
_teamsLauncher.Start(item.ToString());
else if (lstProfiles.SelectedItem != null)
if (lstProfiles.SelectedItem != null)
_teamsLauncher.Start(lstProfiles.SelectedItem.ToString());
}
catch (Exception ex)
Expand All @@ -89,7 +151,7 @@ private void BtnLaunchTeams_Click(object sender, RoutedEventArgs e)
}
}

private async void LstProfiles_KeyUp(object sender, KeyEventArgs e)
private async void LstProfiles_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Delete)
{
Expand All @@ -104,7 +166,7 @@ private async void LstProfiles_KeyUp(object sender, KeyEventArgs e)

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
}
}
}
73 changes: 73 additions & 0 deletions src/MMT.UI/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5f72d4

Please sign in to comment.