Skip to content

Commit

Permalink
chore: Format using prettier (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
davej authored Jul 25, 2023
1 parent ef3f569 commit 7bf2d3a
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 297 deletions.
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"useTabs": true
}
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# contributors guide


## seeking contributors!

this is a FOSS effort and will never be commercialized (no tracking, will not be a paid app (but the chat apps within might), etc). please check out the feature requests (https://github.com/smol-ai/menubar/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) if you'd like to help! in particular, we'd like:

- **a PR to make the 3 panels customizable to different URLs and input targets!**
- a "Windows maintainer" to handle Windows user needs and beta test every release to make sure we didn't break something for them
- Design
- i need a new set of icons for the images
- better styling for the window? maybe normalize the bard window to the openai dimensions?
- i need a new set of icons for the images
- better styling for the window? maybe normalize the bard window to the openai dimensions?

## Install and Run from Source

Expand All @@ -36,10 +35,9 @@ To install and run from source, follow these steps:

This command will launch the application and automatically generate the appropriate desktop file or shortcut for your operating system (Linux, macOS, or Windows).


## debugging

I have the menubar devtools up all the time while in development. You can disable them by commenting this line.
I have the menubar devtools up all the time while in development. You can disable them by commenting this line.

```js
window.webContents.openDevTools();
Expand Down Expand Up @@ -75,7 +73,6 @@ the below from https://developer.apple.com/help/app-store-connect/manage-builds/
xcrun altool --validate-app -f smolmenubar.app -t macos -u shawnthe1@gmail.com
```


but doesnt work

```bash
Expand All @@ -89,4 +86,4 @@ shawnthe1@gmail.com's password:
NSLocalizedFailureReason = "App Store operation failed.";
NSLocalizedRecoverySuggestion = "Unable to determine app platform for 'Undefined' software type.";
}
```
```
258 changes: 136 additions & 122 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ const allProviders = Object.values(providers);
// Electron-store used for persistent data storage
const Store = require('electron-store');
const store = new Store();
console.log('if process.env.NODE_ENV is development, reset the store', process.env.NODE_ENV )
console.log(
'if process.env.NODE_ENV is development, reset the store',
process.env.NODE_ENV,
);
if (process.env.NODE_ENV === 'development') {
store.clear() // reset to defaults when in dev
store.clear(); // reset to defaults when in dev
}
log.info('store reset', store); // Logging the store

Expand All @@ -57,12 +60,11 @@ const contextMenu = require('electron-context-menu');

// Creating an icon image
const image = nativeImage.createFromPath(
path.join(__dirname, `images/iconTemplate.png`)
path.join(__dirname, `images/iconTemplate.png`),
);

// Once the app is ready, the following code will execute
app.on('ready', () => {

const tray = new Tray(image);

let { width } = screen.getPrimaryDisplay().workAreaSize;
Expand All @@ -89,7 +91,7 @@ app.on('ready', () => {
icon: image,
});

// On menubar ready, the following code will execute
// On menubar ready, the following code will execute
mb.on('ready', () => {
const { window } = mb;

Expand All @@ -99,31 +101,32 @@ app.on('ready', () => {
app.dock.hide();
}

// The createContextMenuTemplate function creates the context menu template
// The createContextMenuTemplate function creates the context menu template
// It contains the header, providers' toggles, links, and footer of the menu
const createContextMenuTemplate = () => {
const menuHeader = [
{
label: 'Quit',
accelerator: 'CommandorControl+Q',
click: () => {
app.quit();
},
},
{
label: 'Reload',
accelerator: 'CommandorControl+R',
click: () => {
window.reload();
},
},
{
label: 'Quick Open (use this!)',
accelerator: 'CommandorControl+Shift+G',
click: () => {
window.reload();
},
}, {
const createContextMenuTemplate = () => {
const menuHeader = [
{
label: 'Quit',
accelerator: 'CommandorControl+Q',
click: () => {
app.quit();
},
},
{
label: 'Reload',
accelerator: 'CommandorControl+R',
click: () => {
window.reload();
},
},
{
label: 'Quick Open (use this!)',
accelerator: 'CommandorControl+Shift+G',
click: () => {
window.reload();
},
},
{
label: 'Toggle Fullscreen',
accelerator: 'CommandorControl+Shift+F',
type: 'checkbox',
Expand All @@ -132,29 +135,37 @@ app.on('ready', () => {
const fullscreen = !store.get('isFullscreen', false);
store.set('isFullscreen', fullscreen);
if (fullscreen) {
window.setBounds({x: 0, width: width, height: window.getSize()[1]});
window.setBounds({
x: 0,
width: width,
height: window.getSize()[1],
});
} else {
window.setBounds({x: width - 1200, width: 1200, height: window.getSize()[1]});
window.setBounds({
x: width - 1200,
width: 1200,
height: window.getSize()[1],
});
}
},
}
];
},
];

const separator = { type: 'separator' };
const separator = { type: 'separator' };

const providersToggles = allProviders.map(provider => {
const providersToggles = allProviders.map((provider) => {
return {
label: provider.fullName,
type: 'checkbox',
checked: store.get(`${provider.webviewId}Enabled`, provider.isEnabled()),
checked: store.get(
`${provider.webviewId}Enabled`,
provider.isEnabled(),
),
click: () => {
store.set(
`${provider.webviewId}Enabled`,
!provider.isEnabled()
);
store.set(`${provider.webviewId}Enabled`, !provider.isEnabled());
setTimeout(() => {
window.reload();
}, 100)
}, 100);
},
};
});
Expand All @@ -166,94 +177,94 @@ app.on('ready', () => {
click: () => {
store.set(
'SuperPromptEnterKey',
!store.get('SuperPromptEnterKey', false)
!store.get('SuperPromptEnterKey', false),
);
window.reload();
},
};

const providerLinks = allProviders.map(provider => {
return {
label: `Visit ${provider.name} website`,
click: () => {
shell.openExternal(provider.url);
},
};
});

const menuFooter = [
// Removing the preferences window for now because all settings are now
// in the menubar context menu dropdown. (Seemed like a better UX)
// {
// label: 'Preferences',
// click: () => {
// const preferencesWindow = new BrowserWindow({
// parent: null,
// modal: false,
// alwaysOnTop: true,
// show: false,
// autoHideMenuBar: true,
// width: 500,
// height: 300,
// webPreferences: {
// nodeIntegration: true,
// contextIsolation: false,
// },
// });
// preferencesWindow.loadFile('preferences.html');
// preferencesWindow.once('ready-to-show', () => {
// mb.hideWindow();
// preferencesWindow.show();
// });

// // When the preferences window is closed, show the main window again
// preferencesWindow.on('close', () => {
// mb.showWindow();
// mb.window.reload(); // reload the main window to apply the new settings
// });
// },
// },
{
label: 'View on GitHub',
click: () => {
shell.openExternal('https://github.com/smol-ai/menubar');
},
},
{
type: 'separator',
},
{
label: 'Version ' + version,
}
]

// Return the complete context menu template
return [
...menuHeader,
separator,
...providersToggles,
separator,
superPromptEnterKey,
separator,
...providerLinks,
separator,
...menuFooter,
]
};

// Create the context menu when right-clicking the tray icon
const providerLinks = allProviders.map((provider) => {
return {
label: `Visit ${provider.name} website`,
click: () => {
shell.openExternal(provider.url);
},
};
});

const menuFooter = [
// Removing the preferences window for now because all settings are now
// in the menubar context menu dropdown. (Seemed like a better UX)
// {
// label: 'Preferences',
// click: () => {
// const preferencesWindow = new BrowserWindow({
// parent: null,
// modal: false,
// alwaysOnTop: true,
// show: false,
// autoHideMenuBar: true,
// width: 500,
// height: 300,
// webPreferences: {
// nodeIntegration: true,
// contextIsolation: false,
// },
// });
// preferencesWindow.loadFile('preferences.html');
// preferencesWindow.once('ready-to-show', () => {
// mb.hideWindow();
// preferencesWindow.show();
// });

// // When the preferences window is closed, show the main window again
// preferencesWindow.on('close', () => {
// mb.showWindow();
// mb.window.reload(); // reload the main window to apply the new settings
// });
// },
// },
{
label: 'View on GitHub',
click: () => {
shell.openExternal('https://github.com/smol-ai/menubar');
},
},
{
type: 'separator',
},
{
label: 'Version ' + version,
},
];

// Return the complete context menu template
return [
...menuHeader,
separator,
...providersToggles,
separator,
superPromptEnterKey,
separator,
...providerLinks,
separator,
...menuFooter,
];
};

// Create the context menu when right-clicking the tray icon
tray.on('right-click', () => {
const contextMenuTemplate = createContextMenuTemplate();
const contextMenuTemplate = createContextMenuTemplate();
mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate));
});

// Create the context menu when clicking the tray icon with control or meta key
tray.on('click', e => {
// Create the context menu when clicking the tray icon with control or meta key
tray.on('click', (e) => {
//check if ctrl or meta key is pressed while clicking
if (e.ctrlKey || e.metaKey) {
const contextMenuTemplate = createContextMenuTemplate();
mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate));
}
const contextMenuTemplate = createContextMenuTemplate();
mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate));
}
});
const menu = new Menu();

Expand All @@ -267,7 +278,6 @@ app.on('ready', () => {
}
mb.app.focus();
}

});

// Fullscreen menu shortcut
Expand All @@ -276,9 +286,13 @@ app.on('ready', () => {
store.set('isFullscreen', fullscreen);
const { window } = mb;
if (fullscreen) {
window.setBounds({x: 0, width: width, height: window.getSize()[1]});
window.setBounds({ x: 0, width: width, height: window.getSize()[1] });
} else {
window.setBounds({x: width - 1200, width: 1200, height: window.getSize()[1]});
window.setBounds({
x: width - 1200,
width: 1200,
height: window.getSize()[1],
});
}
});

Expand Down Expand Up @@ -366,7 +380,7 @@ app.on('ready', () => {
// prevent background flickering
app.commandLine.appendSwitch(
'disable-backgrounding-occluded-windows',
'true'
'true',
);
});

Expand Down
Loading

0 comments on commit 7bf2d3a

Please sign in to comment.