Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions packages/unigraph-dev-electron/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu, Tray, nativeImage, globalShortcut, shell } = require('electron');
const { app, BrowserWindow, Menu, Tray, nativeImage, globalShortcut, shell, MenuItem } = require('electron');
const path = require('path');
const os = require('os');
const child_process = require('child_process');
Expand All @@ -14,6 +14,31 @@ const net = require('net');
const { electron } = require('process');
const { createTrayMenu } = require('./tray');

const addMenu = (mainWindow) => {
const newMenu = Menu.getApplicationMenu().items.map((it) => {
let sm;
if (it.submenu?.items?.some((subIt) => subIt.role === 'close')) {
console.log('c');

if (it.submenu?.items?.map)
sm = it.submenu.items.map((subIt) =>
subIt.role === 'close'
? {
accelerator: 'CmdOrCtrl+W',
click: () => {
mainWindow.webContents.send('closeTab');
},
label: 'Close Tab',
}
: subIt,
);
else sm = it.submenu.items;
}
return { ...it, ...(sm ? { submenu: sm } : {}) };
});
Menu.setApplicationMenu(Menu.buildFromTemplate(newMenu));
};

const store = new Store();

const userData = app.getPath('userData');
Expand Down Expand Up @@ -238,11 +263,12 @@ app.whenReady().then(() => {
trayMenu = createTrayMenu((newTemplate) => {
tray.setContextMenu(Menu.buildFromTemplate(newTemplate));
});
globalShortcut.register('Alt+Tab', () => {
if (todayWindow) {
// todayWindow.isVisible() ? todayWindow.hide() : todayWindow.show();
}
});
// globalShortcut.register('Alt+Tab', () => {
// if (todayWindow) {
// // todayWindow.isVisible() ? todayWindow.hide() : todayWindow.show();
// }
// });

globalShortcut.register('CommandOrControl+E', () => {
if (omnibar) {
omnibar.isVisible() ? closeOmnibar() : showOmnibar();
Expand Down Expand Up @@ -285,6 +311,7 @@ app.whenReady().then(() => {
}
}),
);
addMenu(mainWindow);
windows.map((el) => el.on('hide', (event) => {}));
mainWindow.webContents.on('will-navigate', function (e, url) {
e.preventDefault();
Expand All @@ -304,6 +331,10 @@ app.whenReady().then(() => {
ipcMain.on('favorites_updated', (event, args) => {
if (trayMenu) trayMenu.setFavorites(args);
});

ipcMain.on('hideWindow', () => {
mainWindow.hide();
});
// const applescript = require('applescript');

function closeOmnibar() {
Expand Down
14 changes: 14 additions & 0 deletions packages/unigraph-dev-electron/src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ window.electronPreload = () => {
ipcRenderer.on('newTabByUrl', (event, tab) => {
window.wsnavigator(tab);
});
ipcRenderer.on('closeTab', (event) => {
const currentTab = window.layoutModel.getActiveTabset().getSelectedNode().getId();
if (currentTab === 'home') {
// should close the window instead
ipcRenderer.send('hideWindow');
} else {
window.layoutModel.doAction({
type: 'FlexLayout_DeleteTab',
data: {
node: currentTab,
},
});
}
});
};

ipcRenderer.on('loading_log', (event, newLog) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function InlineSearch() {
setSearchResults(
results
.sort((a: any, b: any) => new Date(b._updatedAt || 0).getTime() - new Date(a._updatedAt || 0).getTime())
.slice(0, 100),
.slice(0, key?.length > 1 ? 100 : 10),
);
};
const search = React.useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function TagList({ data }: any) {
</div>
);
}
const getLowercaseName = (a: any) => a.get('name').as('primitive').toLowerCase();
const getLowercaseName = (a: any) => a?.get('name')?.as('primitive').toLowerCase();

export const TagListSubscription = withUnigraphSubscription(
TagList,
Expand Down