-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/change-data-dir' into develop
- Loading branch information
Showing
17 changed files
with
208 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @author: oldj | ||
* @homepage: https://oldj.net | ||
*/ | ||
|
||
import { | ||
app, | ||
BrowserWindow, | ||
dialog, | ||
OpenDialogOptions, | ||
OpenDialogReturnValue, | ||
} from 'electron' | ||
import { localdb } from '@main/data' | ||
import getDataFolder, { getDefaultDataDir } from '@main/libs/getDataDir' | ||
import getI18N from '@main/core/getI18N' | ||
import { IActionFunc } from '@root/main/types' | ||
|
||
export default async function ( | ||
this: IActionFunc, | ||
to_default?: boolean, | ||
): Promise<string | undefined> { | ||
let { sender } = this | ||
let { lang } = await getI18N() | ||
let current_dir = getDataFolder() | ||
let dir: string = '' | ||
|
||
if (to_default) { | ||
dir = getDefaultDataDir() | ||
} else { | ||
let parent = BrowserWindow.fromWebContents(sender) | ||
if (parent?.isFullScreen()) { | ||
parent?.setFullScreen(false) | ||
} | ||
|
||
let options: OpenDialogOptions = { | ||
// title: '选择数据目录', | ||
defaultPath: current_dir, | ||
properties: ['openDirectory', 'createDirectory'], | ||
} | ||
|
||
let r: OpenDialogReturnValue | ||
|
||
if (parent) { | ||
r = await dialog.showOpenDialog(parent, options) | ||
} else { | ||
r = await dialog.showOpenDialog(options) | ||
} | ||
|
||
if (r.canceled) { | ||
return | ||
} | ||
|
||
dir = r.filePaths[0] | ||
} | ||
|
||
if (!dir || dir === current_dir) { | ||
return | ||
} | ||
|
||
await localdb.dict.local.set('data_dir', dir) | ||
dialog.showMessageBoxSync({ | ||
message: lang.need_to_relaunch_after_setting_changed, | ||
}) | ||
app.relaunch() | ||
app.exit(0) | ||
|
||
return dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @author: oldj | ||
* @homepage: https://oldj.net | ||
*/ | ||
|
||
import getDataDir from '@main/libs/getDataDir' | ||
|
||
export default async () => getDataDir() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @author: oldj | ||
* @homepage: https://oldj.net | ||
*/ | ||
|
||
import { getDefaultDataDir } from '@main/libs/getDataDir' | ||
|
||
export default async () => getDefaultDataDir() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @author: oldj | ||
* @homepage: https://oldj.net | ||
*/ | ||
|
||
import * as path from 'path' | ||
import { homedir } from 'os' | ||
|
||
export function getDefaultDataDir() { | ||
return path.join(homedir(), '.SwitchHosts') | ||
} | ||
|
||
export default (): string => { | ||
// todo data folder should be current working dir for portable version | ||
|
||
return global.data_dir || getDefaultDataDir() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.