1// Copyright (C) 2018 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 * as m from 'mithril';
16import {globals} from './globals';
17
18import {createPage} from './pages';
19
20let channelChanged = false;
21
22export const HomePage = createPage({
23  view() {
24    return m(
25        '.page.home-page',
26        m(
27            '.home-page-center',
28            m('.home-page-title', 'Perfetto'),
29            m(`img.logo[src=${globals.root}assets/logo-3d.png]`),
30            m(
31                'div.channel-select',
32                m('div',
33                  'Feeling adventurous? Try our bleeding edge Canary version'),
34                m(
35                    'fieldset',
36                    mkChan('stable'),
37                    mkChan('canary'),
38                    m('.highlight'),
39                    ),
40                m(`.home-page-reload${channelChanged ? '.show' : ''}`,
41                  'You need to reload the page for the changes to have effect'),
42                ),
43            ),
44        m('a.privacy',
45          {href: 'https://policies.google.com/privacy', target: '_blank'},
46          'Privacy policy'));
47  }
48});
49
50function mkChan(chan: string) {
51  const checked =
52      !channelChanged && globals.channel === chan ? '[checked=true]' : '';
53  return [
54    m(`input[type=radio][name=chan][id=chan_${chan}]${checked}`,
55      {onchange: () => changeChannel(chan)}),
56    m(`label[for=chan_${chan}]`, chan),
57  ];
58}
59
60function changeChannel(chan: string) {
61  localStorage.setItem('perfettoUiChannel', chan);
62  channelChanged = true;
63  globals.rafScheduler.scheduleFullRedraw();
64}
65