Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bm777 committed Feb 18, 2024
0 parents commit 045f857
Show file tree
Hide file tree
Showing 30 changed files with 8,691 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/pplx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/record.mov
Binary file not shown.
Binary file added assets/token.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 124 additions & 0 deletions main/background.js
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()
});

83 changes: 83 additions & 0 deletions main/helpers/create-window.js
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;
};
5 changes: 5 additions & 0 deletions main/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import createWindow from './create-window';

export {
createWindow,
};
Loading

0 comments on commit 045f857

Please sign in to comment.