1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Functions related to controlling the modal ui state of the app.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/** @enum {string} */
remoting.AppMode = {
HOME: 'home',
HOME_DAEMON_ENABLED: 'home.daemon.enabled',
HOME_DAEMON_DISABLED: 'home.daemon.disabled',
UNAUTHENTICATED: 'auth',
CLIENT: 'client',
CLIENT_UNCONNECTED: 'client.unconnected',
CLIENT_PIN_PROMPT: 'client.pin-prompt',
CLIENT_CONNECTING: 'client.connecting',
CLIENT_CONNECT_FAILED_IT2ME: 'client.connect-failed.it2me',
CLIENT_CONNECT_FAILED_ME2ME: 'client.connect-failed.me2me',
CLIENT_SESSION_FINISHED_IT2ME: 'client.session-finished.it2me',
CLIENT_SESSION_FINISHED_ME2ME: 'client.session-finished.me2me',
HOST: 'host',
HOST_WAITING_FOR_CODE: 'host.waiting-for-code',
HOST_WAITING_FOR_CONNECTION: 'host.waiting-for-connection',
HOST_SHARED: 'host.shared',
HOST_SHARE_FAILED: 'host.share-failed',
HOST_SHARE_FINISHED: 'host.share-finished',
IN_SESSION: 'in-session'
};
/**
* @type {remoting.AppMode} The current app mode
*/
remoting.currentMode = remoting.AppMode.HOME;
/**
* Change the app's modal state to |mode|, which is considered to be a dotted
* hierachy of modes. For example, setMode('host.shared') will show any modal
* elements with an data-ui-mode attribute of 'host' or 'host.shared' and hide
* all others.
*
* @param {remoting.AppMode} mode The new modal state, expressed as a dotted
* hiearchy.
*/
remoting.setMode = function(mode) {
var modes = mode.split('.');
for (var i = 1; i < modes.length; ++i)
modes[i] = modes[i - 1] + '.' + modes[i];
var elements = document.querySelectorAll('[data-ui-mode]');
for (var i = 0; i < elements.length; ++i) {
var element = /** @type {Element} */ elements[i];
var hidden = true;
for (var m = 0; m < modes.length; ++m) {
if (hasClass(element.getAttribute('data-ui-mode'), modes[m])) {
hidden = false;
break;
}
}
element.hidden = hidden;
}
remoting.debug.log('App mode: ' + mode);
remoting.currentMode = mode;
if (mode == remoting.AppMode.IN_SESSION) {
document.removeEventListener('keydown', remoting.DebugLog.onKeydown, false);
} else {
document.addEventListener('keydown', remoting.DebugLog.onKeydown, false);
}
if (mode == remoting.AppMode.HOME ||
mode == remoting.AppMode.HOME_DAEMON_ENABLED ||
mode == remoting.AppMode.HOME_DAEMON_DISABLED) {
var display = function() { remoting.hostList.display(); };
remoting.hostList.refresh(display);
}
};
/**
* Get the major mode that the app is running in.
* @return {string} The app's current major mode.
*/
remoting.getMajorMode = function() {
return remoting.currentMode.split('.')[0];
};
|