This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
108 additions
and
6 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
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,46 @@ | ||
import { isWin } from './env'; | ||
import { dialog as _dialog, remote } from 'electron'; | ||
import logger from '../main/logger'; | ||
|
||
const dialog = _dialog || remote.dialog; | ||
|
||
async function choose( | ||
title, | ||
filters, | ||
isFile = true, | ||
isSave = false, | ||
defaultPath | ||
) { | ||
const pathObject = await dialog[isSave ? 'showSaveDialog' : 'showOpenDialog']( | ||
{ | ||
title, | ||
defaultPath, | ||
properties: [isFile ? 'openFile' : 'openDirectory'], | ||
filters, | ||
buttonLabel: isSave ? '导出配置' : '导入配置', | ||
} | ||
); | ||
logger.debug('pathObject:', pathObject); | ||
|
||
if (isSave && !pathObject.canceled) { | ||
return pathObject.filePath; | ||
} else if ( | ||
pathObject.filePaths && | ||
pathObject.filePaths.length && | ||
!pathObject.canceled | ||
) { | ||
if (isWin) { | ||
return pathObject.filePaths[0].replace(/\\/g, '\\\\'); | ||
} | ||
return pathObject.filePaths[0]; | ||
} | ||
return null; | ||
} | ||
|
||
export function chooseFile(title, filters, defaultPath) { | ||
return choose(title, filters, true, false, defaultPath); | ||
} | ||
|
||
export function chooseSavePath(title, filters, defaultPath) { | ||
return choose(title, filters, true, true, defaultPath); | ||
} |