1// Copyright (C) 2021 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15export const DEFAULT_CHANNEL = 'stable'; 16const CHANNEL_KEY = 'perfettoUiChannel'; 17 18let currentChannel: string | undefined = undefined; 19let nextChannel: string | undefined = undefined; 20 21// This is the channel the UI is currently running. It doesn't change once the 22// UI has been loaded. 23export function getCurrentChannel(): string { 24 if (currentChannel === undefined) { 25 currentChannel = localStorage.getItem(CHANNEL_KEY) ?? DEFAULT_CHANNEL; 26 } 27 return currentChannel; 28} 29 30// This is the channel that will be applied on reload. 31export function getNextChannel(): string { 32 if (nextChannel !== undefined) { 33 return nextChannel; 34 } 35 return getCurrentChannel(); 36} 37 38export function channelChanged(): boolean { 39 return getCurrentChannel() !== getNextChannel(); 40} 41 42export function setChannel(channel: string): void { 43 getCurrentChannel(); // Cache the current channel before mangling next one. 44 nextChannel = channel; 45 localStorage.setItem(CHANNEL_KEY, channel); 46} 47