diff --git a/app/package.json b/app/package.json index 7be3ae35..f84ca928 100644 --- a/app/package.json +++ b/app/package.json @@ -47,7 +47,8 @@ }, "files": [ "packages", - "src" + "src", + "icon.png" ] }, "homepage": "./", diff --git a/app/src/electron.js b/app/src/electron.js index 84db55d8..9b28d3a2 100644 --- a/app/src/electron.js +++ b/app/src/electron.js @@ -1,5 +1,6 @@ const electron = require('electron'); const os = require('os'); +const fs = require('fs'); const { Menu } = require('electron'); const { fork } = require('child_process'); const { autoUpdater } = require('electron-updater'); @@ -24,6 +25,18 @@ let splashWindow; log.transports.file.level = 'debug'; autoUpdater.logger = log; +function datadir() { + const dir = path.join(os.homedir(), 'dbgate-data'); + if (!fs.existsSync(dir)) { + try { + fs.mkdirSync(dir); + } catch (err) { + console.error(`Error creating ${dir} directory`, err); + } + } + return dir; +} + function hideSplash() { if (splashWindow) { splashWindow.destroy(); @@ -151,7 +164,9 @@ function createWindow() { }); mainWindow.loadURL(startUrl); if (os.platform() == 'linux') { - mainWindow.setIcon(path.resolve(__dirname, '../icon.png')); + const iconFile = path.join(datadir(), 'dbgate-icon.png'); + fs.copyFileSync(path.resolve(__dirname, '../icon.png'), iconFile); + mainWindow.setIcon(iconFile); } } diff --git a/packages/api/src/utility/directories.js b/packages/api/src/utility/directories.js index f1c41ac5..aaffc88c 100644 --- a/packages/api/src/utility/directories.js +++ b/packages/api/src/utility/directories.js @@ -12,7 +12,11 @@ const ensureDirectory = (dir, clean) => { } if (!fs.existsSync(dir)) { console.log(`Creating directory ${dir}`); - fs.mkdirSync(dir); + try { + fs.mkdirSync(dir); + } catch (err) { + console.error(`Error creating ${dir} directory`, err); + } } createDirectories[dir] = true; }