@@ -60,8 +60,8 @@ Item {
6060 priv.mainStageAppId = focusedAppId;
6161 }
6262
63− appId0 = ApplicationManager.get(0).appId;
64− appId1 = ApplicationManager.get(1).appId;
63+ appId0 = ApplicationManager.count >= 1 ? ApplicationManager.get(0).appId : "";
64+ appId1 = ApplicationManager.count > 1 ? ApplicationManager.get(1).appId : "";
6565 }
6666
6767 function indexOf(appId) {
@@ -173,16 +173,20 @@ Item {
173173 return 1;
174174 }
175175 return 0;
176+ case "overlay":
177+ print("foo", priv.appId0, priv.appId1)
178+ return 1;
176179 }
177180 print("unhandled nextInStack case!!!!!");
178181 return -1;
182+
179183 }
180184 property int nextZInStack: indexToZIndex(nextInStack)
181185 onNextInStackChanged: print("next in stack is", nextInStack)
182186
183187 states: [
184188 State {
185− name: "invalid" // temporary until Dash is an app and we always have a main stage app
189+ name: "invalid"
186190 },
187191 State {
188192 name: "main"
@@ -246,10 +250,21 @@ Item {
246250 // We don't want to really reorder them in the model because that allows us to keep track
247251 // of the last focused order.
248252 function indexToZIndex(index) {
253+ print("zIndex calc for index", index);
249254 var app = ApplicationManager.get(index);
255+ if (!app) {
256+ return index;
257+ }
258+
250259 var isActive = app.appId == priv.mainStageAppId || app.appId == priv.sideStageAppId;
260+ print("got app", app.appId, isActive)
251261 if (isActive && app.stage == ApplicationInfoInterface.MainStage) return 0;
252262 if (isActive && app.stage == ApplicationInfoInterface.SideStage) {
263+ if (!priv.mainStageAppId) {
264+ // only have SS apps running
265+ return 0;
266+ }
267+
253268 if (spreadView.nextInStack >= 0 && ApplicationManager.get(spreadView.nextInStack).stage == ApplicationInfoInterface.MainStage) {
254269 return Math.max(index, 2);
255270 } else {
@@ -260,7 +275,7 @@ Item {
260275 return priv.indexOf(priv.sideStageAppId) < index ? index - 1 : index;
261276 }
262277 if (index == spreadView.nextInStack && app.stage == ApplicationInfoInterface.SideStage) {
263− if (priv.sideStageAppId) {
278+ if (priv.sideStageAppId && priv.mainStageAppId) {
264279 return 2;
265280 }
266281 return 1;
@@ -406,7 +421,9 @@ Item {
406421 sideStageDragHandle.dragging = true;
407422 }
408423 onMouseXChanged: {
409− sideStageDragHandle.progress = Math.max(0, (-startX + mouseX) / spreadView.sideStageWidth)
424+ if (priv.mainStageAppId) {
425+ sideStageDragHandle.progress = Math.max(0, (-startX + mouseX) / spreadView.sideStageWidth)
426+ }
410427 gesturePoints.push(mouseX);
411428 }
412429 onReleased: {