feat: app.getPath('recent') (#23381)
* feat: getPath("recent") * test: Add a spec and docs * fix: Integrate feedback * fix: Handle path change * chore: Cut SetRecentPath
This commit is contained in:
parent
c7b2eb68cf
commit
dcbed18f44
6 changed files with 57 additions and 0 deletions
|
@ -608,6 +608,7 @@ Returns `String` - The current application directory.
|
||||||
* `music` Directory for a user's music.
|
* `music` Directory for a user's music.
|
||||||
* `pictures` Directory for a user's pictures.
|
* `pictures` Directory for a user's pictures.
|
||||||
* `videos` Directory for a user's videos.
|
* `videos` Directory for a user's videos.
|
||||||
|
* `recent` Directory for the user's recent files (Windows only).
|
||||||
* `logs` Directory for your app's log folder.
|
* `logs` Directory for your app's log folder.
|
||||||
* `pepperFlashSystemPlugin` Full path to the system version of the Pepper Flash plugin.
|
* `pepperFlashSystemPlugin` Full path to the system version of the Pepper Flash plugin.
|
||||||
* `crashDumps` Directory where crash dumps are stored.
|
* `crashDumps` Directory where crash dumps are stored.
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include "shell/common/gin_helper/object_template_builder.h"
|
#include "shell/common/gin_helper/object_template_builder.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
#include "shell/common/platform_util.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -425,6 +426,10 @@ int GetPathConstant(const std::string& name) {
|
||||||
return chrome::DIR_USER_PICTURES;
|
return chrome::DIR_USER_PICTURES;
|
||||||
else if (name == "videos")
|
else if (name == "videos")
|
||||||
return chrome::DIR_USER_VIDEOS;
|
return chrome::DIR_USER_VIDEOS;
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
else if (name == "recent")
|
||||||
|
return electron::DIR_RECENT;
|
||||||
|
#endif
|
||||||
else if (name == "pepperFlashSystemPlugin")
|
else if (name == "pepperFlashSystemPlugin")
|
||||||
return chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN;
|
return chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN;
|
||||||
else
|
else
|
||||||
|
@ -885,6 +890,15 @@ base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
|
||||||
SetAppLogsPath(thrower, base::Optional<base::FilePath>());
|
SetAppLogsPath(thrower, base::Optional<base::FilePath>());
|
||||||
succeed = base::PathService::Get(key, &path);
|
succeed = base::PathService::Get(key, &path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
// If we get the "recent" path before setting it, set it
|
||||||
|
if (!succeed && name == "recent" &&
|
||||||
|
platform_util::GetFolderPath(DIR_RECENT, &path)) {
|
||||||
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
succeed = base::PathService::Override(DIR_RECENT, path);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!succeed)
|
if (!succeed)
|
||||||
|
|
|
@ -26,6 +26,10 @@ enum {
|
||||||
DIR_USER_CACHE, // Directory where user cache can be written.
|
DIR_USER_CACHE, // Directory where user cache can be written.
|
||||||
DIR_APP_LOGS, // Directory where app logs live
|
DIR_APP_LOGS, // Directory where app logs live
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
DIR_RECENT, // Directory where recent files live
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
DIR_APP_DATA, // Application Data directory under the user profile.
|
DIR_APP_DATA, // Application Data directory under the user profile.
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -45,6 +45,11 @@ bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail);
|
||||||
|
|
||||||
void Beep();
|
void Beep();
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
// SHGetFolderPath calls not covered by Chromium
|
||||||
|
bool GetFolderPath(int key, base::FilePath* result);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
bool GetLoginItemEnabled();
|
bool GetLoginItemEnabled();
|
||||||
bool SetLoginItemEnabled(bool enabled);
|
bool SetLoginItemEnabled(bool enabled);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "base/win/windows_version.h"
|
#include "base/win/windows_version.h"
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
|
#include "shell/common/electron_paths.h"
|
||||||
#include "ui/base/win/shell.h"
|
#include "ui/base/win/shell.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
|
@ -392,6 +393,22 @@ bool MoveItemToTrash(const base::FilePath& path, bool delete_on_fail) {
|
||||||
SUCCEEDED(pfo->PerformOperations());
|
SUCCEEDED(pfo->PerformOperations());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetFolderPath(int key, base::FilePath* result) {
|
||||||
|
wchar_t system_buffer[MAX_PATH];
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case electron::DIR_RECENT:
|
||||||
|
if (FAILED(SHGetFolderPath(NULL, CSIDL_RECENT, NULL, SHGFP_TYPE_CURRENT,
|
||||||
|
system_buffer))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*result = base::FilePath(system_buffer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Beep() {
|
void Beep() {
|
||||||
MessageBeep(MB_OK);
|
MessageBeep(MB_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -737,6 +737,22 @@ describe('app module', () => {
|
||||||
app.setPath('music', __dirname);
|
app.setPath('music', __dirname);
|
||||||
expect(app.getPath('music')).to.equal(__dirname);
|
expect(app.getPath('music')).to.equal(__dirname);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
it('gets the folder for recent files', () => {
|
||||||
|
const recent = app.getPath('recent');
|
||||||
|
|
||||||
|
// We expect that one of our test machines have overriden this
|
||||||
|
// to be something crazy, it'll always include the word "Recent"
|
||||||
|
// unless people have been registry-hacking like crazy
|
||||||
|
expect(recent).to.include('Recent');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can override the recent files path', () => {
|
||||||
|
app.setPath('recent', 'C:\\fake-path');
|
||||||
|
expect(app.getPath('recent')).to.equal('C:\\fake-path');
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setPath(name, path)', () => {
|
describe('setPath(name, path)', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue