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 15import {raf} from './raf_scheduler'; 16 17export const DEFAULT_CHANNEL = 'stable'; 18const CHANNEL_KEY = 'perfettoUiChannel'; 19 20let currentChannel: string | undefined = undefined; 21let nextChannel: string | undefined = undefined; 22 23// This is the channel the UI is currently running. It doesn't change once the 24// UI has been loaded. 25export function getCurrentChannel(): string { 26 if (currentChannel === undefined) { 27 currentChannel = localStorage.getItem(CHANNEL_KEY) ?? DEFAULT_CHANNEL; 28 } 29 return currentChannel; 30} 31 32// This is the channel that will be applied on reload. 33export function getNextChannel(): string { 34 if (nextChannel !== undefined) { 35 return nextChannel; 36 } 37 return getCurrentChannel(); 38} 39 40export function channelChanged(): boolean { 41 return getCurrentChannel() !== getNextChannel(); 42} 43 44export function setChannel(channel: string): void { 45 getCurrentChannel(); // Cache the current channel before mangling next one. 46 nextChannel = channel; 47 localStorage.setItem(CHANNEL_KEY, channel); 48 raf.scheduleFullRedraw(); 49} 50