most apps now begin in the correct directory

This commit is contained in:
Christopher Dumas 2019-05-25 16:58:22 -07:00 committed by Andreas Kling
parent e3f81bce49
commit 50154a23cb
Notes: sideshowbarker 2024-07-19 13:54:06 +09:00
7 changed files with 34 additions and 14 deletions

View File

@ -14,6 +14,7 @@
#include <LibGUI/GTreeView.h>
#include <LibGUI/GFileSystemModel.h>
#include <LibGUI/GSplitter.h>
#include <LibCore/CUserInfo.h>
#include <AK/FileSystemPath.h>
#include <unistd.h>
#include <signal.h>

View File

@ -10,6 +10,7 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <LibCore/CUserInfo.h>
static GWindow* make_launcher_window();
@ -23,6 +24,7 @@ void handle_sigchld(int)
int main(int argc, char** argv)
{
chdir(get_current_user_home_path());
GApplication app(argc, argv);
signal(SIGCHLD, handle_sigchld);

View File

@ -7,6 +7,7 @@
#include <assert.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <pwd.h>
#include "Terminal.h"
#include <Kernel/KeyCode.h>
#include <LibGUI/GApplication.h>
@ -16,6 +17,7 @@
#include <LibGUI/GAction.h>
#include <LibGUI/GFontDatabase.h>
#include <LibGUI/GSlider.h>
#include <LibCore/CUserInfo.h>
static void make_shell(int ptm_fd)
{
@ -80,6 +82,8 @@ int main(int argc, char** argv)
{
GApplication app(argc, argv);
chdir(get_current_user_home_path());
int ptm_fd = open("/dev/ptmx", O_RDWR);
if (ptm_fd < 0) {
perror("open(ptmx)");
@ -112,7 +116,7 @@ int main(int argc, char** argv)
slider->set_fill_with_background_color(true);
slider->set_background_color(Color::LightGray);
slider->on_value_changed = [&terminal] (int value) {
slider->on_value_changed = [&terminal, &config] (int value) {
float opacity = value / 100.0;
terminal.set_opacity(opacity);
};
@ -138,11 +142,11 @@ int main(int argc, char** argv)
auto font_menu = make<GMenu>("Font");
GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
font_menu->add_action(GAction::create(font_name, [&terminal] (const GAction& action) {
font_menu->add_action(GAction::create(font_name, [&terminal, &config] (const GAction& action) {
terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
terminal.config()->write_entry("Text", "Font", metadata.path);
terminal.config()->sync();
config->write_entry("Text", "Font", metadata.path);
config->sync();
terminal.force_repaint();
}));
});

View File

@ -1,5 +1,6 @@
#include <LibCore/CConfigFile.h>
#include <LibCore/CFile.h>
#include <LibCore/CUserInfo.h>
#include <AK/StringBuilder.h>
#include <stdio.h>
#include <pwd.h>
@ -7,15 +8,8 @@
Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
{
String home_path;
if (auto* home_env = getenv("HOME")) {
home_path = home_env;
} else {
uid_t uid = getuid();
if (auto* pwd = getpwuid(uid))
home_path = pwd->pw_dir;
}
if (home_path.is_empty())
String home_path = get_current_user_home_path();
if (home_path == "/")
home_path = String::format("/tmp");
auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters());
return adopt(*new CConfigFile(path));

17
LibCore/CUserInfo.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "CUserInfo.h"
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
const char *get_current_user_home_path() {
if (auto* home_env = getenv("HOME")) {
return home_env;
} else {
auto d = "/";
uid_t uid = getuid();
if (auto* pwd = getpwuid(uid))
return pwd->pw_dir;
else
return d;
}
}

1
LibCore/CUserInfo.h Normal file
View File

@ -0,0 +1 @@
const char *get_current_user_home_path();

View File

@ -19,7 +19,8 @@ OBJS = \
CConfigFile.o \
CEvent.o \
CProcessStatisticsReader.o \
CDirIterator.o
CDirIterator.o \
CUserInfo.o
LIBRARY = libcore.a
DEFINES += -DUSERLAND