Skip to content

Commit 1f512bd

Browse files
committed
option to enable/disable notifications, Fixes #82
1 parent 462e51f commit 1f512bd

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

packages/selenium-ide/src/editor.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var openedWindowIds = new Object();
2525
var openedTabCount = 1;
2626
var selfWindowId = -1;
2727
var contentWindowId;
28-
var notificationCount = 0;
2928

3029
/* playing */
3130
var playingFrameLocations = {};
@@ -272,19 +271,3 @@ browser.runtime.onMessage.addListener(function contentWindowIdListener(message)
272271
browser.runtime.onMessage.removeListener(contentWindowIdListener);
273272
}
274273
})
275-
276-
function notification(command, target, value) {
277-
let tempCount = String(notificationCount);
278-
notificationCount++;
279-
// In Chrome, notification.create must have "iconUrl" key in notificationOptions
280-
browser.notifications.create(tempCount, {
281-
"type": "basic",
282-
"iconUrl": "/icons/icon128.png",
283-
"title": "Record command!",
284-
"message": "command: " + String(command) + "\ntarget: " + String(target[0][0]) + "\nvalue: " + String(value)
285-
});
286-
287-
setTimeout(function() {
288-
browser.notifications.clear(tempCount);
289-
}, 1500);
290-
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import UiState from "../stores/view/UiState";
19+
20+
export function sendRecordNotification(command, target, value) {
21+
if (UiState.options.recordNotifications) {
22+
// In Chrome, notification.create must have "iconUrl" key in notificationOptions
23+
browser.notifications.create({
24+
"type": "basic",
25+
"iconUrl": "/icons/icon128.png",
26+
"title": "Command was recorded",
27+
"message": `command: ${command} \ntarget: ${target[0][0]} \nvalue: ${value}`
28+
}).then(id => {
29+
setTimeout(function() {
30+
browser.notifications.clear(id);
31+
}, 1500);
32+
});
33+
}
34+
}
35+
36+
window.notification = sendRecordNotification;

packages/selenium-ide/src/neo/components/ProjectHeader/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ import PropTypes from "prop-types";
2020
import classNames from "classnames";
2121
import Title from "react-document-title";
2222
import ContentEditable from "react-contenteditable";
23+
import { observer } from "mobx-react";
2324
import OpenButton from "../ActionButtons/Open";
2425
import SaveButton from "../ActionButtons/Save";
2526
import MoreButton from "../ActionButtons/More";
2627
import ListMenu, { ListMenuItem } from "../ListMenu";
28+
import UiState from "../../stores/view/UiState";
2729
import "./style.css";
2830

31+
@observer
2932
export default class ProjectHeader extends React.Component {
3033
constructor(props) {
3134
super(props);
@@ -47,6 +50,7 @@ export default class ProjectHeader extends React.Component {
4750
this.props.changeName(e.target.value);
4851
}
4952
render() {
53+
console.log(UiState.options.recordNotifications);
5054
return (
5155
<div className={classNames("header", {"changed": this.props.changed})}>
5256
<Title title={`Selenium IDE - ${this.props.title}${this.props.changed ? "*" : ""}`} />
@@ -61,6 +65,9 @@ export default class ProjectHeader extends React.Component {
6165
<MoreButton canFocus={true} />
6266
}>
6367
<ListMenuItem onClick={this.props.export}>Export to JavaScript code</ListMenuItem>
68+
<ListMenuItem onClick={() => { UiState.setOptions({ recordNotifications: !UiState.options.recordNotifications }); }}>
69+
{UiState.options.recordNotifications ? "Disable record notifications" : "Enable record notifications"}
70+
</ListMenuItem>
6471
</ListMenu>
6572
</span>
6673
</div>

packages/selenium-ide/src/neo/containers/Panel/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import "../../styles/resizer.css";
4242
import "../../styles/markdown.css";
4343

4444
import { loadProject, exportProject, saveProject } from "../../IO/filesystem";
45+
import "../../IO/notifications";
4546
import "../../IO/SideeX/record";
4647
import "../../IO/SideeX/playback";
4748

packages/selenium-ide/src/neo/stores/view/UiState.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import { action, computed, observable, observe } from "mobx";
18+
import { action, computed, observable, observe, extendObservable } from "mobx";
1919
import storage from "../../IO/storage";
2020
import SuiteState from "./SuiteState";
2121
import TestState from "./TestState";
@@ -41,6 +41,9 @@ class UiState {
4141
@observable navigationDragging = false;
4242
@observable pristineCommand = new Command();
4343
@observable lastFocus = {};
44+
@observable options = {
45+
recordNotifications: true
46+
};
4447

4548
constructor() {
4649
this.suiteStates = {};
@@ -54,6 +57,9 @@ class UiState {
5457
if (data.navigationSize !== undefined && data.navigationSize >= this.minNavigationWidth) {
5558
this.resizeNavigation(data.navigationSize);
5659
}
60+
if (data.options) {
61+
this.setOptions(data.options);
62+
}
5763
});
5864
}
5965

@@ -195,6 +201,13 @@ class UiState {
195201
this.navigationDragging = isDragging;
196202
}
197203

204+
@action.bound setOptions(options) {
205+
extendObservable(this.options, options);
206+
storage.set({
207+
options: this.options
208+
});
209+
}
210+
198211
@action.bound observePristine() {
199212
this.pristineDisposer = observe(this.pristineCommand, () => {
200213
this.pristineDisposer();

0 commit comments

Comments
 (0)