4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 function storageAvailable(type
) {
21 var storage
= window
[type
];
22 var x
= '__storage_test_DEADBEEF__';
23 storage
.setItem(x
, x
);
24 storage
.removeItem(x
);
31 export class LaunchpadSettings
{
34 this.openedNsrsStorageKey
= "openedNsrList";
35 this.debug
= (args
&& args
.debug
);
37 if (!storageAvailable('localStorage')) {
38 this.canUseStorage
= false;
39 console
.log("Unable to use window.localStorage");
40 //throw "Unable to use window.localStorage";
43 this.canUseStorage
= true;
48 console
.log("LaunchpadSettings.openedNSRs called");
51 if (this.canUseStorage
) {
52 let nsrStr
= window
.localStorage
.getItem(this.openedNsrsStorageKey
);
54 nsrs
= nsrStr
.split(',');
57 console
.log("got nsr ids=", nsrs
);
60 return (nsrs
) ? nsrs
: [];
64 let nsrs
= this.openedNSRs();
66 console
.log("LaunchpadSettings.addOpenNSR. nsrs=", nsrs
);
69 if (!nsrs
.includes(nsrId
)) {
71 console
.log("adding nsr id=", nsrId
);
74 window
.localStorage
.setItem(this.openedNsrsStorageKey
, nsrs
);
80 removeOpenNSR(nsrId
) {
82 console
.log("LaunchpadSettings.removeOpenNSR called with id:", nsrId
);
84 if (this.canUseStorage
) {
85 let nsrs
= this.openedNSRs().filter(nsr_id
=> nsr_id
!= nsrId
);
86 window
.localStorage
.setItem(this.openedNsrsStorageKey
, nsrs
);
92 if (this.canUseStorage
) {
93 window
.localStorage
.removeItem(this.openedNsrsStorageKey
);
100 LaunchpadSettings: LaunchpadSettings