Best JavaScript code snippet using playwright-internal
menuManager.js
Source:menuManager.js
1var electron = require('electron'),2 Menu = electron.Menu,3 MenuItem = electron.MenuItem,4 windowManager = require('./windowManager').windowManager,5 path = require('path'),6 _ = require('lodash').noConflict(),7 menuManager = {},8 os = require('os'),9 BrowserWindow = require('electron').BrowserWindow,10 appName = electron.app.getName(),11 APP_UPDATE = 'app-update',12 APP_UPDATE_EVENTS = 'app-update-events',13 CHECK_FOR_ELECTRON_UPDATE = 'checkForElectronUpdate',14 osxTopBarMenuTemplate = [15 {16 label: appName,17 submenu: [18 { role: 'about' },19 {20 label: 'Check for Updates...',21 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('checkElectronUpdates', null, options); }22 },23 { type: 'separator' },24 {25 label: 'Preferences',26 accelerator: 'CmdOrCtrl+,',27 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openSettings', null, options); }28 },29 {30 role: 'services',31 submenu: []32 },33 { type: 'separator' },34 { role: 'hide' },35 { role: 'hideothers' },36 { role: 'unhide' },37 { type: 'separator' },38 { role: 'quit' }39 ]40 },41 {42 label: 'File',43 submenu: [44 {45 label: 'New...',46 accelerator: 'CmdOrCtrl+N',47 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCreateNewModal', null, options); }48 },49 {50 label: 'New Tab',51 accelerator: 'CmdOrCtrl+T',52 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('newTab', null, options); }53 },54 {55 label: 'New Postman Window',56 accelerator: 'CmdOrCtrl+Shift+N',57 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('newWindow', null, options); }58 },59 {60 label: 'New Runner Window',61 accelerator: 'CmdOrCtrl+Shift+R',62 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openRunner', null, options); }63 },64 { type: 'separator' },65 {66 label: 'Import...',67 accelerator: 'CmdOrCtrl+O',68 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openImport', null, options); }69 },70 { type: 'separator' },71 {72 label: 'Close Window',73 accelerator: 'CmdOrCtrl+Shift+W',74 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('closeWindow', null, options); }75 },76 {77 label: 'Close Tab',78 accelerator: 'CmdOrCtrl+W',79 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('closeTab', null, options); }80 },81 {82 label: 'Force Close Tab',83 accelerator: 'CmdOrCtrl+Alt+W',84 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('forceCloseTab', null, options); }85 }86 ]87 },88 {89 label: 'Edit',90 submenu: [91 { role: 'undo' },92 { role: 'redo' },93 { type: 'separator' },94 { role: 'cut' },95 { role: 'copy' },96 { role: 'paste' },97 { role: 'pasteandmatchstyle' },98 { role: 'delete' },99 { role: 'selectall' }100 ]101 },102 {103 label: 'View',104 submenu: [105 { role: 'togglefullscreen' },106 {107 label: 'Zoom In',108 accelerator: 'CmdOrCtrl+Plus',109 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('increaseZoom', null, options); }110 },111 {112 label: 'Zoom Out',113 accelerator: 'CmdOrCtrl+-',114 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('decreaseZoom', null, options); }115 },116 {117 label: 'Reset Zoom',118 accelerator: 'CmdOrCtrl+0',119 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('resetZoom', null, options); }120 },121 {122 label: 'Toggle Sidebar',123 accelerator: 'CmdOrCtrl+\\',124 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleSidebar', null, options); }125 },126 {127 label: 'Toggle Two-Pane View',128 accelerator: 'CmdOrCtrl+Alt+V',129 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleLayout', null, options); }130 },131 { type: 'separator' },132 {133 label: 'Show Postman Console',134 accelerator: 'CmdOrCtrl+Alt+C',135 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openConsole', null, options); }136 },137 {138 label: 'Developer',139 submenu: [140 {141 label: 'Show DevTools (Current View)',142 accelerator: (function () {143 if (process.platform == 'darwin') {144 return 'Alt+Command+I';145 }146 else {147 return 'Ctrl+Shift+I';148 }149 }()),150 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleDevTools', null, options); }151 },152 {153 label: 'Show DevTools (Current Shell)',154 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleShellDevTools', null, options); }155 },156 { type: 'separator' },157 {158 label: 'Show DevTools (Shared)',159 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleSharedDevTools', null, options); }160 },161 {162 label: 'Show DevTools (Shared Shell)',163 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleSharedShellDevTools', null, options); }164 }165 ]166 }167 ]168 },169 {170 role: 'window',171 submenu: [172 { role: 'minimize' },173 { role: 'close' },174 { type: 'separator' },175 {176 label: 'Next Tab',177 accelerator: 'Command+Shift+]',178 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('nextTab', null, options); }179 },180 {181 label: 'Previous Tab',182 accelerator: 'Command+Shift+[',183 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('previousTab', null, options); }184 },185 { type: 'separator' },186 { role: 'front' }187 ]188 },189 {190 role: 'help',191 submenu: [192 {193 label: 'Documentation',194 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://www.getpostman.com/docs/', options); }195 },196 {197 label: 'GitHub',198 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://github.com/postmanlabs/postman-app-support/', options); }199 },200 {201 label: 'Twitter',202 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://twitter.com/postmanclient', options); }203 },204 {205 label: 'Support',206 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://getpostman.com/support', options); }207 }208 ]209 }210 ],211 topBarMenuTemplate = [212 {213 label: 'File',214 submenu: [215 {216 label: 'New...',217 accelerator: 'CmdOrCtrl+N',218 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCreateNewModal', null, options); }219 },220 {221 label: 'New Tab',222 accelerator: 'CmdOrCtrl+T',223 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('newTab', null, options); }224 },225 {226 label: 'New Postman Window',227 accelerator: 'CmdOrCtrl+Shift+N',228 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('newWindow', null, options); }229 },230 {231 label: 'New Runner Window',232 accelerator: 'CmdOrCtrl+Shift+R',233 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openRunner', null, options); }234 },235 { type: 'separator' },236 {237 label: 'Import...',238 accelerator: 'CmdOrCtrl+O',239 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openImport', null, options); }240 },241 { type: 'separator' },242 {243 label: 'Settings',244 accelerator: 'CmdOrCtrl+,',245 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openSettings', null, options); }246 },247 { type: 'separator' },248 {249 label: 'Close Window',250 accelerator: 'CmdOrCtrl+Shift+W',251 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('closeWindow', null, options); }252 },253 {254 label: 'Close Tab',255 accelerator: 'CmdOrCtrl+W',256 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('closeTab', null, options); }257 },258 {259 label: 'Force Close Tab',260 accelerator: 'CmdOrCtrl+Alt+W',261 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('forceCloseTab', null, options); }262 },263 { role: 'quit' }264 ]265 },266 {267 label: 'Edit',268 submenu: [269 { role: 'undo' },270 { role: 'redo' },271 { type: 'separator' },272 { role: 'cut' },273 { role: 'copy' },274 { role: 'paste' },275 { role: 'pasteandmatchstyle' },276 { role: 'delete' },277 { role: 'selectall' }278 ]279 },280 {281 label: 'View',282 submenu: [283 { role: 'togglefullscreen' },284 {285 label: 'Zoom In',286 accelerator: 'CmdOrCtrl+=',287 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('increaseZoom', null, options); }288 },289 {290 label: 'Zoom Out',291 accelerator: 'CmdOrCtrl+-',292 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('decreaseZoom', null, options); }293 },294 {295 label: 'Reset Zoom',296 accelerator: 'CmdOrCtrl+0',297 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('resetZoom', null, options); }298 },299 {300 label: 'Toggle Sidebar',301 accelerator: 'CmdOrCtrl+\\',302 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleSidebar', null, options); }303 },304 {305 label: 'Toggle Two-Pane View',306 accelerator: 'CmdOrCtrl+Alt+V',307 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleLayout', null, options); }308 },309 { type: 'separator' },310 {311 label: 'Next Tab',312 accelerator: 'CmdOrCtrl+Tab',313 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('nextTab', null, options); }314 },315 {316 label: 'Previous Tab',317 accelerator: 'CmdOrCtrl+Shift+Tab',318 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('previousTab', null, options); }319 },320 { type: 'separator' },321 {322 label: 'Show Postman Console',323 accelerator: 'CmdOrCtrl+Alt+C',324 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openConsole', null, options); }325 },326 {327 label: 'Developer',328 submenu: [329 {330 label: 'Show DevTools (Current View)',331 accelerator: (function () {332 if (process.platform == 'darwin') {333 return 'Alt+Command+I';334 }335 else {336 return 'Ctrl+Shift+I';337 }338 }()),339 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleDevTools', null, options); }340 },341 {342 label: 'Show DevTools (Current Shell)',343 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleShellDevTools', null, options); }344 },345 { type: 'separator' },346 {347 label: 'Show DevTools (Shared)',348 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleSharedDevTools', null, options); }349 },350 {351 label: 'Show DevTools (Shared Shell)',352 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('toggleSharedShellDevTools', null, options); }353 }354 ]355 }356 ]357 },358 {359 label: 'Help',360 role: 'help',361 submenu: [362 {363 label: 'Check for Updates',364 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('checkElectronUpdates', null, options); }365 },366 { type: 'separator' },367 {368 label: 'Documentation',369 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://www.getpostman.com/docs/', options); }370 },371 {372 label: 'GitHub',373 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://github.com/postmanlabs/postman-app-support/', options); }374 },375 {376 label: 'Twitter',377 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://twitter.com/postmanclient', options); }378 },379 {380 label: 'Support',381 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('openCustomUrl', 'https://getpostman.com/support', options); }382 }383 ]384 }385 ],386 dockMenuTemplate = [387 {388 label: 'New Collection',389 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('newCollection', null, options); }390 },391 {392 label: 'New Window ',393 click: function (menuItem, browserWindow, options) { menuManager.handleMenuAction('newWindow', null, options); }394 }395 ];396menuManager = {397 dockMenuTemplate: dockMenuTemplate,398 createMenu: function () {399 Menu.setApplicationMenu(400 Menu.buildFromTemplate(401 this.getMenuBarTemplate()402 )403 );404 },405 getMenuBarTemplate: function () {406 var platform = os.platform();407 if (platform === 'darwin') {408 return osxTopBarMenuTemplate;409 }410 else {411 return topBarMenuTemplate;412 }413 },414 handleMenuAction: function (action, meta, options) {415 if (action === 'toggleDevTools') {416 var win = BrowserWindow.getFocusedWindow();417 win && win.webContents.send('shellMessage', { type: 'toggleDevTools' });418 }419 else if (action === 'toggleShellDevTools') {420 var win = BrowserWindow.getFocusedWindow();421 if (win) {422 let webContents = win.webContents;423 (!webContents.isDevToolsOpened()) && (webContents.toggleDevTools({ mode: 'detach' }));424 }425 }426 else if (action === 'toggleSharedDevTools') {427 let sharedWindow = windowManager.getSharedWindow();428 sharedWindow && sharedWindow.webContents.send('shellMessage', { type: 'toggleDevTools' });429 }430 else if (action === 'toggleSharedShellDevTools') {431 let sharedWindow = windowManager.getSharedWindow();432 if (sharedWindow) {433 let webContents = sharedWindow.webContents;434 (!webContents.isDevToolsOpened()) && (webContents.toggleDevTools({ mode: 'detach' }));435 }436 }437 else if (action === 'newWindow') {438 windowManager.createOrRestoreRequesterWindow();439 }440 else if (action === 'openRunner') {441 windowManager.newRunnerWindow();442 }443 else if (action === 'openCustomUrl') {444 windowManager.openCustomURL(meta);445 }446 else if (action == 'openConsole') {447 windowManager.newConsoleWindow();448 }449 else if (action === 'openCreateNewModal') {450 windowManager.sendCustomInternalEvent(action);451 }452 else if (action === 'newTab') {453 windowManager.sendCustomInternalEvent(action);454 }455 else if (action === 'closeTab') {456 windowManager.sendCustomInternalEvent(action);457 }458 else if (action === 'forceCloseTab') {459 windowManager.sendCustomInternalEvent(action);460 }461 else if (action === 'closeWindow') {462 var win = BrowserWindow.getFocusedWindow();463 win && win.close();464 }465 else if (action === 'nextTab') {466 windowManager.sendCustomInternalEvent(action);467 }468 else if (action === 'previousTab') {469 windowManager.sendCustomInternalEvent(action);470 }471 else if (action === 'checkElectronUpdates') {472 let updaterEventBus = global.pm.eventBus.channel(APP_UPDATE_EVENTS);473 updaterEventBus.publish({ name: CHECK_FOR_ELECTRON_UPDATE, namespace: APP_UPDATE });474 }475 else {476 var win = BrowserWindow.getFocusedWindow();477 win && win.webContents.send('electronWindowMessage', {478 name: 'internalEvent',479 data: { event: action }480 });481 }482 }483};...
expr-click.js
Source:expr-click.js
1import {app, shell} from 'electron';2import * as piwik from 'browser/services/piwik';3import prefs from 'browser/utils/prefs';4/**5 * Call the handler for the check-for-update event.6 */7export function cfuCheckForUpdate (informUser) {8 return function () {9 global.application.autoUpdateManager.handleMenuCheckForUpdate(informUser);10 };11}12/**13 * Call the handler for the update-available event.14 */15export function cfuUpdateAvailable () {16 return function () {17 global.application.autoUpdateManager.handleMenuUpdateAvailable();18 };19}20/**21 * Call the handler for the update-downloaded event.22 */23export function cfuUpdateDownloaded () {24 return function () {25 global.application.autoUpdateManager.handleMenuUpdateDownloaded();26 };27}28/**29 * Reset the auto updater url (to use updated prefs).30 */31export function resetAutoUpdaterUrl () {32 return function () {33 global.application.autoUpdateManager.initFeedUrl();34 };35}36/**37 * Enable or disable automatic checks for update.38 */39export function checkForUpdateAuto (valueExpr) {40 return function () {41 const check = valueExpr.apply(this, arguments);42 global.application.autoUpdateManager.setAutoCheck(check);43 };44}45/**46 * Quit the app.47 */48export function appQuit () {49 return function () {50 app.quit();51 };52}53/**54 * Open the url externally, in a browser.55 */56export function openUrl (url) {57 return function () {58 shell.openExternal(url);59 };60}61/**62 * Send a message directly to the webview.63 */64export function sendToWebView (channel, ...valueExprs) {65 return function (menuItem, browserWindow) {66 if (!browserWindow) {67 browserWindow = global.application.mainWindowManager.window;68 }69 const values = valueExprs.map((e) => e.apply(this, arguments));70 browserWindow.webContents.send('fwd-webview', channel, ...values);71 };72}73/**74 * Reload the browser window.75 */76export function reloadWindow () {77 return function (menuItem, browserWindow) {78 if (!browserWindow) {79 browserWindow = global.application.mainWindowManager.window;80 }81 browserWindow.reload();82 };83}84/**85 * Reset the window's position and size.86 */87export function resetWindow () {88 return function (menuItem, browserWindow) {89 if (!browserWindow) {90 browserWindow = global.application.mainWindowManager.window;91 }92 const bounds = prefs.getDefault('window-bounds');93 browserWindow.setSize(bounds.width, bounds.height, true);94 browserWindow.center();95 };96}97/**98 * Show (and focus) the window.99 */100export function showWindow () {101 return function (menuItem, browserWindow) {102 if (!browserWindow) {103 browserWindow = global.application.mainWindowManager.window;104 }105 browserWindow.show();106 };107}108/**109 * Toggle whether the window is in full screen or not.110 */111export function toggleFullScreen () {112 return function (menuItem, browserWindow) {113 if (!browserWindow) {114 browserWindow = global.application.mainWindowManager.window;115 }116 const newState = !browserWindow.isFullScreen();117 browserWindow.setFullScreen(newState);118 };119}120/**121 * Toggle the dev tools panel.122 */123export function toggleDevTools () {124 return function (menuItem, browserWindow) {125 if (!browserWindow) {126 browserWindow = global.application.mainWindowManager.window;127 }128 browserWindow.toggleDevTools();129 };130}131/**132 * Toggle the menu bar of the window.133 */134export function toggleMenuBar () {135 return function (menuItem, browserWindow) {136 if (!browserWindow) {137 browserWindow = global.application.mainWindowManager.window;138 }139 const newState = !browserWindow.isMenuBarVisible();140 browserWindow.setMenuBarVisibility(newState);141 };142}143/**144 * Whether the window should always appear on top.145 */146export function floatOnTop (flagExpr) {147 return function (menuItem, browserWindow) {148 if (!browserWindow) {149 browserWindow = global.application.mainWindowManager.window;150 }151 const flag = flagExpr.apply(this, arguments);152 browserWindow.setAlwaysOnTop(flag);153 };154}155/**156 * Show or hide the tray icon.157 */158export function showInTray (flagExpr) {159 return function () {160 const show = flagExpr.apply(this, arguments);161 if (show) {162 global.application.trayManager.create();163 } else {164 global.application.trayManager.destroy();165 }166 };167}168/**169 * Show or hide the dock icon.170 */171export function showInDock (flagExpr) {172 return function () {173 if (app.dock) {174 const show = flagExpr.apply(this, arguments);175 if (show) {176 app.dock.show();177 } else {178 app.dock.hide();179 }180 }181 };182}183/**184 * Whether the app should launch automatically when the OS starts.185 */186export function launchOnStartup (enabledExpr) {187 return function () {188 const enabled = enabledExpr.apply(this, arguments);189 if (enabled) {190 global.application.autoLauncher.enable()191 .then(() => log('auto launcher enabled'))192 .catch((err) => {193 log('could not enable auto-launcher');194 logError(err);195 });196 } else {197 global.application.autoLauncher.disable()198 .then(() => log('auto launcher disabled'))199 .catch((err) => {200 log('could not disable auto-launcher');201 logError(err);202 });203 }204 };205}206/**207 * Trigger an update to count the unread messages again.208 */209export function updateUnreadMessagesCount () {210 return function (menuItem, browserWindow) {211 if (!browserWindow) {212 browserWindow = global.application.mainWindowManager.window;213 }214 browserWindow.webContents.send('update-unread-count');215 };216}217/**218 * If flag is false, the dock badge will be hidden.219 */220export function hideDockBadge (flagExpr) {221 return function () {222 const flag = flagExpr.apply(this, arguments);223 if (!flag) {224 app.setBadgeCount(0);225 }226 };227}228/**229 * If flag is false, the taskbar badge will be hidden.230 */231export function hideTaskbarBadge (flagExpr) {232 return function (menuItem, browserWindow) {233 if (!browserWindow) {234 browserWindow = global.application.mainWindowManager.window;235 }236 const flag = flagExpr.apply(this, arguments);237 if (!flag) {238 browserWindow.setOverlayIcon(null, '');239 }240 };241}242// Analytics243export const analytics = {244 /**245 * Track an event.246 */247 trackEvent: (...args) => {248 return function (menuItem, browserWindow) {249 piwik.getTracker().trackEvent(...args);250 };251 }252};253/**254 * Restart the app in debug mode.255 */256export function restartInDebugMode () {257 return function () {258 const options = {259 // without --no-console-logs, calls to console.log et al. trigger EBADF errors in the new process260 args: [...process.argv.slice(1), '--debug', '--no-console-logs']261 };262 log('relaunching app', JSON.stringify(options));263 app.relaunch(options);264 app.exit(0);265 };266}267/**268 * Open the log file for easier debugging.269 */270export function openDebugLog () {271 return function () {272 if (global.__debug_file_log_path) {273 log('opening log file with default app', global.__debug_file_log_path);274 shell.openItem(global.__debug_file_log_path);275 } else {276 logError(new Error('global.__debug_file_log_path was falsy'));277 }278 };...
mainWindow.js
Source:mainWindow.js
1import { remote } from 'electron';2import jetpack from 'fs-jetpack';3import { createElement, useEffect, useRef } from './reactiveUi';4const { app, screen } = remote;5const isInsideSomeScreen = ({ x, y, width, height }) =>6 screen.getAllDisplays()7 .some(({ bounds }) => x >= bounds.x && y >= bounds.y8 && x + width <= bounds.x + bounds.width && y + height <= bounds.y + bounds.height,9 );10const loadWindowState = async ([width, height]) => {11 try {12 console.log('====================================')13 console.log(process.env.NODE_ENV)14 console.log('====================================')15 const userDataDir = jetpack.cwd(app.getPath('userData'));16 const windowState = {17 width,18 height,19 ...await userDataDir.readAsync('window-state-main.json', 'json') || {},20 };21 if (!isInsideSomeScreen(windowState)) {22 const { bounds } = screen.getPrimaryDisplay();23 windowState.x = (bounds.width - width) / 2;24 windowState.y = (bounds.height - height) / 2;25 windowState.width = width;26 windowState.height = height;27 }28 return windowState;29 } catch (error) {30 console.error('Failed to load window state');31 console.error(error);32 return { width, height };33 }34};35const saveWindowState = async (windowState) => {36 try {37 const userDataDir = jetpack.cwd(app.getPath('userData'));38 await userDataDir.writeAsync('window-state-main.json', windowState, { atomic: true });39 } catch (error) {40 console.error('Failed to save window state');41 console.error(error);42 }43};44const applyWindowState = (browserWindow, windowState) => {45 if (browserWindow.isDestroyed()) {46 return;47 }48 if (windowState.x !== undefined && windowState.y !== undefined) {49 browserWindow.setPosition(Math.floor(windowState.x), Math.floor(windowState.y), false);50 }51 if (windowState.width !== undefined && windowState.height !== undefined) {52 browserWindow.setSize(Math.floor(windowState.width), Math.floor(windowState.height), false);53 }54 if (windowState.isMaximized) {55 browserWindow.maximize();56 } else if (windowState.isMinimized) {57 browserWindow.minimize();58 } else {59 browserWindow.restore();60 }61 if (windowState.isHidden) {62 browserWindow.hide();63 } else if (!windowState.isMinimized) {64 browserWindow.show();65 }66};67const fetchWindowState = (browserWindow, windowState) => {68 if (browserWindow.isDestroyed()) {69 return;70 }71 windowState.isMaximized = browserWindow.isMaximized();72 windowState.isMinimized = browserWindow.isMinimized();73 windowState.isHidden = !browserWindow.isMinimized() && !browserWindow.isVisible();74 if (!windowState.isMaximized && !windowState.isHidden) {75 [windowState.x, windowState.y] = browserWindow.getPosition();76 [windowState.width, windowState.height] = browserWindow.getSize();77 }78};79const useBeforeAppQuitEvent = (browserWindow, windowStateRef) => {80 useEffect(() => {81 const handleBeforeAppQuit = () => {82 remote.app.removeListener('before-quit', handleBeforeAppQuit);83 saveWindowState(windowStateRef.current);84 browserWindow.destroy();85 };86 remote.app.on('before-quit', handleBeforeAppQuit);87 return () => {88 remote.app.removeListener('before-quit', handleBeforeAppQuit);89 };90 }, [browserWindow, windowStateRef]);91};92const useWindowStateUpdates = (browserWindow, windowStateRef) => {93 const fetchAndSaveTimerRef = useRef();94 useEffect(() => {95 const fetchAndSaveWindowState = () => {96 clearTimeout(fetchAndSaveTimerRef.current);97 fetchAndSaveTimerRef.current = setTimeout(() => {98 fetchWindowState(browserWindow, windowStateRef.current);99 saveWindowState(windowStateRef.current);100 }, 1000);101 };102 browserWindow.on('resize', fetchAndSaveWindowState);103 browserWindow.on('move', fetchAndSaveWindowState);104 browserWindow.on('show', fetchAndSaveWindowState);105 return () => {106 browserWindow.removeListener('resize', fetchAndSaveWindowState);107 browserWindow.removeListener('move', fetchAndSaveWindowState);108 browserWindow.removeListener('show', fetchAndSaveWindowState);109 };110 }, [browserWindow, windowStateRef, fetchAndSaveTimerRef]);111};112const useWindowClosing = (browserWindow, windowStateRef, hideOnClose) => {113 useEffect(() => {114 const handleClose = async () => {115 if (browserWindow.isFullScreen()) {116 await new Promise((resolve) => browserWindow.once('leave-full-screen', resolve));117 browserWindow.setFullScreen(false);118 }119 fetchWindowState(browserWindow, windowStateRef.current);120 browserWindow.blur();121 if (process.platform === 'darwin' || hideOnClose) {122 browserWindow.hide();123 } else if (process.platform === 'win32') {124 browserWindow.minimize();125 } else {126 app.quit();127 }128 saveWindowState(windowStateRef.current);129 };130 browserWindow.on('close', handleClose);131 return () => {132 browserWindow.removeListener('close', handleClose);133 };134 }, [browserWindow, windowStateRef, hideOnClose]);135};136const useWindowStateLoading = (browserWindow, windowStateRef) => {137 useEffect(() => {138 const loadAndApplyWindowState = async () => {139 windowStateRef.current = await loadWindowState(browserWindow.getSize());140 applyWindowState(browserWindow, windowStateRef.current);141 };142 loadAndApplyWindowState();143 if (process.env.NODE_ENV === 'development') {144 //browserWindow.webContents.openDevTools();145 }146 }, [browserWindow, windowStateRef]);147};148const useIpcRequests = (browserWindow) => {149 useEffect(() => {150 const handleFocusRequest = () => {151 if (process.platform === 'win32') {152 if (browserWindow.isVisible()) {153 browserWindow.focus();154 } else if (browserWindow.isMinimized()) {155 browserWindow.restore();156 } else {157 browserWindow.show();158 }159 return;160 }161 if (browserWindow.isMinimized()) {162 browserWindow.restore();163 return;164 }165 browserWindow.show();166 browserWindow.focus();167 };168 remote.ipcMain.on('main-window/focus', handleFocusRequest);169 return () => {170 remote.ipcMain.removeListener('main-window/focus', handleFocusRequest);171 };172 }, [browserWindow]);173};174export function MainWindow({ browserWindow, hideOnClose = false }) {175 const windowStateRef = useRef({});176 useBeforeAppQuitEvent(browserWindow, windowStateRef);177 useWindowStateUpdates(browserWindow, windowStateRef);178 useWindowClosing(browserWindow, windowStateRef, hideOnClose);179 useWindowStateLoading(browserWindow, windowStateRef);180 useIpcRequests(browserWindow);181 return null;182}183let mainWindowElement;184export async function mountMainWindow() {185 mainWindowElement = createElement(MainWindow, { browserWindow: remote.getCurrentWindow() });186 mainWindowElement.mount(document.body);187}188export const unmountMainWindow = () => {189 mainWindowElement.unmount();190 mainWindowElement = undefined;191};192export const updateMainWindow = (newProps) => {193 mainWindowElement.update(newProps);...
paragraph.js
Source:paragraph.js
1import * as actions from '../actions/paragraph'2import keybindings from '../shortcutHandler'3export default {4 id: 'paragraphMenuEntry',5 label: 'Paragraph',6 submenu: [{7 id: 'heading1MenuItem',8 label: 'Heading 1',9 type: 'checkbox',10 accelerator: keybindings.getAccelerator('paragraphHeading1'),11 click (menuItem, browserWindow) {12 actions.paragraph(browserWindow, 'heading 1')13 }14 }, {15 id: 'heading2MenuItem',16 label: 'Heading 2',17 type: 'checkbox',18 accelerator: keybindings.getAccelerator('paragraphHeading2'),19 click (menuItem, browserWindow) {20 actions.paragraph(browserWindow, 'heading 2')21 }22 }, {23 id: 'heading3MenuItem',24 label: 'Heading 3',25 type: 'checkbox',26 accelerator: keybindings.getAccelerator('paragraphHeading3'),27 click (menuItem, browserWindow) {28 actions.paragraph(browserWindow, 'heading 3')29 }30 }, {31 id: 'heading4MenuItem',32 label: 'Heading 4',33 type: 'checkbox',34 accelerator: keybindings.getAccelerator('paragraphHeading4'),35 click (menuItem, browserWindow) {36 actions.paragraph(browserWindow, 'heading 4')37 }38 }, {39 id: 'heading5MenuItem',40 label: 'Heading 5',41 type: 'checkbox',42 accelerator: keybindings.getAccelerator('paragraphHeading5'),43 click (menuItem, browserWindow) {44 actions.paragraph(browserWindow, 'heading 5')45 }46 }, {47 id: 'heading6MenuItem',48 label: 'Heading 6',49 type: 'checkbox',50 accelerator: keybindings.getAccelerator('paragraphHeading6'),51 click (menuItem, browserWindow) {52 actions.paragraph(browserWindow, 'heading 6')53 }54 }, {55 type: 'separator'56 }, {57 id: 'upgradeHeadingMenuItem',58 label: 'Upgrade Heading',59 accelerator: keybindings.getAccelerator('paragraphUpgradeHeading'),60 click (menuItem, browserWindow) {61 actions.paragraph(browserWindow, 'upgrade heading')62 }63 }, {64 id: 'degradeHeadingMenuItem',65 label: 'Degrade Heading',66 accelerator: keybindings.getAccelerator('paragraphDegradeHeading'),67 click (menuItem, browserWindow) {68 actions.paragraph(browserWindow, 'degrade heading')69 }70 }, {71 type: 'separator'72 }, {73 id: 'tableMenuItem',74 label: 'Table',75 type: 'checkbox',76 accelerator: keybindings.getAccelerator('paragraphTable'),77 click (menuItem, browserWindow) {78 actions.paragraph(browserWindow, 'table')79 }80 }, {81 id: 'codeFencesMenuItem',82 label: 'Code Fences',83 type: 'checkbox',84 accelerator: keybindings.getAccelerator('paragraphCodeFence'),85 click (menuItem, browserWindow) {86 actions.paragraph(browserWindow, 'pre')87 }88 }, {89 id: 'quoteBlockMenuItem',90 label: 'Quote Block',91 type: 'checkbox',92 accelerator: keybindings.getAccelerator('paragraphQuoteBlock'),93 click (menuItem, browserWindow) {94 actions.paragraph(browserWindow, 'blockquote')95 }96 }, {97 id: 'mathBlockMenuItem',98 label: 'Math Block',99 type: 'checkbox',100 accelerator: keybindings.getAccelerator('paragraphMathBlock'),101 click (menuItem, browserWindow) {102 actions.paragraph(browserWindow, 'mathblock')103 }104 }, {105 id: 'htmlBlockMenuItem',106 label: 'Html Block',107 type: 'checkbox',108 accelerator: keybindings.getAccelerator('paragraphHtmlBlock'),109 click (menuItem, browserWindow) {110 actions.paragraph(browserWindow, 'html')111 }112 }, {113 type: 'separator'114 }, {115 id: 'orderListMenuItem',116 label: 'Order List',117 type: 'checkbox',118 accelerator: keybindings.getAccelerator('paragraphOrderList'),119 click (menuItem, browserWindow) {120 actions.paragraph(browserWindow, 'ol-order')121 }122 }, {123 id: 'bulletListMenuItem',124 label: 'Bullet List',125 type: 'checkbox',126 accelerator: keybindings.getAccelerator('paragraphBulletList'),127 click (menuItem, browserWindow) {128 actions.paragraph(browserWindow, 'ul-bullet')129 }130 }, {131 id: 'taskListMenuItem',132 label: 'Task List',133 type: 'checkbox',134 accelerator: keybindings.getAccelerator('paragraphTaskList'),135 click (menuItem, browserWindow) {136 actions.paragraph(browserWindow, 'ul-task')137 }138 }, {139 type: 'separator'140 }, {141 id: 'looseListItemMenuItem',142 label: 'Loose List Item',143 type: 'checkbox',144 accelerator: keybindings.getAccelerator('paragraphLooseListItem'),145 click (menuItem, browserWindow) {146 actions.paragraph(browserWindow, 'loose-list-item')147 }148 }, {149 type: 'separator'150 }, {151 id: 'paragraphMenuItem',152 label: 'Paragraph',153 type: 'checkbox',154 accelerator: keybindings.getAccelerator('paragraphParagraph'),155 click (menuItem, browserWindow) {156 actions.paragraph(browserWindow, 'paragraph')157 }158 }, {159 id: 'horizontalLineMenuItem',160 label: 'Horizontal Line',161 type: 'checkbox',162 accelerator: keybindings.getAccelerator('paragraphHorizontalLine'),163 click (menuItem, browserWindow) {164 actions.paragraph(browserWindow, 'hr')165 }166 }, {167 id: 'frontMatterMenuItem',168 label: 'YAML Front Matter',169 type: 'checkbox',170 accelerator: keybindings.getAccelerator('paragraphYAMLFrontMatter'),171 click (menuItem, browserWindow) {172 actions.paragraph(browserWindow, 'front-matter')173 }174 }]...
edit.js
Source:edit.js
1import * as actions from '../actions/edit'2import userPreference from '../preference'3import keybindings from '../shortcutHandler'4const { aidou } = userPreference.getAll()5export default {6 label: 'Edit',7 submenu: [{8 label: 'Undo',9 accelerator: keybindings.getAccelerator('editUndo'),10 click: (menuItem, browserWindow) => {11 actions.edit(browserWindow, 'undo')12 }13 }, {14 label: 'Redo',15 accelerator: keybindings.getAccelerator('editRedo'),16 click: (menuItem, browserWindow) => {17 actions.edit(browserWindow, 'redo')18 }19 }, {20 type: 'separator'21 }, {22 label: 'Cut',23 accelerator: keybindings.getAccelerator('editCut'),24 role: 'cut'25 }, {26 label: 'Copy',27 accelerator: keybindings.getAccelerator('editCopy'),28 role: 'copy'29 }, {30 label: 'Paste',31 accelerator: keybindings.getAccelerator('editPaste'),32 role: 'paste'33 }, {34 type: 'separator'35 }, {36 label: 'Copy As Markdown',37 accelerator: keybindings.getAccelerator('editCopyAsMarkdown'),38 click (menuItem, browserWindow) {39 actions.edit(browserWindow, 'copyAsMarkdown')40 }41 }, {42 label: 'Copy As HTML',43 click (menuItem, browserWindow) {44 actions.edit(browserWindow, 'copyAsHtml')45 }46 }, {47 label: 'Paste As Plain Text',48 accelerator: keybindings.getAccelerator('editCopyAsPlaintext'),49 click (menuItem, browserWindow) {50 actions.edit(browserWindow, 'pasteAsPlainText')51 }52 }, {53 type: 'separator'54 }, {55 label: 'Select All',56 accelerator: keybindings.getAccelerator('editSelectAll'),57 role: 'selectall'58 }, {59 type: 'separator'60 }, {61 label: 'Duplicate',62 accelerator: keybindings.getAccelerator('editDuplicate'),63 click (menuItem, browserWindow) {64 actions.edit(browserWindow, 'duplicate')65 }66 }, {67 label: 'Create Paragraph',68 accelerator: keybindings.getAccelerator('editCreateParagraph'),69 click (menuItem, browserWindow) {70 actions.edit(browserWindow, 'createParagraph')71 }72 }, {73 label: 'Delete Paragraph',74 accelerator: keybindings.getAccelerator('editDeleteParagraph'),75 click (menuItem, browserWindow) {76 actions.edit(browserWindow, 'deleteParagraph')77 }78 }, {79 type: 'separator'80 }, {81 label: 'Find',82 accelerator: keybindings.getAccelerator('editFind'),83 click (menuItem, browserWindow) {84 actions.edit(browserWindow, 'find')85 }86 }, {87 label: 'Find Next',88 accelerator: keybindings.getAccelerator('editFindNext'),89 click (menuItem, browserWindow) {90 actions.edit(browserWindow, 'fineNext')91 }92 }, {93 label: 'Find Previous',94 accelerator: keybindings.getAccelerator('editFindPrevious'),95 click (menuItem, browserWindow) {96 actions.edit(browserWindow, 'findPrev')97 }98 }, {99 label: 'Replace',100 accelerator: keybindings.getAccelerator('editReplace'),101 click (menuItem, browserWindow) {102 actions.edit(browserWindow, 'replace')103 }104 }, {105 type: 'separator'106 }, {107 label: 'Aidou',108 visible: aidou,109 accelerator: keybindings.getAccelerator('editAidou'),110 click (menuItem, browserWindow) {111 actions.edit(browserWindow, 'aidou')112 }113 }, {114 label: 'Insert Image',115 submenu: [{116 label: 'Absolute Path',117 click (menuItem, browserWindow) {118 actions.insertImage(browserWindow, 'absolute')119 }120 }, {121 label: 'Relative Path',122 click (menuItem, browserWindow) {123 actions.insertImage(browserWindow, 'relative')124 }125 }, {126 label: 'Upload to Cloud (EXP)',127 click (menuItem, browserWindow) {128 actions.insertImage(browserWindow, 'upload')129 }130 }]131 }, {132 type: 'separator'133 }, {134 label: 'Line Ending',135 submenu: [{136 id: 'crlfLineEndingMenuEntry',137 label: 'Carriage return and line feed (CRLF)',138 type: 'radio',139 click (menuItem, browserWindow) {140 actions.lineEnding(browserWindow, 'crlf')141 }142 }, {143 id: 'lfLineEndingMenuEntry',144 label: 'Line feed (LF)',145 type: 'radio',146 click (menuItem, browserWindow) {147 actions.lineEnding(browserWindow, 'lf')148 }149 }]150 }, {151 type: 'separator'152 }, {153 label: 'Text Direction',154 submenu: [{155 id: 'textDirectionLTRMenuEntry',156 label: 'Left To Right',157 type: 'radio',158 click (menuItem, browserWindow) {159 actions.textDirection(browserWindow, 'ltr')160 }161 }, {162 id: 'textDirectionRTLMenuEntry',163 label: 'Right To Left',164 type: 'radio',165 click (menuItem, browserWindow) {166 actions.textDirection(browserWindow, 'rtl')167 }168 }]169 }]...
file.js
Source:file.js
1import { app } from '@/../main/electron'2import * as actions from '../actions/file'3import { userSetting } from '../actions/marktext'4import { showTabBar } from '../actions/view'5import userPreference from '../preference'6import keybindings from '../shortcutHandler'7export default function (recentlyUsedFiles) {8 const { autoSave } = userPreference.getAll()9 const notOsx = process.platform !== 'darwin'10 let fileMenu = {11 label: 'File',12 submenu: [{13 label: 'New Tab',14 accelerator: keybindings.getAccelerator('fileNewFile'),15 click (menuItem, browserWindow) {16 actions.newTab(browserWindow)17 showTabBar(browserWindow)18 }19 }, {20 label: 'New Window',21 accelerator: keybindings.getAccelerator('fileNewTab'),22 click (menuItem, browserWindow) {23 actions.newFile()24 }25 }, {26 type: 'separator'27 }, {28 label: 'Open File',29 accelerator: keybindings.getAccelerator('fileOpenFile'),30 click (menuItem, browserWindow) {31 actions.openFile(browserWindow)32 }33 }, {34 label: 'Open Folder',35 accelerator: keybindings.getAccelerator('fileOpenFolder'),36 click (menuItem, browserWindow) {37 actions.openFolder(browserWindow)38 }39 }]40 }41 if (notOsx) {42 let recentlyUsedMenu = {43 label: 'Open Recent',44 submenu: []45 }46 for (const item of recentlyUsedFiles) {47 recentlyUsedMenu.submenu.push({48 label: item,49 click (menuItem, browserWindow) {50 actions.openFileOrFolder(browserWindow, menuItem.label)51 }52 })53 }54 recentlyUsedMenu.submenu.push({55 type: 'separator',56 visible: recentlyUsedFiles.length > 057 }, {58 label: 'Clear Recently Used',59 enabled: recentlyUsedFiles.length > 0,60 click (menuItem, browserWindow) {61 actions.clearRecentlyUsed()62 }63 })64 fileMenu.submenu.push(recentlyUsedMenu)65 } else {66 fileMenu.submenu.push({67 role: 'recentdocuments',68 submenu: [69 {70 role: 'clearrecentdocuments'71 }72 ]73 })74 }75 fileMenu.submenu.push({76 type: 'separator'77 }, {78 label: 'Close Tab',79 accelerator: keybindings.getAccelerator('fileCloseTab'),80 click (menuItem, browserWindow) {81 actions.closeTab(browserWindow)82 }83 }, {84 type: 'separator'85 }, {86 label: 'Save',87 accelerator: keybindings.getAccelerator('fileSave'),88 click (menuItem, browserWindow) {89 actions.save(browserWindow)90 }91 }, {92 label: 'Save As...',93 accelerator: keybindings.getAccelerator('fileSaveAs'),94 click (menuItem, browserWindow) {95 actions.saveAs(browserWindow)96 }97 }, {98 label: 'Auto Save',99 type: 'checkbox',100 checked: autoSave,101 click (menuItem, browserWindow) {102 actions.autoSave(menuItem, browserWindow)103 }104 }, {105 type: 'separator'106 }, {107 label: 'Move To...',108 click (menuItem, browserWindow) {109 actions.moveTo(browserWindow)110 }111 }, {112 label: 'Rename...',113 click (menuItem, browserWindow) {114 actions.rename(browserWindow)115 }116 }, {117 type: 'separator'118 }, {119 label: 'Import...',120 click (menuItem, browserWindow) {121 actions.importFile(browserWindow)122 }123 }, {124 label: 'Export',125 submenu: [126 {127 label: 'HTML',128 click (menuItem, browserWindow) {129 actions.exportFile(browserWindow, 'styledHtml')130 }131 }, {132 label: 'PDF',133 click (menuItem, browserWindow) {134 actions.exportFile(browserWindow, 'pdf')135 }136 }137 ]138 }, {139 type: 'separator'140 }, {141 label: 'Print',142 accelerator: keybindings.getAccelerator('filePrint'),143 click (menuItem, browserWindow) {144 actions.print(browserWindow)145 }146 }, {147 type: 'separator',148 visible: notOsx149 }, {150 label: 'Preferences',151 accelerator: keybindings.getAccelerator('filePreferences'),152 visible: notOsx,153 click (menuItem, browserWindow) {154 userSetting(menuItem, browserWindow)155 }156 }, {157 type: 'separator',158 visible: notOsx159 }, {160 label: 'Quit',161 accelerator: keybindings.getAccelerator('fileQuit'),162 visible: notOsx,163 click: app.quit164 })165 return fileMenu...
windowWatcher.js
Source:windowWatcher.js
1(function() {2 var Cu = Components.utils;3 Cu.import('resource://gre/modules/Services.jsm');4 const BROWSER_WINDOW_TYPE = 'navigator:browser';5 function _isBrowserWindow(browserWindow) {6 return BROWSER_WINDOW_TYPE === browserWindow.document.documentElement.getAttribute('windowtype');7 }8 exports.WindowWatcher = {9 registry: [],10 initialized: false,11 getContext: function(entry, win, remove) {12 for (var i=0; i<entry.contexts.length; i++) {13 if (win === entry.contexts[i].window) {14 var context = entry.contexts[i].context;15 if (remove) {16 entry.contexts.splice(i, 1);17 }18 return context;19 }20 }21 // This entry doesn't have a context yet for the specified window.22 var context = {};23 if (!remove) {24 entry.contexts.push({ window: win, context: context });25 }26 else {27 // TODO: Log failure to find context.28 }29 return context;30 },31 fire: function(isLoad, win) {32 for (var i=0; i<this.registry.length; i++) {33 var callback = isLoad ? this.registry[i].loader : this.registry[i].unloader;34 callback.call(callback, win, this.getContext(this.registry[i], win, !isLoad));35 }36 },37 unload: function() {38 Services.ww.unregisterNotification(this);39 this.forAllWindows(this.fire.bind(this, false));40 this.registry = [];41 },42 init: function() {43 Services.ww.registerNotification(this);44 this._initialized = true;45 },46 register: function(loader, unloader) {47 var entry = {48 loader: loader,49 unloader: unloader,50 contexts: []51 };52 this.registry.push(entry);53 // start listening of browser window open/close events54 if (!this._initialized) {55 this.init();56 }57 // go through open windows and call loader there58 var self = this;59 this.forAllWindows(function(browserWindow) {60 if ('complete' === browserWindow.document.readyState) {61 // Document is fully loaded so we can watch immediately.62 loader(browserWindow, self.getContext(entry, browserWindow));63 } else {64 // Wait for the window to load before watching.65 browserWindow.addEventListener('load', function() {66 browserWindow.removeEventListener('load', arguments.callee, false);67 loader(browserWindow, self.getContext(entry, browserWindow));68 });69 }70 });71 },72 forAllWindows: function(callback) {73 var browserWindows = Services.wm.getEnumerator('navigator:browser');74 while (browserWindows.hasMoreElements()) {75 var browserWindow = browserWindows.getNext();76 callback.call(this, browserWindow);77 }78 },79 isActiveBrowserWindow: function(browserWindow) {80 return browserWindow === Services.wm.getMostRecentWindow('navigator:browser');81 },82 isActiveTab: function(browserWindow, tab) {83 return browserWindow.gBrowser.selectedTab === tab;84 },85 observe: function(subject, topic, data) {86 var browserWindow = subject;87 if (topic === 'domwindowopened') {88 if ('complete' === browserWindow.document.readyState && _isBrowserWindow(browserWindow)) {89 this.fire(true, browserWindow);90 } else {91 var self = this;92 browserWindow.addEventListener('load', function() {93 browserWindow.removeEventListener('load', arguments.callee, false);94 if (_isBrowserWindow(browserWindow)) {95 self.fire(true, browserWindow);96 }97 });98 }99 }100 if (topic === 'domwindowclosed') {101 if (_isBrowserWindow(browserWindow)) {102 this.fire(false, browserWindow);103 }104 }105 }106 };...
menu-functions.js
Source:menu-functions.js
1const { remote, ipcRenderer } = require("electron");2function getCurrentWindow() {3 return remote.getCurrentWindow();4}5// function openMenu(x, y) {6// ipcRenderer.send(`display-app-menu`, { x, y });7// }8function minimizeWindow(browserWindow = getCurrentWindow()) {9 if (browserWindow.minimizable) {10 // browserWindow.isMinimizable() for old electron versions11 browserWindow.minimize();12 }13}14function maximizeWindow(browserWindow = getCurrentWindow()) {15 if (browserWindow.maximizable) {16 // browserWindow.isMaximizable() for old electron versions17 browserWindow.maximize();18 }19}20function unmaximizeWindow(browserWindow = getCurrentWindow()) {21 browserWindow.unmaximize();22}23function maxUnmaxWindow(browserWindow = getCurrentWindow()) {24 if (browserWindow.isMaximized()) {25 browserWindow.unmaximize();26 } else {27 browserWindow.maximize();28 }29}30function closeWindow(browserWindow = getCurrentWindow()) {31 browserWindow.close();32}33function isWindowMaximized(browserWindow = getCurrentWindow()) {34 return browserWindow.isMaximized();35}36module.exports = {37 getCurrentWindow,38 // openMenu,39 minimizeWindow,40 maximizeWindow,41 unmaximizeWindow,42 maxUnmaxWindow,43 isWindowMaximized,44 closeWindow...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: `example2.png` });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: `example3.png` });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: `example4.png` });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: `example5.png` });39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'google.png' });7 await browser.close();8})();9const {chromium} = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: 'google.png' });15 await browser.close();16})();17const {chromium} = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: 'google.png' });23 await browser.close();24})();25const {chromium} = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.screenshot({ path: 'google.png' });31 await browser.close();32})();33const {chromium} = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: 'google.png' });39 await browser.close();40})();41const {chromium} = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();46 await page.screenshot({ path
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const browserWindow = page._delegate._browserWindow;7 await browserWindow.setFullScreen(true);8 await browser.close();9})();
Using AI Code Generation
1const { chromium, webkit, firefox } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const browserWindow = page._delegate._browserWindow;7 browserWindow.maximize();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();11const { chromium, webkit, firefox } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 const browserWindow = page._delegate._browserWindow;17 browserWindow.maximize();18 await page.screenshot({ path: 'example.png' });19 await browser.close();20})();21const { chromium, webkit, firefox } = require('playwright');22(async () => {23 const browser = await chromium.launch();24 const context = await browser.newContext();25 const page = await context.newPage();26 const browserWindow = page._delegate._browserWindow;27 browserWindow.maximize();28 await page.screenshot({ path: 'example.png' });29 await browser.close();30})();31const { chromium, webkit, firefox } = require('playwright');32(async () => {33 const browser = await chromium.launch();34 const context = await browser.newContext();35 const page = await context.newPage();36 const browserWindow = page._delegate._browserWindow;37 browserWindow.maximize();38 await page.screenshot({ path: 'example.png' });39 await browser.close();40})();41const { chromium, webkit, firefox } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();
Using AI Code Generation
1const { browserWindow } = require('@playwright/test');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const win = await browserWindow(page);8 await win.setRect({ width: 800, height: 600 });9 await browser.close();10})();11const { test } = require('@playwright/test');12test('browser window method', async ({ page }) => {13 await page.screenshot({ path: `example.png` });14});15{16 "scripts": {17 },18 "devDependencies": {19 }20}21module.exports = {22 use: {23 },24};25test('my test', async ({ page }) => {26});27test('my test', async ({ page }) => {28 expect(await page.title()).toBe('Playwright');29});30describe('my suite', () => {31 test('my test', async ({ page }) => {32 });33});34describe('my suite', () => {35 beforeEach(async ({ page }) => {
Using AI Code Generation
1const { chromium } = require("playwright-internal");2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const browserContext = page.context();6 const browserWindow = browserContext._browserWindow;7 console.log("Browser window is visible: " + browserWindow.isVisible());8 await browser.close();9})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: 'example.png' });6 await browser.close();7})();8import { chromium } from 'playwright';9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'example.png' });13 await browser.close();14})();15import { chromium } from 'playwright';16(async () => {17 const browser = await chromium.launch();18 const page = await browser.newPage();19 await page.screenshot({ path: 'example.png' });20 await browser.close();21})();22import { chromium } from 'playwright';23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 await page.screenshot({ path: 'example.png' });27 await browser.close();28})();29import { chromium } from 'playwright';30(async () => {31 const browser = await chromium.launch();32 const page = await browser.newPage();
Using AI Code Generation
1const { browserWindow } = require('playwright-core/lib/server/browserContext');2const browser = await chromium.launch({ headless: false });3const context = await browser.newContext();4const page = await context.newPage();5const window = await browserWindow(page);6await window.setFullScreen(true);7const { BrowserWindow } = require('electron');8const win = new BrowserWindow({ webPreferences: { nodeIntegration: true } });9win.setFullScreen(true);
Using AI Code Generation
1const {browserWindow} = require('playwright-core/lib/server/browserType');2const {chromium} = require('playwright-core');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const browserContext = page.context();7 const browserWindow = await browserWindow(browserContext);8 await browserWindow.setWindowRect({x: 0, y: 0, width: 800, height: 600});9 await browser.close();10})();11const {chromium} = require('playwright-core');12(async () => {13 const browser = await chromium.launch();14 const page = await browser.newPage();15 const browserContext = page.context();16 await browserContext.setWindowRect({x: 0, y: 0, width: 800, height: 600});17 await browser.close();18})();19const {chromium} = require('playwright-core');20(async () => {21 const browser = await chromium.launch();22 const page = await browser.newPage();23 const browserContext = page.context();24 const browserWindow = await browserWindow(browserContext);25 const size = await browserWindow.getWindowRect();26 console.log(size);27 await browser.close();28})();29{ x: 0, y: 0, width: 0, height: 0 }30const {chromium} = require('playwright-core');31(async () => {32 const browser = await chromium.launch();33 const page = await browser.newPage();34 const browserContext = page.context();35 const browserWindow = await browserWindow(browserContext);36 await browserWindow.setWindowRect({x: 0, y: 0, width: 800, height: 600});37 await browser.close();38})();39const {chromium} = require('playwright-core');40(async () => {41 const browser = await chromium.launch();
Using AI Code Generation
1const {browserWindow} = require('playwright');2const {window} = require('playwright-internal');3const {chromium} = require('playwright');4const browser = await chromium.launch();5const context = await browser.newContext();6const page = await context.newPage();7const win = await page.evaluateHandle(() => window);8const browserWin = await win.evaluateHandle(() => browserWindow);9const browserWindowWin = await browserWin.evaluateHandle(() => window);10const browserWindowBrowserWin = await browserWindowWin.evaluateHandle(() => browserWindow);11const browserWindowBrowserWindowWin = await browserWindowBrowserWin.evaluateHandle(() => window);12const browserWindowBrowserWindowBrowserWin = await browserWindowBrowserWindowWin.evaluateHandle(() => browserWindow);13const browserWindowBrowserWindowBrowserWindowWin = await browserWindowBrowserWindowBrowserWin.evaluateHandle(() => window);14const browserWindowBrowserWindowBrowserWindowBrowserWin = await browserWindowBrowserWindowBrowserWindowWin.evaluateHandle(() => browserWindow);15const browserWindowBrowserWindowBrowserWindowBrowserWindowWin = await browserWindowBrowserWindowBrowserWindowBrowserWin.evaluateHandle(() => window);16const browserWindowBrowserWindowBrowserWindowBrowserWindowBrowserWin = await browserWindowBrowserWindowBrowserWindowBrowserWindowWin.evaluateHandle(() => browserWindow);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!