Permalink
Browse files

add --always-on-top option

  • Loading branch information...
1 parent a1c0567 commit a5fe4422b1816d04ebfd9ade2ca7b30024693c74 @rhysd committed Nov 12, 2016
Showing with 25 additions and 1 deletion.
  1. +12 −0 app/main.js
  2. +10 −1 bin/cli.js
  3. +3 −0 index.js
View
@@ -45,6 +45,10 @@ function shouldFocus(argv) {
return argv.indexOf('--without-focus') < 0;
}
+function alwaysOnTop(argv) {
+ return argv.indexOf('--always-on-top') >= 0;
+}
+
const shouldQuit = app.makeSingleInstance((argv, workdir) => {
if (win !== null) {
if (win.isMinimized(0)) {
@@ -60,6 +64,13 @@ const shouldQuit = app.makeSingleInstance((argv, workdir) => {
if (shouldFocus(argv)) {
win.focus();
}
+
+ const fixOnTop = alwaysOnTop(argv);
+ if (fixOnTop && !win.isAlwaysOnTop()) {
+ win.setAlwaysOnTop(true);
+ } else if (!fixOnTop && win.isAlwaysOnTop()) {
+ win.setAlwaysOnTop(false);
+ }
}
});
@@ -74,6 +85,7 @@ app.once('ready', () => {
width: size.width || 1000,
height: size.height || 800,
show: false,
+ alwaysOnTop: alwaysOnTop(process.argv),
webPreferrences: {
nodeIntegration: false,
sandbox: true
View
@@ -34,6 +34,11 @@ function parseArgv(argv) {
argv.splice(without_focus_idx, 1);
}
+ const always_on_top_idx = argv.indexOf('--always-on-top');
+ if (always_on_top_idx >= 0) {
+ argv.splice(always_on_top_idx, 1);
+ }
+
const width = parseIntArg('width', argv);
const height = parseIntArg('height', argv);
@@ -47,6 +52,7 @@ function parseArgv(argv) {
target: argv[0],
fallback: fallback_idx >= 0,
focus: without_focus_idx < 0,
+ alwaysOnTop: always_on_top_idx >= 0,
width,
height,
};
@@ -55,7 +61,7 @@ function parseArgv(argv) {
const parsed = parseArgv(process.argv.slice(2));
if (parsed.help) {
process.stderr.write(
-`$ electron-open {something} [--help|--with-fallback|--width {px}|--height {px}|--without-focus]
+`$ electron-open {something} [Options]
Description:
Open something in Electron window.
@@ -77,6 +83,9 @@ Options:
--without-focus
Do not focus a window.
+ --always-on-top
+ Show a window always on top of desktop.
+
--help
Show this help.
View
@@ -40,6 +40,9 @@ function open(parsed) {
if (parsed.focus === false) {
args.push('--without-focus');
}
+ if (parsed.alwaysOnTop) {
+ args.push('--always-on-top');
+ }
child_process.spawn(electron, args, {
stdio: 'ignore',

0 comments on commit a5fe442

Please sign in to comment.