Skip to content

Commit

Permalink
Add remember option checkbox in private mode dialog (#1289)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
panda7789 and sindresorhus authored Mar 9, 2020
1 parent 5daa934 commit 9197321
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions source/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type StoreType = {
followSystemAppearance: boolean;
darkMode: boolean;
privateMode: boolean;
showPrivateModePrompt: boolean;
vibrancy: 'none' | 'sidebar' | 'full';
zoomFactor: number;
lastWindowState: {
Expand Down Expand Up @@ -53,6 +54,10 @@ const schema: {[Key in keyof StoreType]: Store.Schema} = {
type: 'boolean',
default: false
},
showPrivateModePrompt: {
type: 'boolean',
default: true
},
vibrancy: {
type: 'string',
enum: ['none', 'sidebar', 'full'],
Expand Down
25 changes: 15 additions & 10 deletions source/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,27 +432,32 @@ Press Command/Ctrl+R in Caprine to see your changes.
type: 'checkbox',
checked: config.get('privateMode'),
accelerator: 'CommandOrControl+Shift+N',
click(menuItem, _browserWindow, event) {
if (!config.get('privateMode') && event.shiftKey) {
const confirmPrivateMode = dialog.showMessageBoxSync({
async click(menuItem, _browserWindow, event) {
if (!config.get('privateMode') && config.get('showPrivateModePrompt') && event.shiftKey) {
const result = await dialog.showMessageBox(_browserWindow, {
message: 'Are you sure you want to hide names and avatars?',
detail: 'This was triggered by Command/Control+Shift+N.',
buttons: [
'Hide',
'Don\'t Hide'
],
defaultId: 0,
cancelId: 1
}) === 0;
cancelId: 1,
checkboxLabel: 'Don\'t ask me again'
});

config.set('showPrivateModePrompt', !result.checkboxChecked);

if (!confirmPrivateMode) {
if (result.response === 0) {
config.set('privateMode', !config.get('privateMode'));
sendAction('set-private-mode');
} else if (result.response === 1) {
menuItem.checked = false;
return;
}
} else {
config.set('privateMode', !config.get('privateMode'));
sendAction('set-private-mode');
}

config.set('privateMode', !config.get('privateMode'));
sendAction('set-private-mode');
}
},
{
Expand Down

0 comments on commit 9197321

Please sign in to comment.