Skip to content

Commit

Permalink
Setting to control update checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomilist committed Jul 29, 2022
1 parent d4dad3d commit 5aac03a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 26 deletions.
1 change: 1 addition & 0 deletions config/settings.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
check enabled
d .
m keys
i mathcad
Expand Down
4 changes: 2 additions & 2 deletions include/Definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace mcon
#define STR(s) s
#endif

#define MCON_VERSION "1.5.3"
#define MCON_VERSION_WRAPPED STR( "1.5.3" )
#define MCON_VERSION "1.5.4"
#define MCON_VERSION_WRAPPED STR( "1.5.4" )
}

#endif // __DEFINITIONS_H__
44 changes: 34 additions & 10 deletions include/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace mcon
lexer(std::move(character_stream), character_set)
{
character_set->LoadFromFolder("./resources/character-sets");
STRING_OUTPUT
<< STR("For usage information, enter \"help\" (without quote marks) or read the associated user guide.")
<< std::endl;
LoadSettings();
}

Expand Down Expand Up @@ -109,6 +106,16 @@ namespace mcon
Download();
break;
}
case Setting::CheckUpdate:
{
check_update.first = check_update_settings.at(current_token.content);
check_update.second = a_console_input;
if (a_user_triggered)
{
STRING_OUTPUT << STR("\nUpdate checking behavior updated.\n") << std::endl;
}
break;
}
case Setting::DecimalSeparator:
{
decimal_separator.first = decimal_separator_settings.at(current_token.content);
Expand Down Expand Up @@ -198,19 +205,22 @@ namespace mcon
<< STR("\n")
<< STR("2. Show current settings s show settings [no arguments] s\n")
<< STR("\n")
<< STR("3. Show user guide g guide userguide [no arguments] g\n")
<< STR("3. Open user guide g guide userguide [no arguments] g\n")
<< STR("\n")
<< STR("4. Open download page download [no arguments] download\n")
<< STR("\n")
<< STR("5. Set decimal separator d dec ds sep period . d ,\n")
<< STR("5. Set update checking check enabled true check false\n")
<< STR(" disabled false\n")
<< STR("\n")
<< STR("6. Set decimal separator d dec ds sep period . d ,\n")
<< STR(" comma ,\n")
<< STR("\n")
<< STR("6. Set output mode m mode keys keystrokes m clip\n")
<< STR("7. Set output mode m mode keys keystrokes m clip\n")
<< STR(" clip clipboard\n")
<< STR("\n")
<< STR("7. Set input format i in input Mathcad mathcad i mathcad\n")
<< STR("8. Set input format i in input Mathcad mathcad i mathcad\n")
<< STR("\n")
<< STR("8. Set output format o out output Mathcad mathcad o latex\n")
<< STR("9. Set output format o out output Mathcad mathcad o latex\n")
<< STR(" LaTeX Latex latex\n")
<< STR(" MathML mathml\n")
<< STR(" UnicodeMath unicodemath Unicode unicode\n")
Expand All @@ -222,13 +232,15 @@ namespace mcon

void Settings::ShowSettings()
{
String current_update_checking;
String current_decimal_separator;
String current_input_language;
String current_output_language;
String current_output_mode;

try
{
current_update_checking = check_update_names.at(check_update.first);
current_decimal_separator = decimal_separator_names.at(decimal_separator.first);
current_output_mode = output_mode_names.at(output_mode.first);
current_input_language = input_language_names.at(input_language.first);
Expand All @@ -246,16 +258,19 @@ namespace mcon
<< STR("\n")
<< STR("Displaying current settings\n")
<< STR("----------------------------------------------------------------------------------------------------\n")
<< STR("Update checking: ")
<< current_update_checking
<< STR("\n")
<< STR("Decimal separator: ")
<< current_decimal_separator
<< STR("\n")
<< STR("Output mode: ")
<< current_output_mode
<< STR("\n")
<< STR("Input language: ")
<< STR("Input format: ")
<< current_input_language
<< STR("\n")
<< STR("Output language: ")
<< STR("Output format: ")
<< current_output_language
<< STR("\n")
<< std::endl;
Expand All @@ -278,6 +293,7 @@ namespace mcon
void Settings::SaveSettings()
{
String commands =
check_update.second + STR("\n") +
decimal_separator.second + STR("\n") +
output_mode.second + STR("\n") +
input_language.second + STR("\n") +
Expand All @@ -289,6 +305,14 @@ namespace mcon
return;
}

void Settings::PrintTip()
{
STRING_OUTPUT
<< STR("For usage information, enter \"help\" (without quote marks) or read the associated user guide.")
<< std::endl;
return;
}

void Settings::Download()
{
STRING_OUTPUT << STR("\nOpening download page in browser...\n") << std::endl;
Expand Down
24 changes: 24 additions & 0 deletions include/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ namespace mcon
ShowSettings,
ShowGuide,
Download,
CheckUpdate,
DecimalSeparator,
InputLanguage,
OutputLanguage,
OutputMode
};

enum class UpdateChecking
{
Enabled,
Disabled
};

enum class DecimalSeparator
{
Period,
Expand Down Expand Up @@ -78,7 +85,9 @@ namespace mcon
void ShowSettings();
void LoadSettings();
void SaveSettings();
void PrintTip();

std::pair<UpdateChecking, String> check_update = {UpdateChecking::Enabled, STR("check enabled")};
std::pair<DecimalSeparator, String> decimal_separator = {DecimalSeparator::Period, STR("decimal period")};
std::pair<OutputMode, String> output_mode = {OutputMode::Keystrokes, STR("mode keystrokes")};
std::pair<InputLanguage, String> input_language = {InputLanguage::Mathcad, STR("input mathcad")};
Expand All @@ -100,6 +109,7 @@ namespace mcon
{STR("help"), Setting::Help},
{STR("?"), Setting::Help},
{STR("download"), Setting::Download},
{STR("check"), Setting::CheckUpdate},
{STR("s"), Setting::ShowSettings},
{STR("show"), Setting::ShowSettings},
{STR("settings"), Setting::ShowSettings},
Expand All @@ -120,6 +130,20 @@ namespace mcon
{STR("m"), Setting::OutputMode},
};

const std::unordered_map<UpdateChecking, String> check_update_names =
{
{UpdateChecking::Enabled, STR("Enabled")},
{UpdateChecking::Disabled, STR("Disabled")},
};

const std::unordered_map<String, UpdateChecking> check_update_settings =
{
{STR("enabled"), UpdateChecking::Enabled},
{STR("true"), UpdateChecking::Enabled},
{STR("disabled"), UpdateChecking::Disabled},
{STR("false"), UpdateChecking::Disabled},
};

const std::unordered_map<DecimalSeparator, String> decimal_separator_names =
{
{DecimalSeparator::Period, STR("Period (.)")},
Expand Down
33 changes: 23 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,37 @@ int main()
std::wcout.imbue(utf8);
#endif

// Version output and check
// Version output
STRING_OUTPUT << STR("math-converter-") << MCON_VERSION_WRAPPED << std::endl;

try
// Settings initialisation
auto settings_mutex = std::make_shared<std::mutex>();
auto settings = std::make_shared<mcon::Settings>();

// Check for new releases
if (settings->check_update.first == mcon::UpdateChecking::Enabled)
{
auto version = mcon::Version(MCON_VERSION);
version.Check();
try
{
auto version = mcon::Version(MCON_VERSION);
version.Check();
}
catch(const std::exception& e)
{
ERROR_OUTPUT
<< STR("An error occured while checking for new releases.\n")
<< std::endl;
}
}
catch(const std::exception& e)
else
{
ERROR_OUTPUT
<< "An error occured while checking for an updated version.\n"
STRING_OUTPUT
<< STR("Currently not checking for new releases upon launch.\n")
<< std::endl;
}

// Settings initialisation
auto settings_mutex = std::make_shared<std::mutex>();
auto settings = std::make_shared<mcon::Settings>();
// Print usage tip
settings->PrintTip();

// hotkey_thread to catch hotkey triggers and convert math expressions
// config_thread to handle input from the console
Expand Down
27 changes: 23 additions & 4 deletions userguide.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# User guide for math-converter-1.5.3
# User guide for math-converter-1.5.4

## Supported platforms

Expand Down Expand Up @@ -62,22 +62,33 @@ While not all math syntax is supported, a variety of commonly-used features are

The supported input character set can be extended with additional, user-made `.json` files under `/resources/character-sets/`, which are loaded at program launch. Characters not in the character sets will be discarded. Additionally, configuration can be achieved at runtime via the terminal window the program runs in. Settings are saved to `/config/settings.conf`. The currently supported configuration commands include:

- Display help
- Show help
- Show current settings
- Open user guide
- Open download page
- Set update checking behavior
- Set decimal separator
- Set output mode
- Set input format
- Set output format

### Display help
### Show help

This command displays help about the configuration commands.

Command aliases: `h help ?`<br>
Available arguments: none<br>
Example: `h`

### Show user guide
### Show current settings

This command displays the current settings for decimal separator, output mode, input format and output format.

Command aliases: `s show settings`<br>
Available arguments: none<br>
Example: `s`

### Open user guide

This command opens the user guide on math-converter's Github.

Expand All @@ -93,6 +104,14 @@ Command aliases: `download`<br>
Available arguments: none<br>
Example: `download`

### Set update checking behavior

This command controls whether or not math-converter checks for new releases upon launch.

Command aliases: `check`<br>
Available arguments: `enabled true disabled false`<br>
Example: `check false`

### Set decimal separator

This command sets the decimal separator to either a period or a comma. The default is a period.
Expand Down

0 comments on commit 5aac03a

Please sign in to comment.