-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from kid-icarus/rk/configurable-config-path
Allow for configurable config files.
- Loading branch information
Showing
12 changed files
with
182 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"time": 25, | ||
"plugins": { | ||
"application-manager": { | ||
"enabled": false | ||
}, | ||
"bell": { | ||
"enabled": false | ||
}, | ||
"logger": { | ||
"enabled": true | ||
}, | ||
"rain": { | ||
"enabled": false | ||
}, | ||
"rescue-time": { | ||
"enabled": false | ||
}, | ||
"slack": { | ||
"enabled": false | ||
}, | ||
"spotify": { | ||
"enabled": false | ||
}, | ||
"tracker": { | ||
"enabled": false | ||
}, | ||
"webhooks": { | ||
"enabled": false | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,39 @@ | ||
const fs = require('fs') | ||
const {join} = require('path') | ||
const APP_NAME = 'FocusMe' | ||
|
||
const scriptLibrariesDir = join(process.env.HOME, 'Library', 'Script Libraries'); | ||
const focusMeDir = join(scriptLibrariesDir, 'focus-me-applescripts'); | ||
const applicationSupportDir = join(process.env.HOME, 'Library', 'Application Support', APP_NAME); | ||
const configFile = join(process.env.HOME, 'Library', 'Application Support', APP_NAME, 'preferences.json'); | ||
const focusMeDir = join(scriptLibrariesDir, APP_NAME); | ||
|
||
const createSymlink = () => { | ||
/** | ||
* Initial post-install script to install default applescripts and configuration. | ||
*/ | ||
const install = () => { | ||
if (!fs.existsSync(scriptLibrariesDir)) { | ||
console.log('Applescript script libraries directory does not exist, creating it.') | ||
fs.mkdirSync(scriptLibrariesDir) | ||
} | ||
|
||
if (!fs.existsSync(applicationSupportDir)) { | ||
console.log('FocusMe application support directory does not exist, creating it.') | ||
fs.mkdirSync(applicationSupportDir) | ||
} | ||
|
||
if (!fs.existsSync(configFile)) { | ||
console.log('FocusMe config does not exist, creating it.') | ||
fs.copyFile(join(__dirname, 'default-preferences.json'), configFile, (err) => { | ||
if (err) { | ||
console.error('Error saving default config: ', e) | ||
} | ||
}) | ||
} | ||
|
||
if (!fs.existsSync(focusMeDir)) { | ||
console.log('Symlinking compiled applescript libraries.') | ||
fs.symlinkSync(join(__dirname, 'dist/util/focus-me-applescripts'), focusMeDir); | ||
} | ||
} | ||
|
||
createSymlink(); | ||
install(); |
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 |
---|---|---|
@@ -1,23 +1,12 @@ | ||
const util = Library('focus-me-applescripts/util'); | ||
const util = Library('FocusMe/util'); | ||
const config = util.getConfig(); | ||
|
||
config.plugins['application-manager'].close.forEach(({ name }) => { | ||
const app = Application(name); | ||
const realName = app.name(); | ||
const displayedName = app.displayedName(); | ||
const id = app.id(); | ||
try { | ||
if (app.running()) app.quit(); | ||
if (app && app.running()) app.quit(); | ||
} catch (e) { | ||
// Sometimes some MailQuickLookExtension process makes Mail falsely report itself as running. | ||
console.log( | ||
`Could not quit ${name}: | ||
found ${realName} with: | ||
id: ${id} | ||
name: ${name} | ||
displayedName: ${displayedName} | ||
`, | ||
); | ||
console.log(e); | ||
console.log(`Could not close ${name}: `, e); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,9 +1,29 @@ | ||
import { join } from 'path'; | ||
import { ExecException } from 'child_process'; | ||
import { exec, ExecException } from 'child_process'; | ||
|
||
export const script = (plugin: string, file: string) => | ||
join(__dirname, '..', 'plugins', plugin, 'applescripts', file); | ||
|
||
export const log = (error: ExecException | null): void => { | ||
if (error) console.error(error); | ||
}; | ||
|
||
export const execAppleScript = ( | ||
plugin: string, | ||
file: string, | ||
configPath: string, | ||
): Promise<{ stdout: string; stderr: string }> => | ||
new Promise((res, rej) => { | ||
exec( | ||
`osascript -l JavaScript ${script(plugin, file)}`, | ||
{ env: { config: configPath } }, | ||
(err, stdout, stderr) => { | ||
if (err) return rej(err); | ||
|
||
res({ | ||
stderr, | ||
stdout, | ||
}); | ||
}, | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
function getConfig(path) { | ||
let env = $.NSProcessInfo.processInfo.environment; | ||
env = ObjC.unwrap(env); | ||
const configPath = ObjC.unwrap(env.config); | ||
|
||
function getConfig() { | ||
const app = Application.currentApplication(); | ||
app.includeStandardAdditions = true; | ||
const file = app.openForAccess(`${app.pathTo('home folder')}/.timerrc.json`); | ||
const file = app.openForAccess( | ||
configPath || | ||
`${app.pathTo('application support', { | ||
from: 'user domain', | ||
})}/FocusMe/timerrc.json`, | ||
); | ||
const contents = app.read(file); | ||
return JSON.parse(contents); | ||
} |
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