Browse Source

Meilleure gestion du délai sur un lancement d'application

upgrade-electron
William Petit 3 years ago
parent
commit
69cc5a6d39
2 changed files with 17 additions and 10 deletions
  1. 17
    0
      src/components/launcher/app-item.js
  2. 0
    10
      src/components/launcher/launcher-view.js

+ 17
- 0
src/components/launcher/app-item.js View File

@@ -1,8 +1,17 @@
1 1
 var React = require('react');
2
+var logger = require('../../util/logger');
2 3
 var AppIcon = require('../common/app-icon.js');
3 4
 
5
+var MIN_CLICK_DELTATIME = 2000;
6
+
4 7
 module.exports = React.createClass({
5 8
 
9
+  getInitialState: function() {
10
+    return {
11
+      lastClickTimestamp: 0
12
+    };
13
+  },
14
+
6 15
   propTypes: {
7 16
     item: React.PropTypes.object.isRequired,
8 17
     itemPath: React.PropTypes.oneOfType([
@@ -13,7 +22,15 @@ module.exports = React.createClass({
13 22
   },
14 23
 
15 24
   _onItemClick: function(evt) {
25
+
26
+    var clickDeltaTime = Date.now() - this.state.lastClickTimestamp;
27
+    if( clickDeltaTime < MIN_CLICK_DELTATIME ) {
28
+      logger.debug('Item "%s" clicked within %sms. No action.', this.props.itemPath, MIN_CLICK_DELTATIME);
29
+      return;
30
+    }
31
+
16 32
     evt.preventDefault();
33
+    this.setState({ lastClickTimestamp: Date.now() });
17 34
     this.props.onItemClick(evt, this.props.itemPath, this.props.item);
18 35
   },
19 36
 

+ 0
- 10
src/components/launcher/launcher-view.js View File

@@ -8,11 +8,9 @@ var connect = require('react-redux').connect;
8 8
 var logger = require('../../util/logger');
9 9
 var CrossfadeImage = require('../common/crossfade-image');
10 10
 var path = require('path');
11
-var _ = require('lodash');
12 11
 
13 12
 var DEFAULT_PROFILE = path.join(__dirname, '..', '..', '..', 'default-profile.json');
14 13
 var DEFAULT_BACKGROUND = '';
15
-var MIN_CLICK_DELTATIME = 2000;
16 14
 
17 15
 var LauncherView = React.createClass({
18 16
 
@@ -93,12 +91,6 @@ var LauncherView = React.createClass({
93 91
 
94 92
     logger.debug(item);
95 93
 
96
-    var clickDeltaTime = Date.now() - this.state.lastClickTimestamp;
97
-    if( clickDeltaTime < MIN_CLICK_DELTATIME ) {
98
-      logger.debug('Item clicked within %sms. No action.', MIN_CLICK_DELTATIME);
99
-      return;
100
-    }
101
-
102 94
     if(item.items) {
103 95
 
104 96
       this.play(this.refs.appList, 'slide-out-left 250ms ease-in-out')
@@ -126,8 +118,6 @@ var LauncherView = React.createClass({
126 118
       logger.info('No action associated with item "'+item.label+'".');
127 119
     }
128 120
 
129
-    this.setState({ lastClickTimestamp: Date.now() });
130
-
131 121
   },
132 122
 
133 123
   _getItemByPath: function(itemPath, rootItem) {

Loading…
Cancel
Save