Skip to content

Commit

Permalink
Fix trackjs exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaszhix committed Jul 7, 2017
1 parent 0167de4 commit f8dbc2b
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 216 deletions.
43 changes: 26 additions & 17 deletions app/scripts/bg/bg.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
window._trackJs = {
token: 'bd495185bd7643e3bc43fa62a30cec92',
enabled: false,
onError: function (payload) {
onError: function (payload) {
console.log('payload', payload)
if (payload.message.indexOf('unknown') !== -1) {
return false;
}
return true;
return true;
},
version: "",
callback: {
Expand Down Expand Up @@ -99,6 +99,9 @@ var syncSession = (sessions, prefs, windows=null, cb)=>{
for (let i = 0, len = windows.length; i < len; i++) {
allTabs.push(windows[i].tabs);
for (let z = 0, _len = windows[i].tabs.length; z < _len; z++) {
if (typeof windows[i].tabs[z] === 'undefined') {
continue;
}
if (windows[i].tabs[z].url === 'chrome://newtab/') {
_.pullAt(windows[i].tabs, z);
}
Expand Down Expand Up @@ -182,11 +185,11 @@ var createScreenshot = (t, refWindow, refTab, run=0)=>{
return;
}
var screenshot = {
url: t.state.windows[refWindow].tabs[refTab].url,
data: image,
url: t.state.windows[refWindow].tabs[refTab].url,
data: image,
timeStamp: Date.now()
};

var refScreenshot = _.findIndex(t.state.screenshots, {url: t.state.windows[refWindow].tabs[refTab].url});
if (refScreenshot !== -1) {
t.state.screenshots[refScreenshot] = screenshot;
Expand Down Expand Up @@ -221,7 +224,7 @@ var setAction = (t, type, oldTabInstance, newTabInstance=null)=>{
}
if (newTabInstance && newTabInstance.title !== 'New Tab' || oldTabInstance && oldTabInstance.title !== 'New Tab') {
var action = {
type: type,
type: type,
item: _.cloneDeep(type === 'update' ? newTabInstance : oldTabInstance),
id: uuid.v4()
};
Expand Down Expand Up @@ -250,6 +253,10 @@ var setActionThrottled = _.throttle(setAction, 100, {leading: true});
var Bg = React.createClass({
mixins: [Reflux.ListenerMixin],
getInitialState(){
let version = 1;
try { // Firefox check
version = parseInt(/Chrome\/([0-9.]+)/.exec(navigator.userAgent)[1].split('.'))
} catch (e) {}
return {
eventState: eventState,
prefs: null,
Expand All @@ -259,7 +266,7 @@ var Bg = React.createClass({
sessions: [],
screenshots: [],
actions: [],
chromeVersion: parseInt(/Chrome\/([0-9.]+)/.exec(navigator.userAgent)[1].split('.'))
chromeVersion: version
};
},
componentDidMount(){
Expand Down Expand Up @@ -355,8 +362,8 @@ var Bg = React.createClass({
sendMsg({windows: this.state.windows, windowId: Window.id});
});
});
/*
Windows removed
/*
Windows removed
*/
chrome.windows.onRemoved.addListener((windowId)=>{
var refWindow = _.findIndex(this.state.windows, {windowId: windowId});
Expand Down Expand Up @@ -576,9 +583,9 @@ var Bg = React.createClass({
convertV1Sessions(_item){
for (let i = 0, len = _item.sessionData.length; i < len; i++) {
var session = {
timeStamp: _item.sessionData[i].timeStamp,
tabs: [_item.sessionData[i].tabs],
label: _item.sessionData[i].label,
timeStamp: _item.sessionData[i].timeStamp,
tabs: [_item.sessionData[i].tabs],
label: _item.sessionData[i].label,
id: uuid.v4()
};
_item.sessionData[i] = session;
Expand Down Expand Up @@ -708,7 +715,7 @@ var Bg = React.createClass({
return;
}
// Update timestamp for auto-discard feature's accuracy.
_.merge(this.state.windows[refWindow].tabs[refTab], {
_.assignIn(this.state.windows[refWindow].tabs[refTab], {
timeStamp: new Date(Date.now()).getTime()
});

Expand All @@ -732,7 +739,7 @@ var Bg = React.createClass({
}
}
this.state.windows[refWindow].tabs.push(e);
this.state.windows[refWindow].tabs = v(this.state.windows[refWindow].tabs).move(_.findIndex(this.state.windows[refWindow].tabs, _.last(this.state.windows[refWindow].tabs)), e.index).ns;
this.state.windows[refWindow].tabs = v(this.state.windows[refWindow].tabs).move(_.findIndex(this.state.windows[refWindow].tabs, _.last(this.state.windows[refWindow].tabs)), e.index).ns;
} else {
this.state.windows[refWindow].tabs.push(e);
}
Expand All @@ -744,7 +751,9 @@ var Bg = React.createClass({
var refNewTab = _.findIndex(this.state.newTabs, {windowId: e.windowId});
if (refNewTab !== -1) {
var refExistingTab = _.findIndex(this.state.windows[refWindow].tabs, {id: this.state.newTabs[refNewTab].id});
if (refExistingTab === -1 || this.state.windows[refWindow].tabs[refExistingTab].url.indexOf('chrome://newtab/') === -1) {
if (refExistingTab === -1
|| (typeof this.state.windows[refWindow].tabs[refExistingTab] !== 'undefined'
&& this.state.windows[refWindow].tabs[refExistingTab].url.indexOf('chrome://newtab/') === -1)) {
_.pullAt(this.state.newTabs, refNewTab);
this.setState({newTabs: this.state.newTabs}, ()=>{
chrome.tabs.create({active: true});
Expand Down Expand Up @@ -804,7 +813,7 @@ var Bg = React.createClass({
return;
}
setActionThrottled(this, 'update', this.state.windows[refWindow].tabs[refTab], e);
_.merge(e, {
_.assignIn(e, {
timeStamp: new Date(Date.now()).getTime()
});

Expand Down Expand Up @@ -844,7 +853,7 @@ var Bg = React.createClass({
}
this.setState({windows: this.state.windows});
synchronizeSession(this.state.sessions, this.state.prefs, this.state.windows);
sendMsg({windows: this.state.windows, windowId: e.windowId});
sendMsg({windows: this.state.windows, windowId: e.windowId});
}
});
},
Expand Down
48 changes: 24 additions & 24 deletions app/scripts/components/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Btn extends React.Component {
componentWillUnmount(){
try {
v(ReactDOM.findDOMNode(this)).css({display: 'none'});
} catch (e) {}
} catch (e) {}
}
themeChange(e){
if (e.theme) {
Expand Down Expand Up @@ -70,24 +70,24 @@ export class Btn extends React.Component {
textShadow: `1px 1px ${s.theme.lightBtnTextShadow}`
};
}
_.merge(style, {
_.assignIn(style, {
boxShadow: `${s.theme.tileShadow} 1px 1px 5px -1px`,
opacity: '1'
});
_.merge(style, _.cloneDeep(p.style));
_.assignIn(style, _.cloneDeep(p.style));
var faStyle = {
paddingRight: !p.noIconPadding ? '6px' : null
};
_.merge(faStyle, _.cloneDeep(p.faStyle));
_.assignIn(faStyle, _.cloneDeep(p.faStyle));
return (
<button
data-tip={p['data-tip'] ? `<div style="max-width: 350px;">${p['data-tip']}</div>` : null}
ref="btn"
<button
data-tip={p['data-tip'] ? `<div style="max-width: 350px;">${p['data-tip']}</div>` : null}
ref="btn"
style={style}
onMouseEnter={this.handleHoverIn}
onMouseLeave={this.handleHoverOut}
onMouseEnter={this.handleHoverIn}
onMouseLeave={this.handleHoverOut}
onClick={p.onClick}
id={p.id}
id={p.id}
className={p.className}>
<div className="btn-label">{p.fa || p.icon ? <i style={{paddingRight: '2px'}} className={`${p.fa ? 'fa fa-'+p.fa : ''}${p.icon ? ' icon-'+p.icon : ''}`} style={faStyle}></i> : null}{p.fa ? ' ' : null}{p.children}</div>
</button>
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Panel extends React.Component {
onDragEnd={p.onDragEnd}
onDragStart={p.onDragStart}
onDragOver={p.onDragOver}
className={`panel panel-${p.type}${p.className ? ' '+p.className : ''}`}
className={`panel panel-${p.type}${p.className ? ' '+p.className : ''}`}
style={defaultStyle}
onMouseEnter={p.onMouseEnter}
onMouseLeave={p.onMouseLeave}
Expand Down Expand Up @@ -248,8 +248,8 @@ export class ModalOverlay extends React.Component {
overlayStyle = _.assignIn(overlayStyle, p.overlayStyle);
return (
<div className={`modal fade${s.fadeIn ? ' in' : ''}`} style={overlayStyle}>
<ModalDefault
onClose={this.handleCloseClick}
<ModalDefault
onClose={this.handleCloseClick}
header={p.header}
size={p.size}
heightOffset={p.heightOffset}
Expand Down Expand Up @@ -367,7 +367,7 @@ export class Tabs extends React.Component {
})}
</ul>

{p.children ?
{p.children ?
<div className="tab-content">
{p.children}
</div> : null}
Expand All @@ -392,12 +392,12 @@ export class Context extends React.Component {
var p = this.props;
return (
<ul className="dropdown-menu dropdown-menu-xs" style={{
display: 'block',
position: 'relative',
width: '100%',
marginTop: '0',
float: 'none',
padding: '1px',
display: 'block',
position: 'relative',
width: '100%',
marginTop: '0',
float: 'none',
padding: '1px',
borderRadius: '1px',
backgroundColor: p.theme.settingsBg
}}>
Expand All @@ -412,9 +412,9 @@ export class Context extends React.Component {
<label style={{paddingLeft: '47px', paddingTop: '6px', paddingBottom: '6px', color: p.theme.bodyText}} onClick={option.onClick}>
<span className="switchery switchery-default" style={{
left: '8px',
backgroundColor: option.switch ? p.theme.darkBtnBg : 'rgba(255, 255, 255, 0)',
borderColor: option.switch ? p.theme.textFieldBorder : p.theme.darkBtnBg,
boxShadow: `${option.switch ? p.theme.textFieldBorder : p.theme.darkBtnBg} 0px 0px 0px 8px inset`,
backgroundColor: option.switch ? p.theme.darkBtnBg : 'rgba(255, 255, 255, 0)',
borderColor: option.switch ? p.theme.textFieldBorder : p.theme.darkBtnBg,
boxShadow: `${option.switch ? p.theme.textFieldBorder : p.theme.darkBtnBg} 0px 0px 0px 8px inset`,
WebkitTransition: p.animations ? 'border 0.4s, box-shadow 0.4s, background-color 1.2s' : 'initial',
}}>
<small style={{left: option.switch ? '14px' : '0px', WebkitTransition: p.animations ? 'background-color 0.4s, left 0.2s' : 'initial', backgroundColor: option.switch ? p.theme.darkBtnText : p.theme.bodyText}} />
Expand All @@ -424,7 +424,7 @@ export class Context extends React.Component {
</li>
);
} else {
return <li key={i}><a style={{cursor: 'pointer', color: p.theme.bodyText}} onClick={option.onClick}><i style={{color: p.theme.bodyText}} className={option.icon} /> {option.label}</a></li>;
return <li key={i}><a style={{cursor: 'pointer', color: p.theme.bodyText}} onClick={option.onClick}><i style={{color: p.theme.bodyText}} className={option.icon} /> {option.label}</a></li>;
}
} else {
return null;
Expand Down
15 changes: 11 additions & 4 deletions app/scripts/components/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class ContextMenu extends React.Component {
this.handleOptions(this.props);
_.defer(()=>{
var positionedDiv = v('#main > div > div > div.ntg-context > div');
var divTop = positionedDiv.css().top.split('px')[0];
let top = positionedDiv.css().top;
let divTop = 0;
if (top && top.indexOf('px') > -1) {
divTop = top.split('px')[0];
}
if (isNaN(divTop)) {
divTop = 0;
}
if (!positionedDiv.inViewport()) {
positionedDiv.css({top: `${divTop - 100}px`});
}
Expand All @@ -42,7 +49,7 @@ class ContextMenu extends React.Component {
p.context.value = false;
p.context.id = null;
state.set({
context: p.context,
context: p.context,
disableSidebarClickOutside: false
});
if (p.context.hasOwnProperty('origin')) {
Expand Down Expand Up @@ -171,7 +178,7 @@ class ContextMenu extends React.Component {
}
p.context.options = contextOptions;
state.set({
context: p.context,
context: p.context,
disableSidebarClickOutside: true
});
};
Expand All @@ -188,7 +195,7 @@ class ContextMenu extends React.Component {
var isSelectedItems = _.isArray(p.context.id);
var t = _.cloneDeep(this);
p = recursion === 0 ? t.props : p;

if (isSelectedItems) {
var selectedItems = p.context.id;
for (let z = 0, len = selectedItems.length; z < len; z++) {
Expand Down
Loading

0 comments on commit f8dbc2b

Please sign in to comment.