Skip to content

Commit

Permalink
show welcome notification on first launch with dependency check
Browse files Browse the repository at this point in the history
- check atom-ide-ui dependency
- TODO programatically input text in settings page
  • Loading branch information
liuderchi committed Oct 4, 2017
1 parent a14bba6 commit c51b374
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
WELCOME_SHOWN
2 changes: 2 additions & 0 deletions src/main.js
Expand Up @@ -2,9 +2,11 @@ const path = require('path')
const { AutoLanguageClient } = require('atom-languageclient')
const { registerConfigOnChangeHandlers } = require('./util')
const { registerHelpCommands } = require('./help_cmd')
const { showWelcomeNotification } = require('./welcome_notification')

registerConfigOnChangeHandlers()
registerHelpCommands()
showWelcomeNotification()

class HTMLLanguageClient extends AutoLanguageClient {
getGrammarScopes () {
Expand Down
76 changes: 76 additions & 0 deletions src/welcome_notification.js
@@ -0,0 +1,76 @@
// show welcome message on first installation
const path = require('path')
const fs = require('fs')

const WELCOME_SHOWN = path.join(__dirname, '..', 'WELCOME_SHOWN')

const generateWelcomeMsg = () => {
return `## Welcome to ide-html\n\nQuick start for ide-html:\n${[
'Open a HTML file from the Project',
'Dispatch command `Outline View: Toggle`',
].map((str, i) => `${i}. ${str}\n`).join('')
}\nHappy Using Atom IDE : )`
}

const generateWarnMsg = () => {
return `## Welcome to ide-html\n\nPlease install following requirements:\n${[
'[`atom-ide-ui`](https://atom.io/packages/atom-ide-ui)',
].map((str, i) => `${i}. ${str}\n`).join('')
}\nso that ide-html can work properly`
}

const helpButton = [
{
text: ' Help',
onDidClick: () => { atom.commands.dispatch(
atom.views.getView(atom.workspace.getActivePane()),
'ide-html:help'
)},
className: 'btn btn-success btn-lg icon-light-bulb',
},
]

const settingsButton = [
{
text: ' Open Settings Page',
onDidClick: () => {
atom.commands.dispatch(
atom.views.getView(atom.workspace.getActivePane()),
'settings-view:install-packages-and-themes'
)
},
className: 'btn btn-success btn-lg icon-tools',
},
]

const showWelcomeNotification = () => {
try {
fs.accessSync(WELCOME_SHOWN)
} catch (err) {
if (atom.packages.isPackageLoaded('atom-ide-ui')) {
atom.notifications.addSuccess(
generateWelcomeMsg(),
{
buttons: helpButton,
dismissable: true,
icon: 'thumbsup',
}
)
fs.closeSync(fs.openSync(WELCOME_SHOWN, 'w'))
} else {
atom.notifications.addWarning(
generateWarnMsg(),
{
buttons: settingsButton,
dismissable: true,
icon: 'info',
}
)
}
}
}


module.exports = {
showWelcomeNotification,
}

0 comments on commit c51b374

Please sign in to comment.