|
本帖最后由 Qter 于 2020-9-18 18:11 编辑
https://github.com/Foundry376/Mailspring/blob/master/CONTRIBUTING.md
npm install --global --production windows-build-tools
git clone https://github.com/foundry376/mailspring
cd mailspring
npm install
npm start
package.json- "scripts": {
- "postinstall": "node scripts/postinstall.js",
- "start": "node_modules/.bin/electron ./app --enable-logging --dev",
- "lint": "grunt lint --gruntfile=app/build/Gruntfile.js --base=./",
- "test": "node_modules/.bin/electron ./app --enable-logging --test",
- "test-window": "node_modules/.bin/electron ./app --enable-logging --test=window",
- "build": "grunt build-client --gruntfile=app/build/Gruntfile.js --base=./",
- "build-docs": "grunt docs --gruntfile=app/build/Gruntfile.js --base=./ && mkdir -p app/dist-docs && cp README.md ./app/build/docs_src/README.md && gitbook --gitbook=latest build . ./app/dist-docs --log=debug --debug && rm ./app/build/docs_src/README.md && rm -rf ./app/build/docs_src/classes",
- "build-licenses-file": "cat ./app/static/all_licenses_preamble.html | ./node_modules/.bin/marked > ./app/static/all_licenses.html && licext --source ./app --mode output | ./node_modules/.bin/marked >> ./app/static/all_licenses.html",
- "ci-setup-mac-keychain": "grunt setup-mac-keychain --gruntfile=app/build/Gruntfile.js --base=./"
- }
复制代码 app\package.json- "main": "./src/browser/main.js",
复制代码- const Application = require(path.join(options.resourcePath, 'src', 'browser', 'application'))
- .default;
- global.application = new Application();
- global.application.start(options);
复制代码 app\src\browser\application.ts
this.on('application:show-main-window', () => {
this.openWindowsForTokenState();
});- try {
- const mailsync = new MailsyncProcess(options);
- await mailsync.migrate();
- }
复制代码- this.on('application:add-account', ({ existingAccountJSON } = {}) => {
- const onboarding = this.windowManager.get(WindowManager.ONBOARDING_WINDOW);
- if (onboarding) {
- onboarding.show();
- onboarding.focus();
- } else {
- this.windowManager.ensureWindow(WindowManager.ONBOARDING_WINDOW, {
- windowProps: { addingAccount: true, existingAccountJSON },
- title: localized('Add Account'),
- });
- }
- });
复制代码- ipcMain.on('account-setup-successful', () => {
- this.windowManager.ensureWindow(WindowManager.MAIN_WINDOW);
- const onboarding = this.windowManager.get(WindowManager.ONBOARDING_WINDOW);
- if (onboarding) {
- onboarding.close();
- }
- });
复制代码 app\internal_packages\onboarding\lib\main.ts
import { SystemStartService, WorkspaceStore, ComponentRegistry } from 'mailspring-exports';
export function activate() {
ComponentRegistry.register(OnboardingRoot, {
location: WorkspaceStore.Location.Center,
});
}
app\internal_packages\onboarding\lib\onboarding-root.tsx
import AccountSettingsPageGmail from './page-account-settings-gmail';
import AccountSettingsPageIMAP from './page-account-settings-imap';
const PageComponents = {
welcome: WelcomePage,
tutorial: TutorialPage,
authenticate: AuthenticatePage,
'account-choose': AccountChoosePage,
'account-settings': AccountSettingsPage,
'account-settings-gmail': AccountSettingsPageGmail,
'account-settings-imap': AccountSettingsPageIMAP,
'account-onboarding-success': AccountOnboardingSuccess,
'initial-preferences': InitialPreferencesPage,
'initial-subscription': InitialSubscriptionPage,
};
render() {
const Component = PageComponents[this.state.page];
}
app\internal_packages\onboarding\lib\onboarding-store.ts
this._pageStack = ['account-choose', 'account-settings', 'account-settings-imap'];
app\internal_packages\onboarding\lib\page-account-settings-imap.tsx
-----------------------
app\internal_packages\onboarding\lib\page-account-settings.tsx
async submit() {
// expanding the account settings succeeded - try to authenticate
this.props.onConnect(account);
}
app\internal_packages\onboarding\lib\decorators\create-page-for-form.tsx
onConnect = (updatedAccount?: Account) => {
finalizeAndValidateAccount(account)
.then(validated => {
OnboardingActions.moveToPage('account-onboarding-success');
OnboardingActions.finishAndAddAccount(validated);
})
}
app\internal_packages\onboarding\lib\onboarding-helpers.ts
export async function finalizeAndValidateAccount(account: Account) {
// Test connections to IMAP and SMTP
const proc = new MailsyncProcess(AppEnv.getLoadSettings());
proc.identity = IdentityStore.identity();
proc.account = account;
await proc.test();
// Record the date of successful auth
account.authedAt = new Date();
return account;
}
app\src\mailsync-process.ts
export class MailsyncProcess extends EventEmitter
this.binaryPath = path.join(resourcePath, 'mailsync').replace('app.asar', 'app.asar.unpacked');
test() {
return this._spawnAndWait('test');
}
_spawnAndWait(mode, { onData }: { onData?: (data: any) => void } = {}) {
return new Promise<{ response: any; buffer: Buffer }>((resolve, reject) => {
this._spawnProcess(mode);
let buffer = Buffer.from([]);
...
}
_spawnProcess(mode) {
this._proc = spawn(this.binaryPath, args, { env });
}
|
|