[key selector] Load default config and adjust timeout (#114)
This commit is contained in:
parent
6f68675b95
commit
9004bf6722
|
|
@ -225,12 +225,6 @@ ui_print "- ${LANG_CUST_INST_COPY_LIB}"
|
|||
rm -rf "/data/misc/$MISC_PATH/framework"
|
||||
mv "${MODPATH}/system/framework" "/data/misc/$MISC_PATH/framework"
|
||||
|
||||
|
||||
mkdir -p "/data/misc/$MISC_PATH/framework/lib"
|
||||
if [ "$IS64BIT" = true ]; then
|
||||
mkdir -p "/data/misc/$MISC_PATH/framework/lib64"
|
||||
fi
|
||||
|
||||
set_perm_recursive /data/misc/$MISC_PATH/framework root root 0755 0644 "u:object_r:magisk_file:s0" || abortC "! ${LANG_CUST_ERR_PERM}"
|
||||
|
||||
mkdir -p /data/misc/$MISC_PATH/cache
|
||||
|
|
|
|||
|
|
@ -11,11 +11,19 @@ public:
|
|||
virtual const std::string desc_line_1() {
|
||||
return "Select variant. Use Volume Down to move and Volume Up to confirm.";
|
||||
}
|
||||
virtual const std::string desc_line_2(uint16_t seconds) {
|
||||
virtual const std::string desc_line_2(const uint16_t seconds) {
|
||||
const char base[] = "The program will select YAHFA for you in %hu seconds if you don't \nhave a physical volume button. ";
|
||||
return u16fmt(base, seconds);
|
||||
}
|
||||
virtual const std::string timeout(const uint16_t seconds) {
|
||||
const char base[] = "No operation after %hu seconds.";
|
||||
return u16fmt(base, seconds);
|
||||
};
|
||||
protected:
|
||||
std::string u16fmt(const char* base, std::uint16_t s){
|
||||
std::string out;
|
||||
out.resize(sizeof(base) + 20);
|
||||
sprintf(out.data(), base, seconds);
|
||||
out.resize(strlen(base) + 20);
|
||||
sprintf(out.data(), base, s);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
|
@ -25,12 +33,13 @@ public:
|
|||
const std::string desc_line_1() override {
|
||||
return "请选择变种。使用音量减切换,音量加确定。";
|
||||
}
|
||||
const std::string desc_line_2(uint16_t seconds) override {
|
||||
const std::string desc_line_2(const uint16_t seconds) override {
|
||||
const char base[] = "如果您的设备没有音量键,本程序将会在 %hu 秒后自动选择 YAHFA 。";
|
||||
std::string out;
|
||||
out.resize(sizeof(base) + 20);
|
||||
sprintf(out.data(), base, seconds);
|
||||
return out;
|
||||
return u16fmt(base, seconds);
|
||||
}
|
||||
const std::string timeout(const uint16_t seconds) override {
|
||||
const char base[] = "在 %hu 秒内没有任何操作。";
|
||||
return u16fmt(base, seconds);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
|
@ -30,6 +29,7 @@
|
|||
#include <sys/poll.h>
|
||||
#include <sys/system_properties.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "Languages.h"
|
||||
#include "key_selector.h"
|
||||
|
|
@ -231,20 +231,24 @@ uint32_t get_event() {
|
|||
}
|
||||
}
|
||||
|
||||
// for phone which has no button
|
||||
uint16_t timeout = 10;
|
||||
std::unique_ptr<Languages> l = nullptr;
|
||||
|
||||
int main() {
|
||||
if (getuid() != 0) {
|
||||
std::cerr << "Root required" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// for phone which has no button
|
||||
const uint16_t timeout = 20;
|
||||
alarm(timeout);
|
||||
auto sig_handler = [](int){
|
||||
std::cout << "No operation after " << timeout << " seconds" << std::endl;
|
||||
exit(static_cast<int>(Variant::YAHFA));
|
||||
};
|
||||
signal(SIGALRM, sig_handler);
|
||||
// languages
|
||||
char locale[256];
|
||||
__system_property_get("persist.sys.locale", locale);
|
||||
if (locale[0] == 'z' && locale[1] == 'h') {
|
||||
l = std::make_unique<LanguageChinese>();
|
||||
} else {
|
||||
l = std::make_unique<Languages>();
|
||||
}
|
||||
|
||||
// get current arch
|
||||
#if defined(__arm__)
|
||||
|
|
@ -279,6 +283,46 @@ int main() {
|
|||
|
||||
Variant cursor = Variant::YAHFA;
|
||||
|
||||
// Load current variant
|
||||
std::filesystem::path lspd_folder;
|
||||
bool found = false;
|
||||
for (auto &item: std::filesystem::directory_iterator("/data/misc/")) {
|
||||
if (item.is_directory() && item.path().string().starts_with("/data/misc/lspd")) {
|
||||
lspd_folder = item;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
const auto variant_file = lspd_folder / "variant";
|
||||
if (std::filesystem::exists(variant_file)) {
|
||||
std::ifstream ifs(variant_file);
|
||||
if (ifs.good()) {
|
||||
std::string line;
|
||||
std::getline(ifs, line);
|
||||
char* end;
|
||||
int i = std::strtol(line.c_str(), &end, 10);
|
||||
switch (i) {
|
||||
default:
|
||||
case 1:
|
||||
cursor = Variant::YAHFA;
|
||||
break;
|
||||
case 2:
|
||||
cursor = Variant::SandHook;
|
||||
break;
|
||||
}
|
||||
timeout = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
alarm(timeout);
|
||||
signal(SIGALRM, [](int){
|
||||
std::cout << l->timeout(timeout) << std::endl;
|
||||
exit(static_cast<int>(Variant::YAHFA));
|
||||
});
|
||||
|
||||
auto print_status = [&cursor, variants, arch](){
|
||||
//std::cout << "\33[2K\r"; // clear this line
|
||||
std::stringstream ss;
|
||||
|
|
@ -287,7 +331,7 @@ int main() {
|
|||
continue;
|
||||
}
|
||||
ss << "[";
|
||||
ss << (cursor == i.first ? "x" : " ");
|
||||
ss << (cursor == i.first ? "√" : " ");
|
||||
ss << "] ";
|
||||
ss << i.second.expression;
|
||||
ss << " ";
|
||||
|
|
@ -295,16 +339,6 @@ int main() {
|
|||
std::cout << ss.str() << std::endl;
|
||||
};
|
||||
|
||||
// languages
|
||||
Languages* l;
|
||||
char locale[256];
|
||||
__system_property_get("persist.sys.locale", locale);
|
||||
if (locale[0] == 'z' && locale[1] == 'h') {
|
||||
l = new LanguageChinese();
|
||||
} else {
|
||||
l = new Languages();
|
||||
}
|
||||
|
||||
std::cout << l->desc_line_1() << std::endl;
|
||||
std::cout << l->desc_line_2(timeout) << std::endl;
|
||||
print_status();
|
||||
|
|
@ -328,6 +362,5 @@ int main() {
|
|||
}
|
||||
|
||||
// std::cout << std::endl << cursor << std::endl;
|
||||
delete l;
|
||||
return static_cast<int>(cursor);
|
||||
}
|
||||
Loading…
Reference in New Issue