-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07c69cb
commit b691db3
Showing
6 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ const schema = { | |
type: 'string', | ||
default: 'arrow' | ||
}, | ||
active_monitor_id: { | ||
type: 'number', | ||
}, | ||
}; | ||
|
||
// app.getPath('userData') + '/config.json' | ||
|
@@ -52,15 +55,15 @@ let aboutWindow | |
let foregroundMode = false | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
foregroundMode = true | ||
// foregroundMode = true | ||
} | ||
|
||
let showWhiteboard = store.get('show_whiteboard') | ||
let showToolbar = store.get('show_tool_bar') | ||
|
||
const iconSrc = { | ||
DEFAULT: path.resolve('assets/web/trayIcon.png'), | ||
darwin: path.resolve('assets/web/[email protected]'), | ||
DEFAULT: path.resolve(__dirname, '../renderer/assets/trayIcon.png'), | ||
darwin: path.resolve(__dirname, '../renderer/assets/[email protected]'), | ||
} | ||
|
||
const trayIcon = iconSrc[process.platform] || iconSrc.DEFAULT | ||
|
@@ -112,6 +115,14 @@ function updateContextMenu() { | |
} | ||
}, | ||
{ type: 'separator' }, | ||
{ | ||
label: 'Reset to original', | ||
click: () => { | ||
store.clear() | ||
mainWindow.reload() | ||
} | ||
}, | ||
{ type: 'separator' }, | ||
{ | ||
label: 'About DrawPen', | ||
click: () => { | ||
|
@@ -134,8 +145,25 @@ function updateContextMenu() { | |
tray.setContextMenu(contextMenu); | ||
} | ||
|
||
function getActiveMonitor() { | ||
const activeMonitorId = store.get('active_monitor_id') | ||
|
||
screen.getAllDisplays().forEach((display) => { | ||
if (display.id === activeMonitorId) { | ||
return display | ||
} | ||
}) | ||
|
||
const primaryDisplay = screen.getPrimaryDisplay() | ||
store.set('active_monitor_id', primaryDisplay.id) | ||
|
||
return primaryDisplay | ||
} | ||
|
||
function createMainWindow () { | ||
let { width, height } = screen.getPrimaryDisplay().workAreaSize; | ||
const mainDisplay = getActiveMonitor() | ||
|
||
let { width, height } = mainDisplay.workAreaSize | ||
let isResizable = false | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
|
@@ -182,14 +210,19 @@ function createMainWindow () { | |
|
||
mainWindow.webContents.on('did-finish-load', () => { | ||
if (foregroundMode) { | ||
mainWindow.show() | ||
showWindowOnActiveScreen(); | ||
} | ||
}) | ||
} | ||
|
||
function createAboutWindow() { | ||
const currentDisplay = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()); | ||
const { x, y } = currentDisplay.workArea; | ||
|
||
aboutWindow = new BrowserWindow({ | ||
show: false, | ||
x: x, | ||
y: y, | ||
width: 250, | ||
height: 250, | ||
resizable: false, | ||
|
@@ -200,6 +233,7 @@ function createAboutWindow() { | |
preload: ABOUT_WINDOW_PRELOAD_WEBPACK_ENTRY, | ||
} | ||
}) | ||
aboutWindow.center(); | ||
|
||
aboutWindow.loadURL(ABOUT_WINDOW_WEBPACK_ENTRY) | ||
|
||
|
@@ -217,11 +251,10 @@ function createAboutWindow() { | |
aboutWindow.show() | ||
}) | ||
|
||
// Open URL in user's browser. | ||
aboutWindow.webContents.setWindowOpenHandler((details) => { | ||
shell.openExternal(details.url); | ||
|
||
return { action: "deny" }; // Prevent the app from opening the URL. | ||
return { action: "deny" }; | ||
}) | ||
} | ||
|
||
|
@@ -347,7 +380,7 @@ function toggleWindow() { | |
} | ||
|
||
function showDrawWindow() { | ||
mainWindow.show() | ||
showWindowOnActiveScreen() | ||
|
||
foregroundMode = true | ||
updateContextMenu() // Need to rerender the context menu | ||
|
@@ -382,3 +415,26 @@ function toggleWhiteboard() { | |
mainWindow.webContents.send('toggle_whiteboard') | ||
updateContextMenu() // Need to rerender the context menu | ||
} | ||
|
||
function showWindowOnActiveScreen() { | ||
const currentDisplay = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()); | ||
|
||
if (store.get('active_monitor_id') === currentDisplay.id) { | ||
mainWindow.show() | ||
return | ||
} | ||
|
||
mainWindow.setBounds(currentDisplay.workArea) | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
mainWindow.setBounds({ | ||
width: 500, | ||
height: 500 | ||
}) | ||
} | ||
|
||
store.set('active_monitor_id', currentDisplay.id) | ||
store.reset('tool_bar_x') | ||
store.reset('tool_bar_y') | ||
mainWindow.reload() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters