Skip to content

Commit

Permalink
Merge pull request #899 from jijojosephk/issue-867
Browse files Browse the repository at this point in the history
  • Loading branch information
jijojosephk authored Jul 19, 2023
2 parents da21903 + 32b2b69 commit 281877f
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 27 deletions.
49 changes: 49 additions & 0 deletions app/appConfiguration/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const Store = require('electron-store');

let _AppConfiguration_configPath = new WeakMap();
let _AppConfiguration_startupConfig = new WeakMap();
let _AppConfiguration_legacyConfigStore = new WeakMap();
let _AppConfiguration_settingsStore = new WeakMap();

class AppConfiguration {
/**
* @param {string} configPath
*/
constructor(configPath) {
_AppConfiguration_configPath.set(this, configPath);
_AppConfiguration_startupConfig.set(this, require('../config')(configPath));
_AppConfiguration_legacyConfigStore.set(this, new Store({
name: 'config'
}));
_AppConfiguration_settingsStore.set(this, new Store({
name: 'settings'
}));
}

/**
* @returns {string}
*/
get configPath() {
return _AppConfiguration_configPath.get(this);
}

get startupConfig() {
return _AppConfiguration_startupConfig.get(this);
}

/**
* @returns {Store}
*/
get legacyConfigStore() {
return _AppConfiguration_legacyConfigStore.get(this);
}

/**
* @returns {Store}
*/
get settingsStore() {
return _AppConfiguration_settingsStore.get(this);
}
}

module.exports = { AppConfiguration };
16 changes: 8 additions & 8 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const isMac = os.platform() === 'darwin';
if (app.commandLine.hasSwitch('customUserDir')) {
app.setPath('userData', app.commandLine.getSwitchValue('customUserDir'));
}
const config = require('./config')(app.getPath('userData'));

const { AppConfiguration } = require('./appConfiguration');
const appConfig = new AppConfiguration(app.getPath('userData'));

const config = appConfig.startupConfig;
config.appPath = path.join(__dirname, isDev ? '' : '../../');

const logger = new LucidLog({
Expand Down Expand Up @@ -41,10 +45,6 @@ try {
logger.info('No audio players found. Audio notifications might not work.');
}

const Store = require('electron-store');
const store = new Store({
name: 'settings'
});
const certificateModule = require('./certificate');
const gotTheLock = app.requestSingleInstanceLock();
const mainAppWindow = require('./mainAppWindow');
Expand Down Expand Up @@ -144,7 +144,7 @@ function handleAppReady() {
process.on('SIGTERM', onAppTerminated);
//Just catch the error
process.stdout.on('error', () => { });
mainAppWindow.onAppReady(config);
mainAppWindow.onAppReady(appConfig);
}

async function handleGetConfig() {
Expand Down Expand Up @@ -183,7 +183,7 @@ async function handleGetCustomBGList() {
}

function getPartitions() {
return store.get('app.partitions') || [];
return appConfig.settingsStore.get('app.partitions') || [];
}

function getPartition(name) {
Expand All @@ -204,7 +204,7 @@ function savePartition(arg) {
} else {
partitions.push(arg);
}
store.set('app.partitions', partitions);
appConfig.settingsStore.set('app.partitions', partitions);
}

function handleCertificateError() {
Expand Down
22 changes: 19 additions & 3 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const { SpellCheckProvider } = require('../spellCheckProvider');
const helpers = require('../helpers');
const exec = require('child_process').exec;
const TrayIconChooser = require('../browser/tools/trayIconChooser');
// eslint-disable-next-line no-unused-vars
const { AppConfiguration } = require('../appConfiguration');

/**
* @type {TrayIconChooser}
Expand Down Expand Up @@ -43,16 +45,26 @@ let config;
*/
let window = null;

/**
* @type {AppConfiguration}
*/
let appConfig = null;

/**
* @param {AppConfiguration} mainConfig
*/
exports.onAppReady = async function onAppReady(mainConfig) {
config = mainConfig;
iconChooser = new TrayIconChooser(mainConfig);
appConfig = mainConfig;
config = mainConfig.startupConfig;
iconChooser = new TrayIconChooser(mainConfig.startupConfig);
logger = new LucidLog({
levels: config.appLogLevels.split(',')
});

window = await createWindow();

new Menus(window, config, iconChooser.getFile());
const m = new Menus(window, config, iconChooser.getFile());
m.onSpellCheckerLanguageChanged = onSpellCheckerLanguageChanged;

addEventHandlers();

Expand All @@ -62,6 +74,10 @@ exports.onAppReady = async function onAppReady(mainConfig) {
applyAppConfiguration(config, window);
};

function onSpellCheckerLanguageChanged(languages) {
appConfig.legacyConfigStore.set('spellCheckerLanguages', languages);
}

let allowFurtherRequests = true;

exports.onAppSecondInstance = function onAppSecondInstance(event, args) {
Expand Down
70 changes: 61 additions & 9 deletions app/menus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { LucidLog } = require('lucid-log');
const { SpellCheckProvider } = require('../spellCheckProvider');
const checkConnectivity = require('./connectivity');

let _Menus_onSpellCheckerLanguageChanged = new WeakMap();
class Menus {
constructor(window, config, iconPath) {
/**
Expand All @@ -24,6 +25,22 @@ class Menus {
this.initialize();
}

/**
* @type {(languages:Array<string>)=>void}
*/
get onSpellCheckerLanguageChanged() {
return _Menus_onSpellCheckerLanguageChanged.get(this);
}

/**
* @type {(languages:Array<string>)=>void}
*/
set onSpellCheckerLanguageChanged(value) {
if (typeof value === 'function') {
_Menus_onSpellCheckerLanguageChanged.set(this, value);
}
}

async quit(clearStorage = false) {
this.allowQuit = true;

Expand Down Expand Up @@ -279,14 +296,42 @@ function addSpellCheckMenuItems(menu, menus) {
function createSpellCheckLanguagesMenu(menus) {
const activeLanguages = menus.window.webContents.session.getSpellCheckerLanguages();
const splChkMenu = new Menu();
for (const language of menus.spellCheckProvider.supportedList) {
splChkMenu.append(
createLanguageMenuItem(language, activeLanguages, menus)
);
for (const group of menus.spellCheckProvider.supportedListByGroup) {
const subMenu = new Menu();
splChkMenu.append(new MenuItem({
label: group.key,
submenu: subMenu
}));
for (const language of group.list) {
subMenu.append(
createLanguageMenuItem(language, activeLanguages, menus)
);
}
}

createSpellCheckLanguagesNoneMenuEntry(splChkMenu, menus);

return splChkMenu;
}

/**
* @param {Electron.Menu} menu
* @param {Menus} menus
*/
function createSpellCheckLanguagesNoneMenuEntry(menu, menus) {
menu.append(
new MenuItem({
type: 'separator'
})
);
menu.append(
new MenuItem({
label: 'None',
click: () => chooseLanguage(null, menus)
})
);
}

/**
* @param {{language:string,code:string}} language
* @param {Array<string>} activeLanguages
Expand All @@ -309,12 +354,19 @@ function createLanguageMenuItem(language, activeLanguages, menus) {
*/
function chooseLanguage(item, menus) {
const activeLanguages = menus.window.webContents.session.getSpellCheckerLanguages();
if (item.checked) {
addToList(activeLanguages, item.id);
} else {
removeFromList(activeLanguages, item.id);
if (item) {
if (item.checked) {
addToList(activeLanguages, item.id);
} else {
removeFromList(activeLanguages, item.id);
}
}

const changes = menus.spellCheckProvider.setLanguages(item ? activeLanguages : []);

if (menus.onSpellCheckerLanguageChanged) {
menus.onSpellCheckerLanguageChanged.apply(menus, [changes]);
}
menus.spellCheckProvider.setLanguages(activeLanguages);
}

/**
Expand Down
56 changes: 50 additions & 6 deletions app/spellCheckProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class SpellCheckProvider {
return _SpellCheckProvider_supportedList.get(this);
}

/**
* @type {Array<{key:string,list:{language:string,code:string}}>}
*/
get supportedListByGroup() {
var groupedList = [];
for (const language of this.supportedList) {
var key = language.language.substring(0, 1);
addLanguageToGroup(groupedList, key, language);
}
return groupedList;
}

/**
* @type {Electron.BrowserWindow}
*/
Expand Down Expand Up @@ -59,14 +71,12 @@ class SpellCheckProvider {
this.window.webContents.session.setSpellCheckerLanguages(setlanguages);
if (setlanguages.length > 0) {
this.logger.debug(`Language codes ${setlanguages.join(',')} set for spellchecker`);
} else {
this.logger.debug('Spellchecker is disabled!');
}

return setlanguages;
}

setSystemLanguages() {
//this.window.webContents.spl
}
}


Expand All @@ -76,9 +86,11 @@ class SpellCheckProvider {
*/
function init(intance, window) {
const listFromElectron = window.webContents.session.availableSpellCheckerLanguages;
_SpellCheckProvider_supportedList.set(intance, codes.filter(lf => {
var list = codes.filter(lf => {
return listContains(listFromElectron, lf.code);
}));
});
sortLanguages(list);
_SpellCheckProvider_supportedList.set(intance, list);
}

/**
Expand All @@ -92,4 +104,36 @@ function listContains(list, text) {
});
}

/**
* @param {Array<{key:string,list:{language:string,code:string}}>} groupedList
* @param {string} key
* @param {{language:string,code:string}} language
*/
function addLanguageToGroup(groupedList, key, language) {
const group = groupedList.filter(f => f.key === key)[0];
if (group) {
group.list.push(language);
} else {
groupedList.push({
key: key,
list: [language]
});
}
}

/**
* @param {Array<{language:string,code:string}} languages
*/
function sortLanguages(languages) {
languages.sort((a, b) => {
return stringCompare(a.language.toLocaleLowerCase(), b.language.toLocaleLowerCase());
});
}

function stringCompare(str1, str2) {
const le = str1 < str2;
const gr = str1 > str2;
return le ? -1 : gr ? 1 : 0;
}

module.exports = { SpellCheckProvider };
7 changes: 7 additions & 0 deletions com.github.IsmaelMartinez.teams_for_linux.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<url type="bugtracker">https://github.com/IsmaelMartinez/teams-for-linux/issues</url>
<launchable type="desktop-id">com.github.IsmaelMartinez.teams_for_linux.desktop</launchable>
<releases>
<release version="1.2.7" date="2023-07-19">
<description>
<ul>
<li>New: Spellchecker language selections are persisted between runs</li>
</ul>
</description>
</release>
<release version="1.2.5" date="2023-07-11">
<description>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.2.6",
"version": "1.2.7",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down

0 comments on commit 281877f

Please sign in to comment.