-
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
0 parents
commit 045f857
Showing
30 changed files
with
8,691 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { app, globalShortcut, Menu } from 'electron'; | ||
import serve from 'electron-serve'; | ||
import { createWindow } from './helpers'; | ||
|
||
const isProd = process.env.NODE_ENV === 'production'; | ||
let settingsWindow; | ||
|
||
if (isProd) { | ||
serve({ directory: 'app' }); // important for the build | ||
} else { | ||
app.setPath('userData', `${app.getPath('userData')} (development)`); | ||
} | ||
|
||
|
||
(async () => { | ||
await app.whenReady(); | ||
|
||
const mainWindow = createWindow('21éeé', { | ||
width: 750, | ||
height: 480, | ||
resizable: false, | ||
maximizable: false, | ||
minimizable: false, | ||
transparent: true, | ||
backgroundColor: "#00ffffff", //'#fa2E292F', | ||
frame: false | ||
}); | ||
|
||
mainWindow.on('blur', (e) => { | ||
mainWindow.hide(); | ||
}); | ||
globalShortcut.register('Option+X', () => { | ||
if (mainWindow.isVisible()) { | ||
mainWindow.hide(); | ||
} else { | ||
mainWindow.show(); | ||
} | ||
}); | ||
mainWindow.toggleDevTools(); | ||
|
||
if (isProd) { | ||
await mainWindow.loadURL('app://./hask.html'); | ||
// console.log("in production") | ||
} else { | ||
const port = process.argv[2]; | ||
await mainWindow.loadURL(`http://localhost:${port}/hask`); | ||
} | ||
})(); | ||
|
||
const isMac = process.platform === 'darwin' | ||
const template = [ | ||
{ | ||
label: 'Hask AI', | ||
submenu: [ | ||
isMac ? { role: 'quit' } : { role: 'quit' } | ||
] | ||
}, | ||
{ | ||
label: 'Edit', | ||
submenu: [ | ||
{ role: 'undo' }, | ||
{ role: 'redo' }, | ||
{ type: 'separator' }, | ||
{ role: 'cut' }, | ||
{ role: 'copy' }, | ||
{ role: 'paste' }, | ||
{ role: 'delete' }, | ||
{ type: 'separator' }, | ||
{ role: 'selectAll' } | ||
] | ||
}, | ||
{ | ||
label: 'Settings', | ||
submenu: [ | ||
{ | ||
label: 'Open Seettings', | ||
accelerator: 'CmdOrCtrl+,', | ||
click: async () => { | ||
if (!settingsWindow || settingsWindow.isDestroyed()) { | ||
settingsWindow = createWindow('2er', { | ||
width: 750, | ||
height: 480, | ||
resizable: false, | ||
maximizable: false, | ||
minimizable: false, | ||
frame: true | ||
}); | ||
|
||
if (isProd) { | ||
await settingsWindow.loadURL('app://./settings.html'); | ||
} else { | ||
const port = process.argv[2]; | ||
await settingsWindow.loadURL(`http://localhost:${port}/settings`); | ||
} | ||
} else { | ||
// If the settings window is already open, bring it to focus | ||
settingsWindow.focus(); | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
role: 'help', | ||
submenu: [ | ||
{ | ||
label: 'Learn More', | ||
click: async () => { | ||
const { shell } = require('electron') | ||
await shell.openExternal('https://github.com/bm777/hask') | ||
} | ||
} | ||
] | ||
} | ||
] | ||
|
||
const menu = Menu.buildFromTemplate(template) | ||
Menu.setApplicationMenu(menu) | ||
|
||
app.on('window-all-closed', (e) => { | ||
app.quit() | ||
e.preventDefault() | ||
}); | ||
|
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
screen, | ||
BrowserWindow, | ||
} from 'electron'; | ||
import Store from 'electron-store'; | ||
|
||
export default function createWindow(windowName, options) { | ||
const key = 'window-state'; | ||
const name = `window-state-${windowName}`; | ||
const store = new Store({ name }); | ||
const defaultSize = { | ||
width: options.width, | ||
height: options.height, | ||
}; | ||
let state = {}; | ||
let win; | ||
|
||
const restore = () => store.get(key, defaultSize); | ||
|
||
const getCurrentPosition = () => { | ||
const position = win.getPosition(); | ||
const size = win.getSize(); | ||
return { | ||
x: position[0], | ||
y: position[1], | ||
width: size[0], | ||
height: size[1], | ||
}; | ||
}; | ||
|
||
const windowWithinBounds = (windowState, bounds) => { | ||
return ( | ||
windowState.x >= bounds.x && | ||
windowState.y >= bounds.y && | ||
windowState.x + windowState.width <= bounds.x + bounds.width && | ||
windowState.y + windowState.height <= bounds.y + bounds.height | ||
); | ||
}; | ||
|
||
const resetToDefaults = () => { | ||
const bounds = screen.getPrimaryDisplay().bounds; | ||
return Object.assign({}, defaultSize, { | ||
x: (bounds.width - defaultSize.width) / 2, | ||
y: (bounds.height - defaultSize.height) / 2 | ||
}); | ||
}; | ||
|
||
const ensureVisibleOnSomeDisplay = (windowState) => { | ||
const visible = screen.getAllDisplays().some(display => { | ||
return windowWithinBounds(windowState, display.bounds) | ||
}); | ||
if (!visible) { | ||
// Window is partially or fully not visible now. | ||
// Reset it to safe defaults. | ||
return resetToDefaults(); | ||
} | ||
return windowState; | ||
}; | ||
|
||
const saveState = () => { | ||
if (!win.isMinimized() && !win.isMaximized()) { | ||
Object.assign(state, getCurrentPosition()); | ||
} | ||
store.set(key, state); | ||
}; | ||
|
||
state = ensureVisibleOnSomeDisplay(restore()); | ||
|
||
win = new BrowserWindow({ | ||
...options, | ||
...state, | ||
webPreferences: { | ||
webSecurity: false, | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
...options.webPreferences, | ||
}, | ||
}); | ||
|
||
win.on('close', saveState); | ||
|
||
return win; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import createWindow from './create-window'; | ||
|
||
export { | ||
createWindow, | ||
}; |
Oops, something went wrong.