diff --git a/docs/development.md b/docs/development.md index 37c884da..30f8806f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -78,18 +78,18 @@ Format the source codes to pass `npm test`. ``` Mattermost Desktop ├── docs/ - Documentations. -├── resources/ - Resources which are used outside of the application codes. +├── resources/ - Resources which are used outside of the application codes, and original images of assets. ├── scripts/ - Helper scripts. ├── src/ - Application source code. +│   ├── assets/ - Assets which are loaded from the application codes. │   ├── browser/ - Implementation of Electron's renderer process. │   │   ├── components/ - React.js components. │   │   ├── css/ - Stylesheets. │   │   ├── js/ - Helper JavaScript modules. │   │   └── webview/ - Injection code for Electron's tag. │   ├── common/ - Common JavaScript modules for both Electron's processes. -│   ├── main/ - Implementation of Electron's main process. -│   │   └── menus/ - Application menu. -│   └── resources/ - Resources which are loaded from the application codes. +│   └── main/ - Implementation of Electron's main process. +│      └── menus/ - Application menu. └── test/ - Automated tests.    ├── modules/ - Scripts which are commonly used in tests.    └── specs/ - Test scripts. diff --git a/gulpfile.js b/gulpfile.js index aa437a27..2b167e7c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -68,11 +68,11 @@ gulp.task('build', ['sync-meta', 'copy'], (cb) => { fs.writeFile('./dist/package.json', JSON.stringify(distPackageJson, null, ' '), cb); }); -gulp.task('copy', ['copy:resources', 'copy:html/css', 'copy:modules']); +gulp.task('copy', ['copy:assets', 'copy:html/css', 'copy:modules']); -gulp.task('copy:resources', () => { - return gulp.src('src/resources/**'). - pipe(gulp.dest('dist/resources')); +gulp.task('copy:assets', () => { + return gulp.src('src/assets/**'). + pipe(gulp.dest('dist/assets')); }); gulp.task('copy:html/css', () => { @@ -108,9 +108,9 @@ gulp.task('watch', ['build', 'webpack:main', 'webpack:renderer'], () => { gulp.watch(['src/main.js', 'src/main/**/*.js', 'src/common/**/*.js'], ['webpack:main']); gulp.watch(['src/browser/**/*.js', 'src/browser/**/*.jsx'], ['webpack:renderer']); - gulp.watch(['src/browser/**/*.css', 'src/browser/**/*.html', 'src/resources/**/*.png'], ['copy']); + gulp.watch(['src/browser/**/*.css', 'src/browser/**/*.html', 'src/assets/**/*.png'], ['copy']); - gulp.watch(['dist/main.js', 'dist/resources/**'], () => { + gulp.watch(['dist/main.js', 'dist/assets/**'], () => { electron.restart(options); }); gulp.watch(['dist/browser/*.js'], electron.reload); diff --git a/src/resources/appicon.png b/src/assets/appicon.png similarity index 100% rename from src/resources/appicon.png rename to src/assets/appicon.png diff --git a/src/resources/linux/dark/MenuIconMentionTemplate.png b/src/assets/linux/dark/MenuIconMentionTemplate.png similarity index 100% rename from src/resources/linux/dark/MenuIconMentionTemplate.png rename to src/assets/linux/dark/MenuIconMentionTemplate.png diff --git a/src/resources/linux/dark/MenuIconTemplate.png b/src/assets/linux/dark/MenuIconTemplate.png similarity index 100% rename from src/resources/linux/dark/MenuIconTemplate.png rename to src/assets/linux/dark/MenuIconTemplate.png diff --git a/src/resources/linux/dark/MenuIconUnreadTemplate.png b/src/assets/linux/dark/MenuIconUnreadTemplate.png similarity index 100% rename from src/resources/linux/dark/MenuIconUnreadTemplate.png rename to src/assets/linux/dark/MenuIconUnreadTemplate.png diff --git a/src/resources/linux/light/MenuIconMentionTemplate.png b/src/assets/linux/light/MenuIconMentionTemplate.png similarity index 100% rename from src/resources/linux/light/MenuIconMentionTemplate.png rename to src/assets/linux/light/MenuIconMentionTemplate.png diff --git a/src/resources/linux/light/MenuIconTemplate.png b/src/assets/linux/light/MenuIconTemplate.png similarity index 100% rename from src/resources/linux/light/MenuIconTemplate.png rename to src/assets/linux/light/MenuIconTemplate.png diff --git a/src/resources/linux/light/MenuIconUnreadTemplate.png b/src/assets/linux/light/MenuIconUnreadTemplate.png similarity index 100% rename from src/resources/linux/light/MenuIconUnreadTemplate.png rename to src/assets/linux/light/MenuIconUnreadTemplate.png diff --git a/src/resources/osx/ClickedMenuIcon.png b/src/assets/osx/ClickedMenuIcon.png similarity index 100% rename from src/resources/osx/ClickedMenuIcon.png rename to src/assets/osx/ClickedMenuIcon.png diff --git a/src/resources/osx/ClickedMenuIcon@2x.png b/src/assets/osx/ClickedMenuIcon@2x.png similarity index 100% rename from src/resources/osx/ClickedMenuIcon@2x.png rename to src/assets/osx/ClickedMenuIcon@2x.png diff --git a/src/resources/osx/ClickedMenuIconMention.png b/src/assets/osx/ClickedMenuIconMention.png similarity index 100% rename from src/resources/osx/ClickedMenuIconMention.png rename to src/assets/osx/ClickedMenuIconMention.png diff --git a/src/resources/osx/ClickedMenuIconMention@2x.png b/src/assets/osx/ClickedMenuIconMention@2x.png similarity index 100% rename from src/resources/osx/ClickedMenuIconMention@2x.png rename to src/assets/osx/ClickedMenuIconMention@2x.png diff --git a/src/resources/osx/ClickedMenuIconUnread.png b/src/assets/osx/ClickedMenuIconUnread.png similarity index 100% rename from src/resources/osx/ClickedMenuIconUnread.png rename to src/assets/osx/ClickedMenuIconUnread.png diff --git a/src/resources/osx/ClickedMenuIconUnread@2x.png b/src/assets/osx/ClickedMenuIconUnread@2x.png similarity index 100% rename from src/resources/osx/ClickedMenuIconUnread@2x.png rename to src/assets/osx/ClickedMenuIconUnread@2x.png diff --git a/src/resources/osx/MenuIcon.png b/src/assets/osx/MenuIcon.png similarity index 100% rename from src/resources/osx/MenuIcon.png rename to src/assets/osx/MenuIcon.png diff --git a/src/resources/osx/MenuIcon@2x.png b/src/assets/osx/MenuIcon@2x.png similarity index 100% rename from src/resources/osx/MenuIcon@2x.png rename to src/assets/osx/MenuIcon@2x.png diff --git a/src/resources/osx/MenuIconMention.png b/src/assets/osx/MenuIconMention.png similarity index 100% rename from src/resources/osx/MenuIconMention.png rename to src/assets/osx/MenuIconMention.png diff --git a/src/resources/osx/MenuIconMention@2x.png b/src/assets/osx/MenuIconMention@2x.png similarity index 100% rename from src/resources/osx/MenuIconMention@2x.png rename to src/assets/osx/MenuIconMention@2x.png diff --git a/src/resources/osx/MenuIconUnread.png b/src/assets/osx/MenuIconUnread.png similarity index 100% rename from src/resources/osx/MenuIconUnread.png rename to src/assets/osx/MenuIconUnread.png diff --git a/src/resources/osx/MenuIconUnread@2x.png b/src/assets/osx/MenuIconUnread@2x.png similarity index 100% rename from src/resources/osx/MenuIconUnread@2x.png rename to src/assets/osx/MenuIconUnread@2x.png diff --git a/src/resources/windows/tray.ico b/src/assets/windows/tray.ico similarity index 100% rename from src/resources/windows/tray.ico rename to src/assets/windows/tray.ico diff --git a/src/resources/windows/tray_mention.ico b/src/assets/windows/tray_mention.ico similarity index 100% rename from src/resources/windows/tray_mention.ico rename to src/assets/windows/tray_mention.ico diff --git a/src/resources/windows/tray_unread.ico b/src/assets/windows/tray_unread.ico similarity index 100% rename from src/resources/windows/tray_unread.ico rename to src/assets/windows/tray_unread.ico diff --git a/src/browser/js/notification.js b/src/browser/js/notification.js index ca8a3730..2e63ae50 100644 --- a/src/browser/js/notification.js +++ b/src/browser/js/notification.js @@ -3,7 +3,7 @@ const OriginalNotification = Notification; const {remote} = require('electron'); -const appIconURL = `file:///${remote.app.getAppPath()}/resources/appicon.png`; +const appIconURL = `file:///${remote.app.getAppPath()}/assets/appicon.png`; function override(eventHandlers) { Notification = function constructor(title, options) { // eslint-disable-line no-global-assign, no-native-reassign diff --git a/src/main.js b/src/main.js index 1873ec71..8edf8b6f 100644 --- a/src/main.js +++ b/src/main.js @@ -58,6 +58,8 @@ const appMenu = require('./main/menus/app'); const trayMenu = require('./main/menus/tray'); const allowProtocolDialog = require('./main/allowProtocolDialog'); +const assetsDir = path.resolve(app.getAppPath(), 'assets'); + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. var mainWindow = null; @@ -122,34 +124,36 @@ const trayImages = (() => { switch (process.platform) { case 'win32': return { - normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray.ico')), - unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_unread.ico')), - mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_mention.ico')) + normal: nativeImage.createFromPath(path.resolve(assetsDir, 'windows/tray.ico')), + unread: nativeImage.createFromPath(path.resolve(assetsDir, 'windows/tray_unread.ico')), + mention: nativeImage.createFromPath(path.resolve(assetsDir, 'windows/tray_mention.ico')) }; case 'darwin': { const icons = { light: { - normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIcon.png')), - unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconUnread.png')), - mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIconMention.png')) + normal: nativeImage.createFromPath(path.resolve(assetsDir, 'osx/MenuIcon.png')), + unread: nativeImage.createFromPath(path.resolve(assetsDir, 'osx/MenuIconUnread.png')), + mention: nativeImage.createFromPath(path.resolve(assetsDir, 'osx/MenuIconMention.png')) }, clicked: { - normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIcon.png')), - unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconUnread.png')), - mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/ClickedMenuIconMention.png')) + normal: nativeImage.createFromPath(path.resolve(assetsDir, 'osx/ClickedMenuIcon.png')), + unread: nativeImage.createFromPath(path.resolve(assetsDir, 'osx/ClickedMenuIconUnread.png')), + mention: nativeImage.createFromPath(path.resolve(assetsDir, 'osx/ClickedMenuIconMention.png')) } }; switchMenuIconImages(icons, systemPreferences.isDarkMode()); return icons; } case 'linux': - var resourcesDir = 'resources/linux/' + (config.trayIconTheme || 'light') + '/'; - return { - normal: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconTemplate.png')), - unread: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconUnreadTemplate.png')), - mention: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconMentionTemplate.png')) - }; + { + const theme = config.trayIconTheme || 'light'; + return { + normal: nativeImage.createFromPath(path.resolve(assetsDir, 'linux', theme, 'MenuIconTemplate.png')), + unread: nativeImage.createFromPath(path.resolve(assetsDir, 'linux', theme, 'MenuIconUnreadTemplate.png')), + mention: nativeImage.createFromPath(path.resolve(assetsDir, 'linux', theme, 'MenuIconMentionTemplate.png')) + }; + } default: return {}; } @@ -346,7 +350,7 @@ app.on('ready', () => { // In current version, use tray balloon for notification if (osVersion.isLowerThanOrEqualWindows8_1()) { trayIcon.displayBalloon({ - icon: path.resolve(__dirname, 'resources/appicon.png'), + icon: path.resolve(assetsDir, 'appicon.png'), title: arg.title, content: arg.options.body }); @@ -394,7 +398,7 @@ app.on('ready', () => { windowOptions = {}; } if (process.platform === 'linux') { - windowOptions.icon = path.resolve(__dirname, 'resources/appicon.png'); + windowOptions.icon = path.resolve(assetsDir, 'appicon.png'); } windowOptions.title = app.getName(); mainWindow = new BrowserWindow(windowOptions);