Skip to content

Commit

Permalink
Enforce auto-generated usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
Loginer von Web committed Sep 16, 2015
1 parent 27a5fbd commit cb488c2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
8 changes: 6 additions & 2 deletions Albedo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ void AppStartup(object sender, StartupEventArgs e)
Platform.WriteSetting("newVersion", false);
Platform.SaveSettings();
}

if (Platform.ReadSetting("bridgeIP") != "0.0.0.0") {
string username = Platform.ReadSetting("bridgeUserName");
if (Platform.ReadSetting("bridgeIP") != "0.0.0.0" && !username.Contains("albedo")) {
Storage.InitializeData();
} else {
if (username.Contains("albedo")) { //Usernames must be auto-generated by the end of 2015
System.Windows.MessageBox.Show("Due to a software update that changes the way apps pair with the bridge, Albedo will need to re-run the pairing wizard.\nSorry for the inconvenience.");
}

WindowStorage.setupStorage = new SetupWindow();
WindowStorage.setupStorage.Show();
}
Expand Down
2 changes: 1 addition & 1 deletion Albedo/Core/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async public static Task PairAttempt(string bridgeIP, string bridgeUser) {
devicetype = devicetype.Substring(0, 40);
}
dynContent.devicetype = devicetype;
dynContent.username = bridgeUser;
//dynContent.username = bridgeUser; //OBSOLETE. Username is now assigned by the bridge.
StringContent content = new StringContent(JsonParser.Serialize(dynContent));

Task<HttpResponseMessage> postData = client.PostAsync(address, content);
Expand Down
3 changes: 2 additions & 1 deletion Albedo/DummyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static void ToolTipUpdate()

private bool Ready()
{
if (Platform.ReadSetting("bridgeIP") == "0.0.0.0") {
string username = Platform.ReadSetting("bridgeUserName");
if (Platform.ReadSetting("bridgeIP") != "0.0.0.0" && !username.Contains("albedo")) {
return false;
} else {
return true;
Expand Down
5 changes: 5 additions & 0 deletions Albedo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public void SetInfo()
slidersAllowed = false;
int i = 1;

string username = Platform.ReadSetting("bridgeUserName");
if (username.Contains("albedo")) {
return;
}

//Populate Lights tab
foreach (string lightLabel in Storage.groupData.lights) {
if (i <= 5) {
Expand Down
2 changes: 1 addition & 1 deletion Albedo/SetupWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<Button Content="Close" HorizontalAlignment="Left" Margin="460,297,0,0" VerticalAlignment="Top" Width="200" Height="50" FontSize="22" FontFamily="Segoe UI Semilight" Click="Close_Click" />
<TextBlock HorizontalAlignment="Left" Margin="10,87,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Height="205" Width="650" FontSize="16" FontFamily="Segoe UI Semilight" Text=
"By default, Windows hides new notification icons. You can pin Albedo to the taskbar by following the instructions below. This step is optional, but highly recommended.&#xA;&#xA;Close this window to complete the tutorial."/>
"By default, Windows hides new notification icons. You can pin Albedo to the taskbar by following the instructions below. This step is optional, but highly recommended.&#xA;If you're on Windows 10, drag the icon to the taskbar to pin it.&#xA;Close this window to complete the tutorial."/>
<Image HorizontalAlignment="Left" Height="103" VerticalAlignment="Top" Width="550" Source="Resources/albedo_pin_instructions.png" Margin="65,189,0,0"/>
</Grid>
</TabItem>
Expand Down
30 changes: 23 additions & 7 deletions Albedo/SetupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public override string ToString()
int tutStep = 1;
string bridgeIP;
string bridgeUser;
bool newUsername = false;

public SetupWindow()
{
Expand All @@ -58,6 +59,15 @@ public SetupWindow()
async private void StartIndex()
{
await Task.Delay(100); //Makes sure TabControl animation triggers

string username = Platform.ReadSetting("bridgeUserName");
if (username.Contains("albedo")) {
bridgeIP = Platform.ReadSetting("bridgeIP");
newUsername = true;
SetupTabs.SelectedIndex = 3;
return;
}

SetupTabs.SelectedIndex = 1;
return;
}
Expand Down Expand Up @@ -99,15 +109,19 @@ private void SetupTabs_SelectionChanged(object sender, SelectionChangedEventArgs
{
if (SetupTabs.SelectedIndex == 3) {
Search(false);
ComboItem bridge = (ComboItem)BridgeCombo.SelectedItem;
if (BridgeCombo.SelectedIndex != -1) {
bridgeIP = bridge.idStore;
} else {
bridgeIP = ManualIP.Text;
if (!newUsername) {
ComboItem bridge = (ComboItem)BridgeCombo.SelectedItem;
if (BridgeCombo.SelectedIndex != -1) {
bridgeIP = bridge.idStore;
} else {
bridgeIP = ManualIP.Text;
}
}

Pair(true);
} else if (SetupTabs.SelectedIndex < 3) {
Pair(false);
newUsername = false;
Search(true);
} else {
Pair(false);
Expand Down Expand Up @@ -190,10 +204,12 @@ private void PairEvent(Object source, ElapsedEventArgs e)
{
this.Dispatcher.Invoke((Action)(async () =>
{
await Setup.PairAttempt(bridgeIP, bridgeUser);
await Setup.PairAttempt(bridgeIP, bridgeUser); //bridgeUser isn't actually used anymore
if (JsonParser.Read(Storage.tempData, new string[] { "success" }) != null) {
string generatedName = JsonParser.Read(Storage.tempData, new string[] { "success", "username" });
Properties.Settings.Default.bridgeIP = bridgeIP;
Properties.Settings.Default.bridgeUserName = bridgeUser;
Properties.Settings.Default.bridgeUserName = generatedName;
Properties.Settings.Default.Save();
this.SetupTabs.SelectedIndex++;
Storage.InitializeData();
Expand Down

0 comments on commit cb488c2

Please sign in to comment.