Skip to content

Commit a9d9bb6

Browse files
committed
add sketch plugin
1 parent f53bb49 commit a9d9bb6

File tree

17 files changed

+3569
-10
lines changed

17 files changed

+3569
-10
lines changed

app/src/lib/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum HttpStatusCode {
2828
}
2929

3030
/** The note URL used for authorizations the app creates. */
31-
const NoteURL = 'https://kactus.io/'
31+
const NoteURL = 'http://kactus.io/'
3232

3333
/**
3434
* Information about a repository as returned by the GitHub API.

app/src/lib/dispatcher/dispatcher.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ export class Dispatcher {
866866
}
867867
break
868868

869-
case 'open-repository-from-path':
869+
case 'open-repository-from-path': {
870870
const state = this.appStore.getState()
871871
const repositories = state.repositories
872872
const existingRepository = repositories.find(r => {
@@ -888,6 +888,40 @@ export class Dispatcher {
888888
})
889889
}
890890
break
891+
}
892+
893+
case 'open-sketch-file': {
894+
const state = this.appStore.getState()
895+
const repositories = state.repositories
896+
const existingRepository = repositories.find(r => {
897+
if (__WIN32__) {
898+
// Windows is guaranteed to be case-insensitive so we can be a
899+
// bit more accepting.
900+
return Path.normalize(action.path).toLowerCase().indexOf(Path.normalize(r.path).toLowerCase()) === 0
901+
} else {
902+
return Path.normalize(action.path).indexOf(Path.normalize(r.path)) === 0
903+
}
904+
})
905+
906+
if (existingRepository) {
907+
this.selectRepository(existingRepository)
908+
if (existingRepository instanceof Repository) {
909+
const repositoryState = this.appStore.getRepositoryState(existingRepository)
910+
const existingFile = repositoryState.kactus.files.find(f => {
911+
return Path.normalize(f.path + '.sketch') === Path.normalize(action.path)
912+
})
913+
if (existingFile) {
914+
this.changeSketchFileSelection(existingRepository, existingFile)
915+
}
916+
}
917+
} else {
918+
return this.showPopup({
919+
type: PopupType.AddRepository,
920+
path: Path.dirname(action.path),
921+
})
922+
}
923+
break
924+
}
891925

892926
default:
893927
const unknownAction: IUnknownAction = action

app/src/lib/parse-app-url.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export interface IOpenRepositoryFromPathAction {
2929
readonly path: string
3030
}
3131

32+
export interface IOpenSketchFileAction {
33+
readonly name: 'open-sketch-file'
34+
35+
/** The local path to open. */
36+
readonly path: string
37+
}
38+
3239
export interface IUnknownAction {
3340
readonly name: 'unknown'
3441
}
@@ -38,6 +45,7 @@ export type URLActionType =
3845
| IOpenRepositoryFromURLAction
3946
| IOpenRepositoryFromPathAction
4047
| IUnknownAction
48+
| IOpenSketchFileAction
4149

4250
export function parseAppURL(url: string): URLActionType {
4351
const parsedURL = URL.parse(url, true)
@@ -99,5 +107,12 @@ export function parseAppURL(url: string): URLActionType {
99107
}
100108
}
101109

110+
if (actionName === 'opensketchfile') {
111+
return {
112+
name: 'open-sketch-file',
113+
path: decodeURIComponent(parsedPath),
114+
}
115+
}
116+
102117
return unknown
103118
}

app/src/lib/stats/stats-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { getGUID } from './get-guid'
88
import { Repository } from '../../models/repository'
99
import { merge } from '../../lib/merge'
1010

11-
const StatsEndpoint = 'https://kactus.io/api/usage/desktop'
11+
const StatsEndpoint = 'https://api.kactus.io/v1/usage/desktop'
1212

1313
/** The URL to the stats samples page. */
14-
export const SamplesURL = 'https://kactus.io/usage-data/'
14+
export const SamplesURL = 'http://kactus.io/usage-data/'
1515

1616
const LastDailyStatsReportKey = 'last-daily-stats-report'
1717

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Path from 'path'
2+
import * as Fs from 'fs'
3+
4+
/** Symlink the sketch plugin to the sketch plugin folder */
5+
export function symlinkSketchPlugin() {
6+
// skip a thread not to delay the startup
7+
Promise.resolve().then(() => {
8+
const pluginDirectory = require('os').homedir() + '/Library/Application Support/com.bohemiancoding.sketch3/Plugins/'
9+
const pluginPath = Path.join(pluginDirectory, 'kactus.sketchplugin')
10+
11+
// check if the plugin is already there
12+
Fs.stat(pluginPath, (err) => {
13+
if (err) {
14+
Fs.symlink(Path.resolve(__dirname, './plugin.sketchplugin'), pluginPath, undefined, (err) => {
15+
console.error(err)
16+
})
17+
}
18+
})
19+
})
20+
}

app/src/main-process/exception-reporting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { app, net } from 'electron'
22

3-
const ErrorEndpoint = 'https://kactus.io/api/usage/desktop/exception'
3+
const ErrorEndpoint = 'https://api.kactus.io/v1/usage/desktop/exception'
44

55
/** Report the error to Central. */
66
export async function reportError(error: Error, extra?: { [key: string]: string }) {

app/src/main-process/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import { log as writeLog } from './log'
1717
import { formatError } from '../lib/logging/format-error'
1818
import { reportError } from './exception-reporting'
1919
import { enableSourceMaps, withSourceMappedStack } from '../lib/source-map-support'
20+
import { symlinkSketchPlugin } from '../lib/symlink-sketch-plugin'
2021
import { now } from './now'
2122

2223
enableSourceMaps()
24+
symlinkSketchPlugin()
2325

2426
let mainWindow: AppWindow | null = null
2527
let sharedProcess: SharedProcess | null = null

app/src/ui/about/about.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface IAboutState {
4141
readonly updateState: IUpdateState
4242
}
4343

44-
const releaseNotesUri = 'https://kactus.io/release-notes/'
44+
const releaseNotesUri = 'http://kactus.io/release-notes/'
4545

4646
/**
4747
* A dialog that presents information about the

app/src/ui/repository-settings/repository-settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class RepositorySettings extends React.Component<IRepositorySettingsProps
161161
}
162162

163163
private onShowKactusDoc = () => {
164-
this.props.dispatcher.openInBrowser('https://kactus.io/docs/kactus.json')
164+
this.props.dispatcher.openInBrowser('http://kactus.io/help/kactus-dot-json')
165165
}
166166

167167
private onSubmit = async () => {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
"test": "npm run test:unit # && npm run test:integration",
1111
"test:setup": "node script/test-setup",
1212
"test:review": "node script/test-review",
13-
"postinstall": "cd app && npm install && cd .. && git submodule update --recursive --init && npm run compile:tslint",
13+
"postinstall": "cd app && npm install && cd .. && git submodule update --recursive --init && npm run compile:tslint && cd plugin && npm install",
1414
"start": "cross-env NODE_ENV=development node script/start",
1515
"start:prod": "cross-env NODE_ENV=production node script/start",
1616
"debug": "cross-env NODE_ENV=development node script/debug",
17-
"compile:dev": "cross-env NODE_ENV=development parallel-webpack --config app/webpack.development.js",
18-
"compile:prod": "cross-env NODE_ENV=production parallel-webpack --config app/webpack.production.js",
17+
"compile:plugin": "cd plugin && npm run build",
18+
"compile:dev": "cross-env NODE_ENV=development parallel-webpack --config app/webpack.development.js && npm run compile:plugin",
19+
"compile:prod": "cross-env NODE_ENV=production parallel-webpack --config app/webpack.production.js && npm run compile:plugin",
1920
"build:dev": "npm run compile:dev && cross-env NODE_ENV=development node script/build",
2021
"build:prod": "npm run compile:prod && cross-env NODE_ENV=production node script/build",
2122
"package": "node script/package",

0 commit comments

Comments
 (0)