Skip to content

Commit 47a934e

Browse files
committed
init Version 2 (react)
1 parent d62b079 commit 47a934e

35 files changed

+22434
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*/.js
2+
node_modules
3+
dist
4+
webpack/*.js
5+
.webpack
6+
out

.eslintrc.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": [
9+
"standard",
10+
"prettier"
11+
],
12+
"parser": "@typescript-eslint/parser",
13+
"parserOptions": {
14+
"ecmaFeatures": {
15+
"jsx": true
16+
},
17+
"ecmaVersion": 12,
18+
"sourceType": "module"
19+
},
20+
"plugins": [
21+
"react",
22+
"prettier",
23+
"@typescript-eslint"
24+
],
25+
"rules": {
26+
"react/prop-types": "off"
27+
}
28+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
packages
4+
.webpack
5+
out

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
![logo](http://www.freelogovectors.net/wp-content/uploads/2013/06/stackoverflow_logo.jpg)
2+
3+
# A full-featured StackOverflow desktop app
4+
5+
**IMPORTANT:** This app is under development. This is a hobby project so no deadlines, no commercial.
6+
7+
### Why?
8+
9+
- Faster and cleaner UI
10+
- Better code editor
11+
- Native notifications
12+
- and more...
13+
14+
### Screenshots (work in progress)
15+
![screen](./screenshot.png)
16+
17+
## Installing
18+
19+
### MacOS
20+
Download [StackOverflow.dmg]() (TBD)
21+
22+
### Windows
23+
TBD
24+
25+
### Linux
26+
TBD

assets/.gitkeep

Whitespace-only changes.

assets/stackoverflow-logo.png

19.5 KB
Loading

assets/user-placeholder.jpeg

132 KB
Loading

babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-env',
4+
'@babel/preset-typescript',
5+
['@babel/preset-react', {
6+
runtime: 'automatic'
7+
}]
8+
],
9+
plugins: [
10+
['@babel/plugin-transform-runtime', {
11+
regenerator: true
12+
}]
13+
]
14+
}

electron/bridge.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { contextBridge, ipcRenderer } from 'electron'
2+
3+
export const api = {
4+
/**
5+
* Here you can expose functions to the renderer process
6+
* so they can interact with the main (electron) side
7+
* without security problems.
8+
*
9+
* The function below can accessed using `window.Main.sayHello`
10+
*/
11+
12+
sendMessage: (message: any) => {
13+
ipcRenderer.send('message', message)
14+
},
15+
16+
auth: () => {
17+
ipcRenderer.send('message', 'auth')
18+
},
19+
20+
/**
21+
* Provide an easier way to listen to events
22+
*/
23+
on: (channel: string, callback: Function) => {
24+
ipcRenderer.on(channel, (_, data) => callback(data))
25+
}
26+
}
27+
28+
contextBridge.exposeInMainWorld('Main', api)

electron/main.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { app, BrowserWindow, ipcMain } from "electron";
2+
import { auth } from "../src/unitls/stackexchange-auth";
3+
4+
let mainWindow: BrowserWindow | null;
5+
6+
declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
7+
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
8+
9+
// const assetsPath =
10+
// process.env.NODE_ENV === 'production'
11+
// ? process.resourcesPath
12+
// : app.getAppPath()
13+
14+
function createWindow() {
15+
mainWindow = new BrowserWindow({
16+
// icon: path.join(assetsPath, 'assets', 'icon.png'),
17+
width: 1000,
18+
height: 600,
19+
title: 'StackOverflow',
20+
titleBarStyle: "hiddenInset",
21+
backgroundColor: "#191622",
22+
webPreferences: {
23+
nodeIntegration: false,
24+
contextIsolation: true,
25+
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
26+
},
27+
});
28+
29+
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
30+
31+
mainWindow.on("closed", () => {
32+
mainWindow = null;
33+
});
34+
35+
// TODO
36+
// mainWindow.setTitle('StackOverflow')
37+
//
38+
// mainWindow.on('page-title-updated', function(e) {
39+
// e.preventDefault()
40+
// });
41+
}
42+
43+
async function registerListeners() {
44+
/**
45+
* This comes from bridge integration, check bridge.ts
46+
*/
47+
ipcMain.on("message", (_, message) => {
48+
if (message === "auth") {
49+
auth((token, expires) => {
50+
console.log(token, expires);
51+
});
52+
}
53+
});
54+
}
55+
56+
app
57+
.on("ready", createWindow)
58+
.whenReady()
59+
.then(registerListeners)
60+
.catch((e) => console.error(e));
61+
62+
app
63+
.on("web-contents-created", (event, webContents) => {
64+
webContents.on('dom-ready', () => {
65+
auth((token, expires) => {
66+
webContents.send('stackexchange:on-auth', { token: token, expires: expires });
67+
});
68+
})
69+
})
70+
71+
app.on("window-all-closed", () => {
72+
if (process.platform !== "darwin") {
73+
app.quit();
74+
}
75+
});
76+
77+
app.on("activate", () => {
78+
if (BrowserWindow.getAllWindows().length === 0) {
79+
createWindow();
80+
}
81+
});

jest.config.js

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after `n` failures
9+
// bail: 0,
10+
11+
// The directory where Jest should store its cached dependency information
12+
// cacheDirectory: "/tmp/jest_rs",
13+
14+
// Automatically clear mock calls and instances between every test
15+
clearMocks: true,
16+
17+
// Indicates whether the coverage information should be collected while executing the test
18+
// collectCoverage: false,
19+
20+
// An array of glob patterns indicating a set of files for which coverage information should be collected
21+
// collectCoverageFrom: undefined,
22+
23+
// The directory where Jest should output its coverage files
24+
// coverageDirectory: undefined,
25+
26+
// An array of regexp pattern strings used to skip coverage collection
27+
// coveragePathIgnorePatterns: [
28+
// "/node_modules/"
29+
// ],
30+
31+
// Indicates which provider should be used to instrument code for coverage
32+
// coverageProvider: "babel",
33+
34+
// A list of reporter names that Jest uses when writing coverage reports
35+
// coverageReporters: [
36+
// "json",
37+
// "text",
38+
// "lcov",
39+
// "clover"
40+
// ],
41+
42+
// An object that configures minimum threshold enforcement for coverage results
43+
// coverageThreshold: undefined,
44+
45+
// A path to a custom dependency extractor
46+
// dependencyExtractor: undefined,
47+
48+
// Make calling deprecated APIs throw helpful error messages
49+
// errorOnDeprecated: false,
50+
51+
// Force coverage collection from ignored files using an array of glob patterns
52+
// forceCoverageMatch: [],
53+
54+
// A path to a module which exports an async function that is triggered once before all test suites
55+
// globalSetup: undefined,
56+
57+
// A path to a module which exports an async function that is triggered once after all test suites
58+
// globalTeardown: undefined,
59+
60+
// A set of global variables that need to be available in all test environments
61+
// globals: {},
62+
63+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
64+
// maxWorkers: "50%",
65+
66+
// An array of directory names to be searched recursively up from the requiring module's location
67+
// moduleDirectories: [
68+
// "node_modules"
69+
// ],
70+
71+
// An array of file extensions your modules use
72+
// moduleFileExtensions: [
73+
// "js",
74+
// "json",
75+
// "jsx",
76+
// "ts",
77+
// "tsx",
78+
// "node"
79+
// ],
80+
81+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
82+
// moduleNameMapper: {},
83+
84+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
85+
// modulePathIgnorePatterns: [],
86+
87+
// Activates notifications for test results
88+
// notify: false,
89+
90+
// An enum that specifies notification mode. Requires { notify: true }
91+
// notifyMode: "failure-change",
92+
93+
// A preset that is used as a base for Jest's configuration
94+
preset: 'ts-jest',
95+
96+
// Run tests from one or more projects
97+
// projects: undefined,
98+
99+
// Use this configuration option to add custom reporters to Jest
100+
// reporters: undefined,
101+
102+
// Automatically reset mock state between every test
103+
// resetMocks: false,
104+
105+
// Reset the module registry before running each individual test
106+
// resetModules: false,
107+
108+
// A path to a custom resolver
109+
// resolver: undefined,
110+
111+
// Automatically restore mock state between every test
112+
// restoreMocks: false,
113+
114+
// The root directory that Jest should scan for tests and modules within
115+
// rootDir: undefined,
116+
117+
// A list of paths to directories that Jest should use to search for files in
118+
// roots: [
119+
// "<rootDir>"
120+
// ],
121+
122+
// Allows you to use a custom runner instead of Jest's default test runner
123+
// runner: "jest-runner",
124+
125+
// The paths to modules that run some code to configure or set up the testing environment before each test
126+
// setupFiles: [],
127+
128+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
129+
setupFilesAfterEnv: ['./tests/setupTests.ts'],
130+
131+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
132+
// snapshotSerializers: [],
133+
134+
// The test environment that will be used for testing
135+
testEnvironment: 'jsdom'
136+
137+
// Options that will be passed to the testEnvironment
138+
// testEnvironmentOptions: {},
139+
140+
// Adds a location field to test results
141+
// testLocationInResults: false,
142+
143+
// The glob patterns Jest uses to detect test files
144+
// testMatch: [
145+
// "**/__tests__/**/*.[jt]s?(x)",
146+
// "**/?(*.)+(spec|test).[tj]s?(x)"
147+
// ],
148+
149+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
150+
// testPathIgnorePatterns: [
151+
// "/node_modules/"
152+
// ],
153+
154+
// The regexp pattern or array of patterns that Jest uses to detect test files
155+
// testRegex: [],
156+
157+
// This option allows the use of a custom results processor
158+
// testResultsProcessor: undefined,
159+
160+
// This option allows use of a custom test runner
161+
// testRunner: "jasmine2",
162+
163+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
164+
// testURL: "http://localhost",
165+
166+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
167+
// timers: "real",
168+
169+
// A map from regular expressions to paths to transformers
170+
// transform: undefined,
171+
172+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
173+
// transformIgnorePatterns: [
174+
// "/node_modules/"
175+
// ],
176+
177+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
178+
// unmockedModulePathPatterns: undefined,
179+
180+
// Indicates whether each individual test should be reported during the run
181+
// verbose: undefined,
182+
183+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
184+
// watchPathIgnorePatterns: [],
185+
186+
// Whether to use watchman for file crawling
187+
// watchman: true,
188+
}

0 commit comments

Comments
 (0)