Skip to content

Commit

Permalink
Impprovements and bug fixes
Browse files Browse the repository at this point in the history
* Bug fix: broken customCSS
* Improvement: set deafult spellcheck lang
* Improvement: ensure spellchecker is set every session
* Bug fix: json.parse() cannot parse empty array string when all the langs are deselected
  • Loading branch information
manavmehta committed Jun 17, 2020
1 parent 647034b commit 462db7a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ app.on('ready', () => {
const ses = session.fromPartition('persist:webviewsession');
ses.setUserAgent(`ZulipElectron/${app.getVersion()} ${ses.getUserAgent()}`);
ipcMain.on('set-spellcheck-langs', () => {
ses.setSpellCheckerLanguages(ConfigUtil.getConfigItem('spellcheck-languages'));
ses.setSpellCheckerLanguages(ConfigUtil.getConfigItem('spellcheckerLanguages'));
});
AppMenu.setMenu({
tabs: []
Expand Down
10 changes: 5 additions & 5 deletions app/renderer/js/components/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ export default class WebView extends BaseComponent {
}

registerListeners(): void {
const webContents = this.$el.getWebContents();
webContents.addListener('context-menu', (event, menuParameters) => {
contextMenu(webContents, event, menuParameters);
});

this.$el.addEventListener('new-window', event => {
handleExternalLink.call(this, event);
});
Expand Down Expand Up @@ -127,6 +122,11 @@ export default class WebView extends BaseComponent {
});

this.$el.addEventListener('dom-ready', () => {
const webContents = remote.webContents.fromId(this.$el.getWebContentsId());
webContents.addListener('context-menu', (event, menuParameters) => {
contextMenu(webContents, event, menuParameters);
});

if (this.props.role === 'server') {
this.$el.classList.add('onload');
}
Expand Down
5 changes: 4 additions & 1 deletion app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface SettingsOptions extends DNDSettings {
quitOnClose: boolean;
promptDownload: boolean;
dockBouncing?: boolean;
spellcheckerLanguages: string[];
}

const logger = new Logger({
Expand Down Expand Up @@ -137,6 +138,7 @@ class ServerManagerView {
await this.initTabs();
this.initActions();
this.registerIpcs();
ipcRenderer.send('set-spellcheck-langs');
}

async loadProxy(): Promise<void> {
Expand Down Expand Up @@ -196,7 +198,8 @@ class ServerManagerView {
},
downloadsPath: `${app.getPath('downloads')}`,
quitOnClose: false,
promptDownload: false
promptDownload: false,
spellcheckerLanguages: ['en-US']
};

// Platform specific settings
Expand Down
15 changes: 11 additions & 4 deletions app/renderer/js/pages/preference/general-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export default class GeneralSection extends BaseSection {
const newValue = !ConfigUtil.getConfigItem('enableSpellchecker');
ConfigUtil.setConfigItem('enableSpellchecker', newValue);
this.enableSpellchecker();
// TODO: change display attribute of the #spellcheck-langs div
}
});
}
Expand Down Expand Up @@ -503,6 +504,7 @@ export default class GeneralSection extends BaseSection {
initSpellChecker(): void {
// The elctron API is a no-op on macOS and macOS default spellchecker is used.
if (process.platform === 'darwin') {
// TODO: change display attribute of the #spellcheck-langs div to none on macOS
const note = document.querySelector('#note');
note.append(t.__('On macOS, the OS spellchecker is used.'));
note.append(document.createElement('br'));
Expand Down Expand Up @@ -551,13 +553,18 @@ export default class GeneralSection extends BaseSection {
}
});

const configuredLanguages: string[] = ConfigUtil.getConfigItem('spellcheck-languages').map((code: string) => [...languagePairs].filter(pair => (pair[1] === code))[0][0]);
const configuredLanguages: string[] = ConfigUtil.getConfigItem('spellcheckerLanguages').map((code: string) => [...languagePairs].filter(pair => (pair[1] === code))[0][0]);
tagify.addTags(configuredLanguages);

tagField.addEventListener('change', event => {
const spellLangs: string[] = [...JSON.parse((event.target as HTMLInputElement).value).values()].map(elt => languagePairs.get(elt.value));
ConfigUtil.setConfigItem('spellcheck-languages', spellLangs);
ipcRenderer.send('set-spellcheck-langs');
if ((event.target as HTMLInputElement).value.length === 0) {
ConfigUtil.setConfigItem('spellcheckerLanguages', []);
ipcRenderer.send('set-spellcheck-langs');
} else {
const spellLangs: string[] = [...JSON.parse((event.target as HTMLInputElement).value).values()].map(elt => languagePairs.get(elt.value));
ConfigUtil.setConfigItem('spellcheckerLanguages', spellLangs);
ipcRenderer.send('set-spellcheck-langs');
}
});
}
}
Expand Down

0 comments on commit 462db7a

Please sign in to comment.