Skip to content

Commit

Permalink
Merge pull request #59 from scimusmn/feat-auto-start
Browse files Browse the repository at this point in the history
Feat auto start #59
  • Loading branch information
azuldev1 authored Jan 24, 2019
2 parents 2b63cd6 + a7d9427 commit e80880b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 25 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you've made changes to the application and are ready to release a new version

yarn package

This will save either a `.dmg` (macOS), `.exe` (Windows 10), or an `.AppImage` (Linux) in the `release` directory.
This will save either a `.dmg` (macOS), `.exe` (Windows 10), or an `.zip` (Linux) in the `release` directory.

## Change kiosk URL
When you start the app, and no URL is set, you will be directed to the settings page to enter a URL for your kiosk view.
Expand All @@ -54,6 +54,7 @@ When running the application you can use a few keyboard shortcuts to control the

\* Hide application works on Windows. On Linux and Mac, we simply open the file explorer, pushing the Stele application into the background.


# Credit
## What's a Stele?
> A stele (/ˈstiːli/ STEE-lee) is a stone or wooden slab, generally taller than it is wide, erected in the ancient world as a monument.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"test-watch": "yarn test --watch"
},
"dependencies": {
"auto-launch": "^5.0.5",
"bootstrap": "^4.1.3",
"depcheck": "^0.6.11",
"devtron": "^1.4.0",
Expand Down Expand Up @@ -161,7 +162,8 @@
},
"linux": {
"target": [
"AppImage"
"AppImage",
"zip"
],
"category": "Development"
},
Expand Down
65 changes: 42 additions & 23 deletions src/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ class Settings extends Component {
this.state = {
displayHome: '',
cursorVisibility: 'show',
autoLaunch: false,
};
}

componentWillMount() {
const kioskSettings = ipcRenderer.sendSync('settingsGet', 'kiosk');
let { displayHome, cursorVisibility } = kioskSettings;
let { displayHome, cursorVisibility, autoLaunch } = kioskSettings;
if (displayHome === undefined) displayHome = '';
if (cursorVisibility === undefined) cursorVisibility = 'show';
this.setState({ displayHome, cursorVisibility });
if (autoLaunch === undefined) autoLaunch = false;
this.setState({ displayHome, cursorVisibility, autoLaunch });
}

render() {
const { displayHome, cursorVisibility } = this.state;
const { displayHome, cursorVisibility, autoLaunch } = this.state;
return (
<Formik
initialValues={{ url: displayHome, cursorVis: cursorVisibility }}
initialValues={{ url: displayHome, cursorVis: cursorVisibility, autoLaunch }}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
ipcRenderer.send('updateSettings', values);
Expand Down Expand Up @@ -72,7 +74,7 @@ class Settings extends Component {
return (
<Container>
<Row className="mt-3">
<Col xs={8}>
<Col xs={8} className="mx-auto">
<Form
className="border p-3 bg-light"
onSubmit={handleSubmit}
Expand All @@ -97,26 +99,43 @@ class Settings extends Component {
Enter the home URL for the kiosk.
</FormText>
</FormGroup>
<FormGroup>
<Label for="cursorVis">Cursor Visibility</Label>
<select
name="cursorVis"
id="cursorVis"
value={values.cursorVis}
onChange={handleChange}
onBlur={handleBlur}
style={{ display: 'block' }}
>
<option value="show" label="Show" />
<option value="hide" label="Hide" />
<option value="hide_after_5" label="Hide after 5 seconds inactivity" />
<option value="hide_after_60" label="Hide after 60 seconds inactivity" />
<Row form>
<Col md={6}>
<FormGroup>
<Label for="cursorVis">Cursor Visibility</Label>
<select
name="cursorVis"
id="cursorVis"
value={values.cursorVis}
onChange={handleChange}
onBlur={handleBlur}
style={{ display: 'block' }}
>
<option value="show" label="Show" />
<option value="hide" label="Hide" />
<option value="hide_after_5" label="Hide after 5 seconds inactivity" />
<option value="hide_after_60" label="Hide after 60 seconds inactivity" />

</select>
<FormText>
</select>
<FormText>
Select mouse cursor visibility. Does not work with iFrames.
</FormText>
</FormGroup>
</FormText>
</FormGroup>
</Col>
<Col md={6}>
<Label for="autoLaunch">Auto Launch</Label>
<FormGroup check>
<Label check>
<Input onChange={handleChange} type="checkbox" id="autoLaunch" checked={values.autoLaunch} />
{' '}
Auto launch application on startup
</Label>
<FormText>
Auto launch application on startup.
</FormText>
</FormGroup>
</Col>
</Row>
<Button
color="primary"
type="submit"
Expand Down
3 changes: 3 additions & 0 deletions src/main.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import DailyRotateFile from 'winston-daily-rotate-file';
import buildMenu from './buildMenu';
import setupDevelopmentEnvironment from './devTools';
import navigateSettings from './navigate';
import { autoLaunchApp } from './settingsHelpers';

const promisedExec = childProcess.exec;

Expand Down Expand Up @@ -295,8 +296,10 @@ app.on('ready', async () => {
store.set({
'kiosk.displayHome': arg.url,
'kiosk.cursorVisibility': arg.cursorVis,
'kiosk.autoLaunch': arg.autoLaunch,
});
mainWindow.loadURL(arg.url);
autoLaunchApp(store.get('kiosk.autoLaunch'));
});

ipcMain.on('settingsGet', (event) => {
Expand Down
31 changes: 31 additions & 0 deletions src/settingsHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import AutoLaunch from 'auto-launch';
import { app } from 'electron';

export function autoLaunchApp(autoLaunchSetting) {
// linux issue: placing path:process.env.APPIMAGE for linux appImage build
// even though the Stele appImage is place in ~./config when path above is added
// the appImage does not get called on startup. works fine with .zip build
const kioskAutoLaunch = new AutoLaunch({
name: app.getName(),
});
function whichSetting(settingsBool, configSetting) {
if (settingsBool == configSetting) {
console.log('autolaunch setting already configured');
} else if (configSetting) {
console.log('autolaunch enabled');
kioskAutoLaunch.enable();
} else {
console.log('autolaunch disabled');
kioskAutoLaunch.disable();
}
}
function successCallback(result) {
console.log(`auto launch Success: ${result}`);
}
function failureCallback(error) {
console.log(`auto launch Error: ${error}`);
}
kioskAutoLaunch.isEnabled()
.then(isEnabled => whichSetting(isEnabled, autoLaunchSetting))
.catch(failureCallback);
}
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,11 @@ append-transform@^0.4.0:
dependencies:
default-require-extensions "^1.0.0"

applescript@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/applescript/-/applescript-1.0.0.tgz#bb87af568cad034a4e48c4bdaf6067a3a2701317"
integrity sha1-u4evVoytA0pOSMS9r2Bno6JwExc=

aproba@^1.0.3, aproba@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
Expand Down Expand Up @@ -1493,6 +1498,17 @@ atob@^2.1.1:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

auto-launch@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/auto-launch/-/auto-launch-5.0.5.tgz#d14bd002b1ef642f85e991a6195ff5300c8ad3c0"
integrity sha512-ppdF4mihhYzMYLuCcx9H/c5TUOCev8uM7en53zWVQhyYAJrurd2bFZx3qQVeJKF2jrc7rsPRNN5cD+i23l6PdA==
dependencies:
applescript "^1.0.0"
mkdirp "^0.5.1"
path-is-absolute "^1.0.0"
untildify "^3.0.2"
winreg "1.2.4"

autoprefixer@^9.0.0:
version "9.4.3"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-9.4.3.tgz#c97384a8fd80477b78049163a91bbc725d9c41d9"
Expand Down Expand Up @@ -10645,6 +10661,11 @@ unset-value@^1.0.0:
has-value "^0.3.1"
isobject "^3.0.0"

untildify@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.3.tgz#1e7b42b140bcfd922b22e70ca1265bfe3634c7c9"
integrity sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==

unzip-response@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
Expand Down Expand Up @@ -11140,6 +11161,11 @@ widest-line@^2.0.0:
dependencies:
string-width "^2.1.1"

[email protected]:
version "1.2.4"
resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b"
integrity sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=

winston-compat@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/winston-compat/-/winston-compat-0.1.4.tgz#599b4ce807ffe728713ecc25ede3f6b89425b739"
Expand Down

0 comments on commit e80880b

Please sign in to comment.