Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Added support for opening in browser. (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
haryp2309 committed Nov 18, 2020
1 parent 0c047e9 commit dbd4336
Showing 1 changed file with 114 additions and 9 deletions.
123 changes: 114 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, Menu, MenuItem } = require('electron')
const path = require('path')
const isMac = process.platform === 'darwin'
const shell = require('electron').shell

function createWindow() {
createSpecificWindow('https:///gitpod.idi.ntnu.no')
Expand All @@ -18,20 +20,123 @@ function createSpecificWindow(urlToLoad) {
}
})

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

const template = [
// { role: 'appMenu' }
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}] : []),
// { role: 'fileMenu' }
{
label: 'File',
submenu: [
isMac ? { role: 'close' } : { role: 'quit' }
]
},
// { role: 'editMenu' }
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac ? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
] : [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
// { role: 'viewMenu' }
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
// { role: 'windowMenu' }
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
{
label: 'Open in system browser',
click() {
shell.openExternal(urlToLoad)
}
},
...(isMac ? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
] : [
{ role: 'close' }
])
]
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://electronjs.org')
}
}
]
}
]

const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

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


mainWindow.on('resize', (event) =>{
mainWindow.on('resize', (event) => {
updateCSS(mainWindow)
});

mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.on('did-finish-load', () => {
updateCSS(mainWindow)
})
})
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault()
createSpecificWindow(url)
Expand All @@ -47,11 +152,11 @@ function createSpecificWindow(urlToLoad) {

function updateCSS(window) {
var zoomFactor = window.webContents.getZoomFactor()
var theiaPadding = 60/zoomFactor
var theiaPadding = 60 / zoomFactor
if (window.isFullScreen()) {
window.webContents.insertCSS('#theia-top-panel { padding-left: 0px; -webkit-app-region: drag; } header { -webkit-app-region: drag; }')
} else {
window.webContents.insertCSS('#theia-top-panel { padding-left: '+theiaPadding+'px; -webkit-app-region: drag; } header { -webkit-app-region: drag; }')
window.webContents.insertCSS('#theia-top-panel { padding-left: ' + theiaPadding + 'px; -webkit-app-region: drag; } header { -webkit-app-region: drag; }')
}
}

Expand Down

0 comments on commit dbd4336

Please sign in to comment.