summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-05-08 15:09:51 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-05-14 09:22:21 -0300
commitc0fbe1d0c00b7bcb4c988ffeb4bbf20ecb51dc4a (patch)
tree4a82ef6a004f16c3c187a0b1d01db45938a608ff
parent692f0c810a3fbb869ac556606384312ac8e60eec (diff)
downloadmullvadvpn-c0fbe1d0c00b7bcb4c988ffeb4bbf20ecb51dc4a.tar.xz
mullvadvpn-c0fbe1d0c00b7bcb4c988ffeb4bbf20ecb51dc4a.zip
Change path of RPC connection info file on Windows
-rw-r--r--app/main.js45
-rw-r--r--mullvad-ipc-client/src/lib.rs10
2 files changed, 38 insertions, 17 deletions
diff --git a/app/main.js b/app/main.js
index ffc9016799..ea85de8b36 100644
--- a/app/main.js
+++ b/app/main.js
@@ -22,7 +22,6 @@ const isDevelopment = (process.env.NODE_ENV === 'development');
// The name for application directory used for
// scoping logs and user data in platform special folders
const appDirectoryName = 'Mullvad VPN';
-const rpcAddressFile = path.join(getSystemTemporaryDirectory(), '.mullvad_rpc_address');
let browserWindowReady = false;
@@ -81,18 +80,28 @@ const appDelegate = {
case 'darwin':
// macOS: ~/Library/Logs/{appname}
return path.join(app.getPath('home'), 'Library/Logs', appDirectoryName);
+ case 'win32':
+ // Windows: %ALLUSERSPROFILE%\{appname}
+ return appDelegate._getSharedDataDirectory();
+ default:
+ // Linux: ~/.config/{appname}/logs
+ return path.join(app.getPath('userData'), 'logs');
+ }
+ },
+
+ _getSharedDataDirectory: () => {
+ switch(process.platform) {
case 'win32': {
// Windows: %ALLUSERSPROFILE%\{appname}
- let appDataDir = process.env.ALLUSERSPROFILE;
- if (appDataDir) {
- return path.join(appDataDir, appDirectoryName);
- } else {
+ let programDataDirectory = process.env.ALLUSERSPROFILE;
+ if (typeof programDataDirectory === 'undefined' || programDataDirectory === null) {
throw new Error('Missing %ALLUSERSPROFILE% environment variable');
+ } else {
+ return path.join(programDataDirectory, appDirectoryName);
}
}
default:
- // Linux: ~/.config/{appname}/logs
- return path.join(app.getPath('userData'), 'logs');
+ throw new Error(`No shared data directory on platform: ${process.platform}`);
}
},
@@ -181,7 +190,8 @@ const appDelegate = {
},
_startBackend: () => {
- const backendIsRunning = appDelegate._rpcAddressFileExists();
+ const rpcAddressFile = appDelegate._getRpcAddressFilePath();
+ const backendIsRunning = fs.existsSync(rpcAddressFile);
if (backendIsRunning) {
log.info('Not starting the backend as it appears to already be running');
return;
@@ -205,8 +215,15 @@ const appDelegate = {
return p;
});
},
- _rpcAddressFileExists: () => {
- return fs.existsSync(rpcAddressFile);
+ _getRpcAddressFilePath: () => {
+ const rpcAddressFileName = '.mullvad_rpc_address';
+
+ switch(process.platform) {
+ case 'win32':
+ return path.join(appDelegate._getSharedDataDirectory(), rpcAddressFileName);
+ default:
+ return path.join(getSystemTemporaryDirectory(), rpcAddressFileName);
+ }
},
_setupBackendProcessListeners: (p) => {
// electron-sudo writes all output to some buffers in memory.
@@ -239,22 +256,24 @@ const appDelegate = {
return;
}
+ const rpcAddressFile = appDelegate._getRpcAddressFilePath();
+
const pollIntervalMs = 200;
appDelegate.connectionFilePollInterval = setInterval(() => {
- if (browserWindowReady && appDelegate._rpcAddressFileExists()) {
+ if (browserWindowReady && fs.existsSync(rpcAddressFile)) {
if (appDelegate.connectionFilePollInterval) {
clearInterval(appDelegate.connectionFilePollInterval);
appDelegate.connectionFilePollInterval = null;
}
- appDelegate._sendBackendInfo();
+ appDelegate._sendBackendInfo(rpcAddressFile);
}
}, pollIntervalMs);
},
- _sendBackendInfo: () => {
+ _sendBackendInfo: (rpcAddressFile: string) => {
const window = appDelegate._window;
if (!window) {
log.error('Attempted to send backend rpc address before the window was ready');
diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs
index 0105176fb6..6b570d9d03 100644
--- a/mullvad-ipc-client/src/lib.rs
+++ b/mullvad-ipc-client/src/lib.rs
@@ -227,12 +227,14 @@ mod platform_specific {
mod platform_specific {
use super::*;
+ static PRODUCT_NAME: &str = "Mullvad VPN";
+
pub fn rpc_file_path() -> Result<PathBuf> {
- let windows_directory =
- ::std::env::var_os("WINDIR").ok_or_else(|| ErrorKind::UnknownRpcFilePath)?;
+ let shared_data_directory =
+ ::std::env::var_os("ALLUSERSPROFILE").ok_or_else(|| ErrorKind::UnknownRpcFilePath)?;
- Ok(PathBuf::from(windows_directory)
- .join("Temp")
+ Ok(PathBuf::from(shared_data_directory)
+ .join(PRODUCT_NAME)
.join(".mullvad_rpc_address"))
}