Skip to content

Commit 8d4f3be

Browse files
committed
small mobile fixes
1 parent 89fb4dc commit 8d4f3be

4 files changed

Lines changed: 100 additions & 101 deletions

File tree

OpenFlow/src/public/CommonControllers.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ module openflow {
2727
static $inject = ["$rootScope", "$location", "WebSocketClient"];
2828
public messageQueue: IHashTable<messagequeue> = {};
2929
constructor(public $rootScope: ng.IRootScopeService, public $location, public WebSocketClient: WebSocketClient) {
30-
var isChrome = navigator.userAgent.indexOf("Chrome") !== -1;
31-
var formerlog = console.log.bind(console);
32-
var formerwarn = console.warn.bind(console);
33-
var formerdebug = console.debug.bind(console);
34-
var me = this;
35-
3630
['log', 'warn', 'debug', 'error'].forEach((methodName) => {
3731
//['error'].forEach((methodName) => {
3832
const originalMethod = console[methodName];
@@ -350,7 +344,7 @@ module openflow {
350344
// attrs.$observe('i18n', function (newVal, oldVal) {
351345
// });
352346
//scope.$watch(watchFunction, () => {
353-
if (attr.value !== null && attr.value !== undefined) {
347+
if (attr.value !== null && attr.value !== undefined && element[0].tagName !== "OPTION") {
354348
value = calculateValue(attr.value);
355349
attr.$set('value', value);
356350
} else {

OpenFlow/src/public/Controllers.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,16 @@ module openflow {
542542
QRScanner.hide();
543543
QRScanner.destroy();
544544

545-
console.log("set mobiledomain to " + value);
546-
await this.writefile("mobiledomain.txt", value);
547-
548545
this.scanning = false;
549546
if (!this.$scope.$$phase) { this.$scope.$apply(); }
550-
if (value !== null && value !== undefined && value !== "") {
551-
console.log(value);
552-
var config = JSON.parse(value);
547+
if (value === null || value === undefined || value === "") {
548+
console.log("QRCode had null value"); return;
549+
}
550+
console.log("QRCode value: " + value);
551+
var config = JSON.parse(value);
552+
if (config.url !== null || config.url !== undefined || config.url !== "" || config.loginurl !== null || config.loginurl !== undefined || config.loginurl !== "") {
553+
console.log("set mobiledomain to " + value);
554+
await this.writefile("mobiledomain.txt", value);
553555
window.location.replace(config.url);
554556
}
555557
} catch (error) {
@@ -1580,6 +1582,7 @@ module openflow {
15801582
this.messages += "GetNoderedInstance completed, status " + this.instancestatus + "\n";
15811583
} catch (error) {
15821584
this.messages += error + "\n";
1585+
this.instancestatus = "";
15831586
console.error(error);
15841587
}
15851588
if (!this.$scope.$$phase) { this.$scope.$apply(); }
@@ -1591,8 +1594,10 @@ module openflow {
15911594
this.instancelog = await this.api.GetNoderedInstanceLog();
15921595
this.instancelog = this.instancelog.split("\n").reverse().join("\n");
15931596
this.messages += "GetNoderedInstanceLog completed\n";
1597+
this.instancestatus = "";
15941598
} catch (error) {
15951599
this.messages += error + "\n";
1600+
this.instancestatus = "";
15961601
console.error(error);
15971602
}
15981603
if (!this.$scope.$$phase) { this.$scope.$apply(); }

OpenFlow/src/public/WebSocketClient.ts

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/// <reference path='ReconnectingWebSocket.ts' />
22
module openflow {
33
// "use strict";
4-
5-
var doLoadMobileData: boolean = false;
64
interface IHashTable<T> {
75
[key: string]: T;
86
}
@@ -39,6 +37,7 @@ module openflow {
3937
public jwt: string = null;
4038
public device: any = null;
4139
public usingCordova: boolean = false;
40+
public scanCount: number = 0;
4241
public oneSignalId: string = null;
4342
public location: any;
4443
static $inject = ["$rootScope", "$location", "$window"];
@@ -174,7 +173,92 @@ module openflow {
174173
});
175174
});
176175
}
176+
scanForCordova() {
177+
try {
178+
if (cordova !== undefined) {
179+
console.log("Found cordova");
180+
this.usingCordova = true;
181+
document.addEventListener("deviceready", async () => {
182+
console.log("deviceready");
183+
if ((window as any).plugins) {
184+
var oneSignal = (window as any).plugins.OneSignal;
185+
if (oneSignal) {
186+
try {
187+
console.debug("window.plugins.OneSignal exists");
188+
189+
const sender_id = "906036108091"; // google_project_number
190+
const oneSignalAppId = "cfdefd08-d4ad-4593-8173-4ba4ebf4d67a"; // onesignal_app_id
191+
var iosSettings = {};
192+
iosSettings["kOSSettingsKeyAutoPrompt"] = true;
193+
iosSettings["kOSSettingsKeyInAppLaunchURL"] = true;
194+
195+
console.debug("oneSignal.startInit");
196+
oneSignal.startInit(oneSignalAppId, sender_id).
197+
iOSSettings(iosSettings).
198+
inFocusDisplaying(oneSignal.OSInFocusDisplayOption.Notification).
199+
handleNotificationOpened(this.notificationOpenedCallback).
200+
handleNotificationReceived(this.notificationReceivedCallback).
201+
endInit();
202+
this.oneSignalId = await this.getids(oneSignal);
203+
console.log("oneSignalId: " + this.oneSignalId);
204+
205+
} catch (error) {
206+
console.error(error);
207+
}
208+
} else {
209+
console.log("Missing oneSignal plugin");
210+
}
211+
}
212+
try {
213+
if (device) {
214+
console.debug("device exists");
215+
this.device = device;
216+
} else {
217+
console.debug("device does NOT exists");
218+
}
219+
} catch (error) {
220+
console.error(error);
221+
}
222+
document.addEventListener("pause", this.onPause, false);
223+
document.addEventListener("resume", this.onResume, false);
224+
document.addEventListener("menubutton", this.onMenuKeyDown, false);
225+
document.addEventListener("backbutton", this.onbackbutton, false);
226+
227+
228+
if (cordova.plugins && cordova.plugins.diagnostic) {
229+
console.debug("Check if authorized for location");
230+
var isAuthorized = await this.isLocationAuthorized();
231+
if (!isAuthorized) {
232+
console.debug("Not authorized for location is not , request authorization");
233+
await this.requestLocationAuthorization();
234+
}
235+
236+
var isAvailable = await this.isLocationAvailable();
237+
if (!isAvailable) {
238+
console.debug("Location is not available");
239+
} else {
240+
console.debug("Location is available, get current location");
241+
this.location = await this.getLocation();
242+
}
243+
} else {
244+
console.debug("diagnostic is missing");
245+
}
246+
this.gettoken();
247+
});
248+
} else {
249+
console.debug("cordova not definded");
250+
if (this.scanCount < (5 * 4)) {
251+
this.scanCount++;
252+
setTimeout(this.scanForCordova, 200);
253+
}
254+
}
255+
} catch (error) {
256+
console.error(error);
257+
console.debug("Failed locating cordova");
258+
}
259+
}
177260
init() {
261+
setTimeout(this.scanForCordova.bind(this), 200);
178262
this.getJSON("/config", async (error: any, data: any) => {
179263
var parser = document.createElement('a');
180264
parser.href = data.wshost;
@@ -185,6 +269,7 @@ module openflow {
185269
parser.search; // => "?search=test"
186270
parser.hash; // => "#hash"
187271
parser.host; // => "example.com:3000"
272+
console.log(data);
188273
if (location.protocol == 'https:' && parser.protocol == "ws:") {
189274
data.wshost = "wss://" + parser.hostname;
190275
console.log("new wshost: " + data.wshost);
@@ -265,88 +350,6 @@ module openflow {
265350
timeout(ms) {
266351
return new Promise(resolve => setTimeout(resolve, ms));
267352
}
268-
private async LoadMobileData() {
269-
console.log("this.usingCordova: " + this.usingCordova);
270-
if (!this.usingCordova) {
271-
console.log("wait 1 seconds and test for Cordova again");
272-
let counter: number = 0;
273-
while (!this.usingCordova && counter < 15) {
274-
counter++;
275-
await this.timeout(100);
276-
var win: any = window;
277-
this.usingCordova = !!win.cordova;
278-
}
279-
console.log("this.usingCordova: " + this.usingCordova);
280-
}
281-
if (this.usingCordova) {
282-
document.addEventListener("deviceready", async () => {
283-
console.log("deviceready");
284-
if ((window as any).plugins) {
285-
var oneSignal = (window as any).plugins.OneSignal;
286-
if (oneSignal) {
287-
try {
288-
console.debug("window.plugins.OneSignal exists");
289-
290-
const sender_id = "906036108091"; // google_project_number
291-
const oneSignalAppId = "cfdefd08-d4ad-4593-8173-4ba4ebf4d67a"; // onesignal_app_id
292-
var iosSettings = {};
293-
iosSettings["kOSSettingsKeyAutoPrompt"] = true;
294-
iosSettings["kOSSettingsKeyInAppLaunchURL"] = true;
295-
296-
console.debug("oneSignal.startInit");
297-
oneSignal.startInit(oneSignalAppId, sender_id).
298-
iOSSettings(iosSettings).
299-
inFocusDisplaying(oneSignal.OSInFocusDisplayOption.Notification).
300-
handleNotificationOpened(this.notificationOpenedCallback).
301-
handleNotificationReceived(this.notificationReceivedCallback).
302-
endInit();
303-
this.oneSignalId = await this.getids(oneSignal);
304-
console.log("oneSignalId: " + this.oneSignalId);
305-
306-
} catch (error) {
307-
console.error(error);
308-
}
309-
} else {
310-
console.log("Missing oneSignal plugin");
311-
}
312-
}
313-
try {
314-
if (device) {
315-
console.debug("device exists");
316-
this.device = device;
317-
} else {
318-
console.debug("device does NOT exists");
319-
}
320-
} catch (error) {
321-
console.error(error);
322-
}
323-
document.addEventListener("pause", this.onPause, false);
324-
document.addEventListener("resume", this.onResume, false);
325-
document.addEventListener("menubutton", this.onMenuKeyDown, false);
326-
document.addEventListener("backbutton", this.onbackbutton, false);
327-
328-
329-
if (cordova.plugins && cordova.plugins.diagnostic) {
330-
console.debug("Check if authorized for location");
331-
var isAuthorized = await this.isLocationAuthorized();
332-
if (!isAuthorized) {
333-
console.debug("Not authorized for location is not , request authorization");
334-
await this.requestLocationAuthorization();
335-
}
336-
337-
var isAvailable = await this.isLocationAvailable();
338-
if (!isAvailable) {
339-
console.debug("Location is not available");
340-
} else {
341-
console.debug("Location is available, get current location");
342-
this.location = await this.getLocation();
343-
}
344-
} else {
345-
console.debug("diagnostic is missing");
346-
}
347-
});
348-
}
349-
}
350353
private onopen(evt: Event) {
351354
console.log("WebSocketClient::onopen: connected");
352355
this.gettoken();
@@ -375,9 +378,6 @@ module openflow {
375378
}
376379
return;
377380
}
378-
if (doLoadMobileData == true) {
379-
await this.LoadMobileData()
380-
}
381381
q.jwt = data.jwt;
382382
q.rawAssertion = data.rawAssertion;
383383
q.realm = "browser";

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.259
1+
0.0.260

0 commit comments

Comments
 (0)