Пример #1
0
	app.on('ready', () => {
		localShortcut.register(isOSX ? 'Cmd+Alt+I' : 'Ctrl+Shift+I', devTools);
		localShortcut.register('F12', devTools);

		localShortcut.register('CmdOrCtrl+R', refresh);
		localShortcut.register('F5', refresh);
	});
Пример #2
0
app.on('ready', () => {
	electron.Menu.setApplicationMenu(appMenu);
	mainWindow = createMainWindow();
	tray.create(mainWindow);

	const page = mainWindow.webContents;

	// Add spellcheck dictionary
	SpellChecker.getDictionary("en-US", "./node_modules/simple-spellchecker/dict", function(err, result) {
	    if(!err) {
	        myDictionary = result;
	    }
	});

	// Define function for consult the dictionary.
	ipc.on('checkspell', function(event, word) {
	    var res = null;
	    if(myDictionary != null && word != null) {
	        res = myDictionary.spellCheck(word);
	    }
	    event.returnValue = res;
	});

	// TODO - use global shortcut instead
	electronLocalshortcut.register(mainWindow, 'CommandOrControl+R', () => {
	   mainWindow.reload();
	 });

	electronLocalshortcut.register(mainWindow, 'Alt+Left', () => {
		if (page.canGoBack()) {
			page.goBack();
		}
	 });

    electronLocalshortcut.register(mainWindow, 'CommandOrControl+=', () => {
    	page.send('zoomIn');
	});

    electronLocalshortcut.register(mainWindow, 'CommandOrControl+-', () => {
		page.send('zoomOut');
    });

   	electronLocalshortcut.register(mainWindow, 'CommandOrControl+0', () => {
		page.send('zoomActualSize');
	});

    page.on('new-window', (event, url) => {
        if (mainWindow.useDefaultWindowBehaviour) {
            mainWindow.useDefaultWindowBehaviour = false;
            return;
        }
        if (linkIsInternal(checkWindowURL(), url)) {
        	event.preventDefault();
			return mainWindow.loadURL(url);
        }
        event.preventDefault();
        electron.shell.openExternal(url);
    });
});
Пример #3
0
Файл: main.js Проект: joskid/HNU
function createWindow() {
    Menu.setApplicationMenu(menu);

    mainWindow = new BrowserWindow({
        width: 750,
        height: 800,
        maxWidth: 750,
        title: 'Unofficial Hacker News desktop application',
        backgroundColor: 'rgb(255, 102, 0)',
        darkTheme: true,
        icon: process.platform === 'linux' && path.join(__dirname, 'media', 'Icon.png')
    });

    mainWindow.loadURL('https://news.ycombinator.com/');

    mainWindow.on('closed', () => {
        mainWindow = null;
    });

    const page = mainWindow.webContents;

    page.on('dom-ready', () => {
        page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8'));

        mainWindow.show();
    });

    page.on('app-command', (e, cmd) => {
        // Navigate the window back when the user hits their mouse back button
        if (cmd === 'browser-backward' && page.canGoBack()) {
            page.goBack();
        }
    });

    localShortcut.register(mainWindow, 'Ctrl+backspace', () => {
        if (page.canGoBack()) {
            page.goBack();
        }
    });

    localShortcut.register(mainWindow, 'Ctrl+R', () => {
        page.reloadIgnoringCache();
    });

    page.on('will-navigate', (e, url) => {
        if (url.indexOf('news.ycombinator.com') === -1) {
            e.preventDefault();

            shell.openExternal(url);
        }
    });

    page.on('new-window', (e, url) => {
        e.preventDefault();

        shell.openExternal(url);
    });
}
Пример #4
0
	app.on('ready', () => {
		// activate devtron for the user if they have it installed
		try {
			BrowserWindow.addDevToolsExtension(require('devtron').path);
		} catch (err) {}

		localShortcut.register(isMacOS ? 'Cmd+Alt+I' : 'Ctrl+Shift+I', devTools);
		localShortcut.register('F12', devTools);

		localShortcut.register('CmdOrCtrl+R', refresh);
		localShortcut.register('F5', refresh);
	});
Пример #5
0
function createWindow(tabInfo) {
  // Create the browser window.
  const browser = new BrowserWindow({
    center: false,
    width: 1366,
    height: 768,
    minWidth: 512,
    minHeight: 128,
    frame: false,
    show: false,
  });
  mainWindows.push(browser);

  browser.loadURL(fileUrl(path.join(uiDir, 'browser', 'browser.html')));

  if (BUILD_CONFIG.development) {
    browser.openDevTools({ detach: true });
  }

  // Emitted when the window is closed.
  browser.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    const index = mainWindows.indexOf(browser);
    if (index > -1) {
      mainWindows.splice(index, 1);
    }
  });

  electronLocalshortcut.register(browser, 'CmdOrCtrl+L', () => {
    browser.webContents.send('focus-urlbar');
  });

  electronLocalshortcut.register(browser, 'CmdOrCtrl+R', () => {
    browser.webContents.send('page-reload');
  });

  browser.webContents.once('did-finish-load', () => {
    const browserDidFinishLoadTime = Date.now();
    instrument.event('browser', 'READY', 'ms', browserDidFinishLoadTime - browserStartTime);

    browser.show();

    if (tabInfo) {
      browser.webContents.send('tab-attach', tabInfo);
    }

    // TODO: Don't achieve this with a hammer.
    sendDiffsToWindows(true);
  });
}
Пример #6
0
            Application.on("ready", function() {
                // CTRL+F12 to toggle the dev tools
                Shortcuts.register("CmdOrCtrl+F12", function() {
                    var window = windowManager.getCurrent();
                    if (window) window.toggleDevTools();
                });

                // CTRL+R to reload the page
                Shortcuts.register("CmdOrCtrl+R", function() {
                    var window = windowManager.getCurrent();
                    if (window) window.reload();
                });
            });
Пример #7
0
function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 1366, height: 790, autoHideMenuBar: true});

  // and load the index.html of the app.
  mainWindow.loadURL('file://' + __dirname + '/index.html');

  // Open the DevTools.
  //mainWindow.webContents.openDevTools();

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });

  screen = electron.screen;
  displays = screen.getAllDisplays();
  console.log('enumerated', displays.length, 'displays.');
  mainWindow.setFullScreen(true);

  // register two local shortcuts
  electronLocalshortcut.register('CommandOrControl+Shift+Left', function() {
    currentDisplay--;
    if (currentDisplay < 0) {
      currentDisplay = displays.length - 1;
    }
    currentDisplay%=(displays.length);
    console.log('switching to display', currentDisplay + 1, 'out of', displays.length);
    mainWindow.setFullScreen(false);
    setTimeout(function() {
      mainWindow.setBounds(displays[currentDisplay].bounds);
      mainWindow.setFullScreen(true);
    }, 100);
  });

  electronLocalshortcut.register('CommandOrControl+Shift+Right', function() {
    currentDisplay++;
    currentDisplay%=(displays.length);
    console.log('switching to display', currentDisplay + 1, 'out of', displays.length);
    mainWindow.setFullScreen(false);
    setTimeout(function() {
      mainWindow.setBounds(displays[currentDisplay].bounds);
      mainWindow.setFullScreen(true);
    }, 100);
  });
}
Пример #8
0
app.on('ready', () => {
	electron.Menu.setApplicationMenu(appMenu);
	mainWindow = createMainWindow();
	// Not using for now // tray.create();

	const page = mainWindow.webContents;

	// TODO - use global shortcut instead
	electronLocalshortcut.register(mainWindow, 'CommandOrControl+R', () => {
		mainWindow.reload();
		mainWindow.webContents.send('destroytray');
	});

	electronLocalshortcut.register(mainWindow, 'CommandOrControl+[', () => {
		if (page.canGoBack()) {
			page.goBack();
		}
	});

	electronLocalshortcut.register(mainWindow, 'CommandOrControl+]', () => {
		if (page.canGoForward()) {
			page.goForward();
		}
	});

	page.on('dom-ready', () => {
		page.insertCSS(fs.readFileSync(path.join(__dirname, '../renderer/css/preload.css'), 'utf8'));
		mainWindow.show();
	});

	page.on('new-window', (event, url) => {
		if (linkIsInternal(checkWindowURL(), url) && url.match(skipImages) === null) {
			event.preventDefault();
			return mainWindow.loadURL(url);
		}
		event.preventDefault();
		electron.shell.openExternal(url);
	});

	page.once('did-frame-finish-load', () => {
		const checkOS = isWindowsOrmacOS();
		if (checkOS && !isDev) {
			// Initate auto-updates on MacOS and Windows
			appUpdater();
		}
	});
	checkConnection();
});
Пример #9
0
function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 1360, height: 800});

  // and load the index.html of the app.
  mainWindow.loadURL('file://' + __dirname + '/public/index.html');

  // Open the DevTools.
  mainWindow.webContents.openDevTools();


  /* 
    Registering a shortcut so that it can be listened to. 
  */


  // Check whether a shortcut is registered.
  electronLocalshortcut.register(mainWindow, 'Cmd+F', () => {
    console.log('You pressed cmd & F');
    mainWindow.webContents.send('ping','who are you?');
  });

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
  mainWindow.showDefinitionForSelection()
}
Пример #10
0
module.exports.register = (win) => {
  // Most of these events will simply be listened to by the app store and acted
  // upon.  However sometimes there are no state changes, for example with focusing
  // the URL bar.  In those cases it's acceptable for the individual components to
  // listen to the events.
  const simpleWebContentEvents = [
    ['CmdOrCtrl+Shift+]', messages.SHORTCUT_NEXT_TAB],
    ['CmdOrCtrl+Shift+[', messages.SHORTCUT_PREV_TAB],
    ['CmdOrCtrl+Alt+Right', messages.SHORTCUT_NEXT_TAB],
    ['CmdOrCtrl+Alt+Left', messages.SHORTCUT_PREV_TAB],
    ['Ctrl+PageDown', messages.SHORTCUT_NEXT_TAB],
    ['Ctrl+PageUp', messages.SHORTCUT_PREV_TAB],
    ['CmdOrCtrl+9', messages.SHORTCUT_SET_ACTIVE_FRAME_TO_LAST],
    ['CmdOrCtrl+G', messages.SHORTCUT_ACTIVE_FRAME_FIND_NEXT],
    ['CmdOrCtrl+Alt+U', messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE],
    ['CmdOrCtrl+Shift+G', messages.SHORTCUT_ACTIVE_FRAME_FIND_PREV],
    ['CmdOrCtrl+Alt+J', messages.SHORTCUT_ACTIVE_FRAME_TOGGLE_DEV_TOOLS],
    ['CmdOrCtrl+Shift+=', messages.SHORTCUT_ACTIVE_FRAME_ZOOM_IN],
    ['CmdOrCtrl+Shift+-', messages.SHORTCUT_ACTIVE_FRAME_ZOOM_OUT]
  ]

  if (!isDarwin) {
    simpleWebContentEvents.push(
      ['F5', messages.SHORTCUT_ACTIVE_FRAME_RELOAD],
      ['Ctrl+F5', messages.SHORTCUT_ACTIVE_FRAME_CLEAN_RELOAD],
      ['Ctrl+F4', messages.SHORTCUT_CLOSE_FRAME],
      ['Alt+D', messages.SHORTCUT_FOCUS_URL],
      ['Alt+Left', messages.SHORTCUT_ACTIVE_FRAME_BACK],
      ['Alt+Right', messages.SHORTCUT_ACTIVE_FRAME_FORWARD])
  } else if (process.env.NODE_ENV !== 'development') {
    // We're in Darwin and release or test mode...
    // We disable for development mode because Browser level dev tools copy doesn't work.
    // Workaround for #1060
    simpleWebContentEvents.push([
      'Cmd+C',
      messages.SHORTCUT_ACTIVE_FRAME_COPY
    ])
  }

  // Tab ordering shortcuts
  Array.from(new Array(8), (x, i) => i).reduce((list, i) => {
    list.push([`CmdOrCtrl+${String(i + 1)}`, messages.SHORTCUT_SET_ACTIVE_FRAME_BY_INDEX, i])
    return list
  }, simpleWebContentEvents)

  simpleWebContentEvents.forEach((shortcutEventName) =>
    electronLocalshortcut.register(win, shortcutEventName[0], () => {
      let win = BrowserWindow.getFocusedWindow()
      if (win) {
        win.webContents.send(shortcutEventName[1], shortcutEventName[2])
      }
    }))

  electronLocalshortcut.register(win, 'Shift+F8', () => {
    let win = BrowserWindow.getFocusedWindow()
    if (win) {
      win.toggleDevTools()
    }
  })
}
Пример #11
0
var createWindow = () => {
	win = new BrowserWindow({
		width: process.platform === 'darwin' ? 398 : 425,
		height: process.platform === 'darwin' ? 285 : 324,
		titleBarStyle: 'hidden',
		resizable: false,
		title: 'WoW Stat',
		show: false
	});

	win.loadURL(`file://${__dirname}/index.html`);

	win.on('closed', () => {
		win = null;
	});

	win.on('close', (e) => {
		if (!willQuit) {
			win.hide();
			e.preventDefault();
		}
	});

	app.on('before-quit', () => willQuit = true);

	shortcut.register(win, 'CmdOrCtrl+H', () => {
		win.hide();
	});

	// dev
	if (process.env.ELECTRON_DEV) {
		win.webContents.openDevTools();
	}
};
Пример #12
0
  open(fullPath) {
    let width = 200, height = 200;
    const file = path.basename(fullPath);
    let instance = this.all[file];
    let bounds;

    if (instance && instance.bounds) {
      bounds = instance.bounds;
      width = bounds.width;
      height = bounds.height;
    } else {
      instance = new _Instance();
      this.all[file] = instance;
    }

    let options = {
      width, height, frame: false, show: false,
      fullscreen: false, minimizable: true, maximizable: false,
      webPreferences: {webSecurity: false}
    };

    if (bounds) {
      Object.assign(options, {x: bounds.x, y: bounds.y});
    }

    const window = new BrowserWindow(options);

    _windows.push(window);

    instance.path = fullPath;

    window.instance = instance;
    window.loadURL(`file://${__dirname}/renderer/post.html`);
    window.setMenu(null);

    const updateBounds = () => {
      Object.assign(window.instance.bounds, window.getBounds());
    };
    window.on('resize', updateBounds);
    window.on('move', updateBounds);

    electronLocalshortcut.register(window,
      'CommandOrControl+Shift+I', () => { window.openDevTools();
    });

    // BrouserWindowインスタンスへの参照を破棄しているだけ。
    // アプリ終了後に参照残りに関連するっぽいエラーが出るが、原因不明。
    // 破棄に関してはこれだけやれば十分なはずだが…
    window.on('closed', () => {
      for(var i = 0; i < _windows.length; i++) {
        if (_windows[i] === window) {
          _windows[i] = null;
          delete _windows[i];
        }
      }
      _windows = _windows.filter((win) => {
        return (win !== null);
      });
    });
  }
Пример #13
0
 simpleWebContentEvents.forEach((shortcutEventName) =>
   electronLocalshortcut.register(win, shortcutEventName[0], () => {
     let win = BrowserWindow.getFocusedWindow()
     if (win) {
       win.webContents.send(shortcutEventName[1], shortcutEventName[2])
     }
   }))
Пример #14
0
function init (menu, windows) {
  // ⌘+Shift+F is an alternative fullscreen shortcut to the ones defined in menu.js.
  // Electron does not support multiple accelerators for a single menu item, so this
  // is registered separately here.
  localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen)

  // Special "media key" for play/pause, available on some keyboards
  globalShortcut.register('MediaPlayPause', () => windows.main.send('dispatch', 'playPause'))
}
Пример #15
0
    Window.prototype.registerShortcut = function(accelerator, callback){
        var instance = this;

        Shortcuts.register(this.object, accelerator, function(){
            callback.call(null, instance);
        });

        return this;
    };
Пример #16
0
function createWindow () {
  // Create the browser window.
  // {width: 500, height: 245, frame: false}
  mainWindow = new BrowserWindow({width: 500, height: 245, frame: false})

  // and load the index.html of the app.
  mainWindow.loadURL(`file://${__dirname}/app.html`)

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
  })

  // global shortcut events 
  shortcut.register(mainWindow, 'Ctrl+D', () => {
    mainWindow.webContents.send('global-shortcut', 'jump');
  });

  shortcut.register(mainWindow, 'Ctrl+N', () => {
    mainWindow.webContents.send('global-shortcut', 'next');
  });

  shortcut.register(mainWindow, 'Ctrl+L', () => {
    mainWindow.webContents.send('global-shortcut', 'login');
  });

  shortcut.register(mainWindow, 'Ctrl+U', () => {
    mainWindow.webContents.send('global-shortcut', 'heart');
  });  

  shortcut.register(mainWindow, 'Ctrl+S', () => {
    mainWindow.webContents.send('global-shortcut', 'lrc');
  });  

  shortcut.register(mainWindow, 'Ctrl+Q', () => {
    mainWindow.webContents.send('global-shortcut', 'quit');
  });  

  shortcut.register(mainWindow, 'Ctrl+Shift+M', () => {
    mainWindow.webContents.send('global-shortcut', 'menu');
  });  

  shortcut.register(mainWindow, 'Space', () => {
    mainWindow.webContents.send('global-shortcut', 'play');
  });  
}
Пример #17
0
export function createShellWindow () {
  // create window
  var { x, y, width, height } = ensureVisibleOnSomeDisplay(restoreState())
  var win = new BrowserWindow({ 
    titleBarStyle: 'hidden-inset',
    'standard-window': false,
    x, y, width, height,
    webPreferences: {
      webSecurity: false, // disable same-origin-policy in the shell window, webviews have it restored
      allowRunningInsecureContent: false
    },
    icon: path.join(__dirname, './assets/img/logo.png')
  })
  downloads.registerListener(win)
  loadShell(win)
  numActiveWindows++

  // register shortcuts
  for (var i=1; i <= 9; i++)
    registerShortcut(win, 'CmdOrCtrl+'+i, onTabSelect(win, i-1))
  registerShortcut(win, 'Ctrl+Tab', onNextTab(win))
  registerShortcut(win, 'Ctrl+Shift+Tab', onPrevTab(win))
  registerShortcut(win, 'CmdOrCtrl+[', onGoBack(win))
  registerShortcut(win, 'CmdOrCtrl+]', onGoForward(win))

  // register event handlers
  win.on('scroll-touch-begin', sendToWebContents('scroll-touch-begin'))
  win.on('scroll-touch-end', sendToWebContents('scroll-touch-end'))
  win.on('focus', sendToWebContents('focus'))
  win.on('blur', sendToWebContents('blur'))
  win.on('enter-full-screen', sendToWebContents('enter-full-screen'))
  win.on('leave-full-screen', sendToWebContents('leave-full-screen'))
  win.on('close', onClose(win))

  return win
}
Пример #18
0
function createWindow(tabInfo) {
  // Create the browser window.
  const browser = new BrowserWindow({
    center: false,
    width: 1024,
    height: 720,
    frame: false,
    show: false,
  });
  mainWindows.push(browser);

  browser.loadURL('http://localhost:8765/browser.html');

  if (!isProduction()) {
    browser.openDevTools({ detach: true });
  }

  // Emitted when the window is closed.
  browser.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    const index = mainWindows.indexOf(browser);
    if (index > -1) {
      mainWindows.splice(index, 1);
    }
  });

  electronLocalshortcut.register(browser, 'CmdOrCtrl+L', () => {
    browser.webContents.send('focus-urlbar');
  });

  browser.webContents.once('did-finish-load', () => {
    const browserDidFinishLoadTime = Date.now();
    instrument.event('browser', 'READY', 'ms', browserDidFinishLoadTime - browserStartTime);

    browser.show();

    if (tabInfo) {
      browser.webContents.send('tab-attach', tabInfo);
    } else {
      browser.webContents.send('new-tab');
    }
  });
}
Пример #19
0
module.exports.register = (win) => {
  // Most of these events will simply be listened to by the app store and acted
  // upon.  However sometimes there are no state changes, for example with focusing
  // the URL bar.  In those cases it's acceptable for the individual components to
  // listen to the events.
  const simpleWebContentEvents = [
    ['CmdOrCtrl+Shift+]', messages.SHORTCUT_NEXT_TAB],
    ['CmdOrCtrl+Shift+[', messages.SHORTCUT_PREV_TAB],
    ['CmdOrCtrl+Alt+Right', messages.SHORTCUT_NEXT_TAB],
    ['CmdOrCtrl+Alt+Left', messages.SHORTCUT_PREV_TAB],
    ['Ctrl+PageDown', messages.SHORTCUT_NEXT_TAB],
    ['Ctrl+PageUp', messages.SHORTCUT_PREV_TAB],
    ['CmdOrCtrl+9', messages.SHORTCUT_SET_ACTIVE_FRAME_TO_LAST]
  ]

  if (!isDarwin) {
    simpleWebContentEvents.push(
      ['F5', messages.SHORTCUT_ACTIVE_FRAME_RELOAD],
      ['Ctrl+F5', messages.SHORTCUT_ACTIVE_FRAME_CLEAN_RELOAD],
      ['Ctrl+F4', messages.SHORTCUT_CLOSE_FRAME],
      ['Alt+D', messages.SHORTCUT_FOCUS_URL, false],
      ['Alt+Left', messages.SHORTCUT_ACTIVE_FRAME_BACK],
      ['Alt+Right', messages.SHORTCUT_ACTIVE_FRAME_FORWARD])

    electronLocalshortcut.register(win, 'F11', (win) => {
      const focusedWindow = win || BrowserWindow.getFocusedWindow()
      focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
    })
  }

  // Tab ordering shortcuts
  Array.from(new Array(8), (x, i) => i).reduce((list, i) => {
    list.push([`CmdOrCtrl+${String(i + 1)}`, messages.SHORTCUT_SET_ACTIVE_FRAME_BY_INDEX, i])
    return list
  }, simpleWebContentEvents)

  simpleWebContentEvents.forEach((shortcutEventName) =>
    electronLocalshortcut.register(win, shortcutEventName[0], () => {
      BrowserWindow.getFocusedWindow().webContents.send(shortcutEventName[1], shortcutEventName[2])
    }))
}
Пример #20
0
const buildShortcutsProd = (mainWindow, store) => {
  // Undo
  electronLocalshortcut.register('CommandOrControl+Z', () => {
    mainWindow.webContents.undo();
  });
  // Redo
  electronLocalshortcut.register('CommandOrControl+Shift+Z', () => {
    mainWindow.webContents.redo();
  });
  // Cut
  electronLocalshortcut.register('CommandOrControl+X', () => {
    mainWindow.webContents.cut();
  });
  // Copy
  electronLocalshortcut.register(mainWindow, 'CommandOrControl+C', () => {
    mainWindow.webContents.copy();
  });
  // Paste
  electronLocalshortcut.register('CommandOrControl+V', () => {
    mainWindow.webContents.paste();
  });
  // Select all
  electronLocalshortcut.register('CommandOrControl+A', () => {
    mainWindow.webContents.selectAll();
  });
  // Settings
  electronLocalshortcut.register('CommandOrControl+,', () => {
    navigateAppToSettings(mainWindow, store);
  });
  // Reload
  electronLocalshortcut.register('CommandOrControl+R', () => {
    mainWindow.webContents.reload();
  });
  // Hide window
  electronLocalshortcut.register('CommandOrControl+H', () => {
    if (process.platform === 'linux') {
      childProcess.exec('nautilus');
    } else {
      mainWindow.blur();
    }
  });

  // Dev tools - Optional shortcut, enabled via Settings
  const devToolsShortcutSetting = _.get(store.get('kiosk'), 'devToolsShortcut');

  if (devToolsShortcutSetting) {
    const devToolsOSShortcut = process.platform === 'darwin'
      ? 'Command+Option+I'
      : 'Control+Shift+I';
    electronLocalshortcut.register(devToolsOSShortcut, () => {
      mainWindow.webContents.openDevTools();
    });
  }

  // Quit
  electronLocalshortcut.register('CommandOrControl+Q', () => {
    app.quit();
  });
};
Пример #21
0
var createWindow = () => {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 1400,
    height: 800,
    icon: __dirname+'/app/img/markdownify.ico',
    title: appDetails.productName
  });

  // and load the index.html of the app.
  mainWindow.loadURL(mainPage);

  // Open the DevTools.
  mainWindow.webContents.openDevTools();

  // Emitted when the window is closed.
  mainWindow.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });

  mainWindow.on('close', e => {
    if (!isQuitting) {
      e.preventDefault();
      if (process.platform === 'darwin') {
        app.hide();
      } else {
        mainWindow.hide();
      }
    }
  });

  //Open anchor links in browser
  mainWindow.webContents.on('will-navigate', (e, url) => {
    e.preventDefault();
    shell.openExternal(url);
  });

  //Set native menubar
  var template = [
    {
      label: "&File",
      submenu: [
        {
          label: "New", 
          accelerator: "CmdOrCtrl+N", 
          click: () => {
            var focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('file-new');
          }
        },
        {
          label: "Open", 
          accelerator: "CmdOrCtrl+O", 
          click: () => {
            let focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('file-open');
          }
        },
        {
          label: "Save", 
          accelerator: "CmdOrCtrl+S", 
          click: () => {
            let focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('file-save');
          }
        },
        {
          label: "Save As", 
          accelerator: "CmdOrCtrl+Shift+S", 
          click: () => {
            var focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('file-save-as');
          }
        },
        {
          label: "Save As PDF", 
          accelerator: "CmdOrCtrl+Shift+P", 
          click: () => {
            var focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('file-pdf');
          }
        },
        {
          label: "Quit", 
          accelerator: "Command+Q", 
          click: app.quit
        }
      ]
    },
    {
      label: "&Edit",
      submenu: [
        {
          label: "Undo", 
          accelerator: "CmdOrCtrl+Z", 
          role: "undo"
        },
        {
          label: "Redo", 
          accelerator: "Shift+CmdOrCtrl+Z", 
          role: "redo"
        },
        {
          type: "separator"
        },
        {
          label: "Cut", 
          accelerator: "CmdOrCtrl+X", 
          role: "cut"
        },
        {
          label: "Copy", 
          accelerator: "CmdOrCtrl+C", 
          role: "copy"
        },
        {
          label: "Paste", 
          accelerator: "CmdOrCtrl+V", 
          role: "paste"
        },
        {
          label: "Select All", 
          accelerator: "CmdOrCtrl+A", 
          role: 'selectall'
        },
        {
          type: "separator"
        },
        {
          label: "Search", 
          accelerator: "CmdOrCtrl+F", 
          click: () => {
            let focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('ctrl+f');
          }
        },
        {
          label: "Replace", 
          accelerator: "CmdOrCtrl+Shift+F", 
          click: () => {
            let focusedWindow = BrowserWindow.getFocusedWindow();
            focusedWindow.webContents.send('ctrl+shift+f');
          }
        }
      ]
    },
    {
      label: "&View",
      submenu: [
        {
          label: "Toggle Full Screen", 
          accelerator:"F11", 
          click: () => {
            let focusedWindow = BrowserWindow.getFocusedWindow();
            let isFullScreen = focusedWindow.isFullScreen();
            focusedWindow.setFullScreen(!isFullScreen);
          }
        }
      ]
    },
    {
      label: "&Help",
      submenu: [
        {
          label: "Documentation", 
          click:  () => {
            shell.openExternal(appDetails.repository.docs);
          }
        },
        {
          label: "Report Issue", 
          click: () => {
            shell.openExternal(appDetails.bugs.url);
          }
        },
        {
          label: "About Markdownify", 
          click: () => {
            dialog.showMessageBox({title: "About Markdownify", type:"info", message: "A minimal Markdown Editor desktop app. \nMIT Copyright (c) 2016 Amit Merchant <*****@*****.**>", buttons: ["Close"] });
          }
        }
      ]
    }
  ];

  ipcMain.on('print-to-pdf', (event, filePath) => {

    const win = BrowserWindow.fromWebContents(event.sender)
    // Use default printing options
    win.webContents.printToPDF({pageSize: 'A4'}, (error, data) => {
      if (error) throw error
      fs.writeFile(filePath, data, (error) => {
        if (error) {
          throw error
        }
      })
    })

  });

  Menu.setApplicationMenu(Menu.buildFromTemplate(template));

  // Registering shortcuts for formatting markdown
  localShortcut.register(mainWindow, 'Ctrl+B', () => {
      mainWindow.webContents.send('ctrl+b');
  });

  localShortcut.register(mainWindow, 'Ctrl+i', () => {
      mainWindow.webContents.send('ctrl+i');
  });

  localShortcut.register(mainWindow, 'Ctrl+/', () => {
      mainWindow.webContents.send('ctrl+/');
  });

  localShortcut.register(mainWindow, 'Ctrl+l', () => {
      mainWindow.webContents.send('ctrl+l');
  });

  localShortcut.register(mainWindow, 'Ctrl+h', () => {
      mainWindow.webContents.send('ctrl+h');
  });

  localShortcut.register(mainWindow, 'Ctrl+Alt+i', () => {
      mainWindow.webContents.send('ctrl+alt+i');
  });

  localShortcut.register(mainWindow, 'Ctrl+Shift+t', () => {
      mainWindow.webContents.send('ctrl+shift+t');
  });

  tray.create(mainWindow);
}
Пример #22
0
app.on('ready', () => {
	mainWindow = createMainWindow();
	tray.create(mainWindow);

	const page = mainWindow.webContents;
	
	// let's find out back keycode
	// const back = () => {
	// 	if (process.platform !== 'darwin') {
	// 		return 'Backspace'
	// 	}
	// 	return 'Delete'
	// };

	// Add spellcheck dictionary
	SpellChecker.getDictionary("en-US", "./node_modules/simple-spellchecker/dict", function(err, result) {
	    if(!err) {
	        myDictionary = result;
	    }
	});

	// Define function for consult the dictionary.
	ipc.on('checkspell', function(event, word) {
	    var res = null;
	    if(myDictionary != null && word != null) {
	        res = myDictionary.spellCheck(word);
	    }
	    event.returnValue = res;
	});

	electronLocalshortcut.register(mainWindow, 'CommandOrControl+Left', () => {
		if (page.canGoBack()) {
			page.goBack();
		}
	 });


    electronLocalshortcut.register(mainWindow, 'CommandOrControl+=', () => {
    	page.executeJavaScript('zoomIn()');
	});

    electronLocalshortcut.register(mainWindow, 'CommandOrControl+-', () => {
		page.executeJavaScript('zoomOut()');
    });

   	electronLocalshortcut.register(mainWindow, 'CommandOrControl+0', () => {
		page.executeJavaScript('zoomActualSize()');
	});
    
    page.on('new-window', (event, url) => {
        if (mainWindow.useDefaultWindowBehaviour) {
            mainWindow.useDefaultWindowBehaviour = false;
            return;
        }
        if (linkIsInternal(checkWindowURL(), url)) {
        	event.preventDefault();
			return mainWindow.loadURL(url);
        }
        event.preventDefault();
        electron.shell.openExternal(url);
    });
});
Пример #23
0
    _createBrowserWindow(wm: WindowManager) {
        this._browserWindow = new BrowserWindow({
            icon: wm.getIcon(),
            show: false,
            autoHideMenuBar: true,
            webPreferences: {
                nodeIntegration: false,
                nodeIntegrationInWorker: false,
                // TODO: not a real os sandbox yet.
                // https://github.com/electron-userland/electron-builder/issues/2562
                // https://electronjs.org/docs/api/sandbox-option
                sandbox: true,
                // can't use contextIsolation because this will prevent
                // the preload script changes to the web app
                contextIsolation: false,
                webSecurity: true,
                preload: this._preloadjs
            }
        })
        this._browserWindow.setMenuBarVisibility(false)
        this.id = this._browserWindow.id
        this._ipc.addWindow(this.id)

        this._browserWindow.webContents.session.setPermissionRequestHandler(this._permissionRequestHandler)
        wm.dl.manageDownloadsForSession(this._browserWindow.webContents.session)

        this._browserWindow
            .on('closed', () => {
                this.setUserInfo(null)
                this._ipc.removeWindow(this.id)
            })
            .on('focus', () => localShortcut.enableAll(this._browserWindow))
            .on('blur', ev => localShortcut.disableAll(this._browserWindow))

        this._browserWindow.webContents
            .on('new-window', (e, url) => {
                // we never open any new windows directly from the renderer
                // except for links in mails etc. so open them in the browser
                shell.openExternal(url)
                e.preventDefault()
            })
            .on('will-attach-webview', e => e.preventDefault())
            .on('did-start-navigation', (e, url, isInPlace) => {
                const newURL = this._rewriteURL(url, isInPlace)
                if (newURL !== url) {
                    e.preventDefault()
                    this._browserWindow.loadURL(newURL)
                }
            })
            .on('context-menu', (e, params) => {
                this.sendMessageToWebContents('open-context-menu', [{linkURL: params.linkURL}])
            })
            .on('crashed', () => wm.recreateWindow(this))
        /**
         * we need two conditions for the context menu to work on every window
         * 1. the preload script must have run already on this window
         * 2. the first web app instance must have sent the translations to the node thread
         * dom-ready is after preload and after the index.html was loaded into the webContents,
         * but may be before any javascript ran
         */
        this._browserWindow.webContents.on('dom-ready', () => {
            lang.initialized.promise.then(() => this.sendMessageToWebContents('setup-context-menu', []))
        })

        localShortcut.register(this._browserWindow, 'CommandOrControl+F', () => this._openFindInPage())
        localShortcut.register(this._browserWindow, 'CommandOrControl+P', () => this._printMail())
        localShortcut.register(this._browserWindow, 'F12', () => this._toggleDevTools())
        localShortcut.register(this._browserWindow, 'F5', () => this._browserWindow.loadURL(this._startFile))
        localShortcut.register(this._browserWindow, 'CommandOrControl+W', () => this._browserWindow.close())
        localShortcut.register(this._browserWindow, 'CommandOrControl+H', () => this._browserWindow.hide())
        localShortcut.register(this._browserWindow, 'CommandOrControl+N', () => wm.newWindow(true))
        localShortcut.register(
            this._browserWindow,
            process.platform === 'darwin'
                ? 'Command+Control+F'
                : 'F11',
            () => this._toggleFullScreen()
        )
    }
Пример #24
0
app.on('ready', function onReady() {
    mainWindow = new BrowserWindow({
      minWidth: 1024,
      minHeight: 768,
      width: 1024,
      height: 768,
      icon: `${dirname}/dist/assets/icons/linux.png`
    });

    mainWindow.setMenu(null);

    mainWindow.maximize();

    delete mainWindow.module;

    // If you want to open up dev tools programmatically, call
    // mainWindow.openDevTools();

    // By default, we'll open the Ember App by directly going to the
    // file system.
    //
    // Please ensure that you have set the locationType option in the
    // config/environment.js file to 'hash'. For more information,
    // please consult the ember-electron readme.
    mainWindow.loadURL(emberAppLocation);

    // If a loading operation goes wrong, we'll send Electron back to
    // Ember App entry point
    mainWindow.webContents.on('did-fail-load', () => {
        mainWindow.loadURL(emberAppLocation);
    });

    mainWindow.webContents.on('crashed', () => {
        console.log('Your Ember app (or other code) in the main window has crashed.');
        console.log('This is a serious issue that needs to be handled and/or debugged.');
    });

    mainWindow.on('unresponsive', () => {
        console.log('Your Ember app (or other code) has made the window unresponsive.');
    });

    mainWindow.on('responsive', () => {
        console.log('The main window has become responsive again.');
    });

    mainWindow.on('closed', () => {
        mainWindow = null;
    });

    // Handle an unhandled error in the main thread
    //
    // Note that 'uncaughtException' is a crude mechanism for exception handling intended to
    // be used only as a last resort. The event should not be used as an equivalent to
    // "On Error Resume Next". Unhandled exceptions inherently mean that an application is in
    // an undefined state. Attempting to resume application code without properly recovering
    // from the exception can cause additional unforeseen and unpredictable issues.
    //
    // Attempting to resume normally after an uncaught exception can be similar to pulling out
    // of the power cord when upgrading a computer -- nine out of ten times nothing happens -
    // but the 10th time, the system becomes corrupted.
    //
    // The correct use of 'uncaughtException' is to perform synchronous cleanup of allocated
    // resources (e.g. file descriptors, handles, etc) before shutting down the process. It is
    // not safe to resume normal operation after 'uncaughtException'.
    process.on('uncaughtException', (err) => {
        console.log('An exception in the main thread was not handled.');
        console.log('This is a serious issue that needs to be handled and/or debugged.');
        console.log(`Exception: ${err}`);
    });

    // Open external links in default browser
    let handleRedirect = (e, url) => {
      if(url !== mainWindow.webContents.getURL()) {
        e.preventDefault();
        shell.openExternal(url);
      }
    };

    mainWindow.webContents.on('will-navigate', handleRedirect);
    mainWindow.webContents.on('new-window', handleRedirect);

    // Shortcuts
    localshortcut.register(mainWindow, 'F11', () => {
      mainWindow.setFullScreen(!mainWindow.isFullScreen());
    });

    localshortcut.register(mainWindow, 'Shift+CmdOrCtrl+I', () => {
      mainWindow.webContents.toggleDevTools();
    });

    localshortcut.register(mainWindow, 'CmdOrCtrl+R', () => {
      mainWindow.reload();
    });
});
Пример #25
0
function createMainWindow() {
	const win = new electron.BrowserWindow({
		// This settings needs to be saved in config
		title: 'Zulip',
		width: conf.get('width') || 1000,
		height: conf.get('height') || 600,
		icon: iconPath(),
		minWidth: 600,
		minHeight: 400,
		webPreferences: {
			preload: path.join(__dirname, 'preload.js'),
			nodeIntegration: true,
			plugins: true
		}
	});

	win.loadURL(targetUrl);
	win.on('closed', onClosed);
	win.setTitle('Zulip');

	// Let's save browser window position 
	if (conf.get('x') || conf.get('y')) {
	  win.setPosition(conf.get('x'), conf.get('y'));
	}

	if (conf.get('maximize')) {
	  win.maximize();
	}

	// Handle sizing events so we can persist them.
	win.on('maximize', function (event) {
	  conf.set('maximize', true);
	});

	win.on('unmaximize', function (event) {
	  conf.set('maximize', false);
	});

	win.on('resize', function (event) {
	  var size = this.getSize();
	  conf.set({
	    width: size[0],
	    height: size[1]
	  });
	});

	// on osx it's 'moved'
	win.on('move', function (event) {
	  var pos = this.getPosition();
	  conf.set({
	    x: pos[0],
	    y: pos[1]
	  });
	});

	// stop page to update it's title
	win.on('page-title-updated', (e) => {
	e.preventDefault();
	});

	// TODO - use global shortcut instead
	electronLocalshortcut.register(win, 'CommandOrControl+R', () => {
	   win.reload();
	 });

	return win;
}
Пример #26
0
export function createShellWindow () {
  // create window
  var { x, y, width, height } = ensureVisibleOnSomeDisplay(restoreState())
  var win = new BrowserWindow({ 
    titleBarStyle: 'hidden-inset',
    'standard-window': false,
    x, y, width, height,
    webPreferences: {
      webSecurity: false, // disable same-origin-policy in the shell window, webviews have it restored
      allowRunningInsecureContent: false
    }
  })


    //safe filter
    let filter = {
        urls: ['http://*/*', 'https://*/*' ]
      
    }
    win.webContents.session.webRequest.onBeforeRequest(filter, (details, callback) => 
    {
        const parsedUrl = url.parse(details.url)
        
        if( typeof(win.webContents.isSafe) === 'undefined' )
        {
            win.webContents.isSafe = true
        }
       
        if( ! win.webContents.isSafe || parsedUrl.host.indexOf( 'localhost' ) === 0 )
        {
            callback({})
            return
        }
            
        if( details.url.indexOf('http') > -1 )
        {
          callback({ cancel: true })
          
        }
    })
    
    //extra shortcuts outside of menus
    electronLocalshortcut.register(win, 'Alt+D', () => 
    {
        if (win) win.webContents.send('command', 'file:open-location')
    })
  
    
    store.subscribe( e => 
    {        
        saveStore();    
        win.webContents.send('safeStore-updated')

    })

  
  
  downloads.registerListener(win)
  loadURL(win, 'beaker:shell-window')
  numActiveWindows++

  // register shortcuts
  for (var i=1; i <= 9; i++)
    registerShortcut(win, 'CmdOrCtrl+'+i, onTabSelect(win, i-1))
  registerShortcut(win, 'Ctrl+Tab', onNextTab(win))
  registerShortcut(win, 'Ctrl+Shift+Tab', onPrevTab(win))

  // register event handlers
  win.on('scroll-touch-begin', sendToWebContents('scroll-touch-begin'))
  win.on('scroll-touch-end', sendToWebContents('scroll-touch-end'))
  win.on('focus', sendToWebContents('focus'))
  win.on('blur', sendToWebContents('blur'))
  win.on('enter-full-screen', sendToWebContents('enter-full-screen'))
  win.on('leave-full-screen', sendToWebContents('leave-full-screen'))
  win.on('close', onClose(win))

  return win
}
Пример #27
0
 HOTKEYS.forEach((handlerFactory, accelerator) => {
   shortcut.register(browserWindow, accelerator, handlerFactory(browserWindow));
 });
Пример #28
0
 registerLocalShortcut() {
   electronLocalShortcut.register(this.wechatWindow, 'CommandOrControl + H', () => {
     this.wechatWindow.hide();
   });
 }
Пример #29
0
 shortcuts.forEach(function(shortcut) {
   ShortcutManager.register(shortcut, function() {
     self._emitShortcutEvent(mainWindow, isWindowLoaded, shortcut);
   });
 });
Пример #30
0
function init (menu) {
  // ⌘+Shift+F is an alternative fullscreen shortcut to the one defined in menu.js.
  // Electron does not support multiple accelerators for a single menu item, so this
  // is registered separately here.
  localShortcut.register('CmdOrCtrl+Shift+F', menu.toggleFullScreen)
}