Skip to content

Commit f0c4017

Browse files
committed
Merge branch 'main' into refactor/settings-parent-groupings
Signed-off-by: Adam Setch <[email protected]>
2 parents cc4e711 + 5712df1 commit f0c4017

File tree

10 files changed

+241
-210
lines changed

10 files changed

+241
-210
lines changed

config/webpack.config.renderer.base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ const configuration: webpack.Configuration = {
4040
},
4141

4242
plugins: [
43-
// Development Keys - See README.md
43+
// Development Keys - See CONTRIBUTING.md
4444
new webpack.EnvironmentPlugin({
45-
OAUTH_CLIENT_ID: '3fef4433a29c6ad8f22c',
46-
OAUTH_CLIENT_SECRET: '9670de733096c15322183ff17ed0fc8704050379',
45+
OAUTH_CLIENT_ID: 'Ov23liQIkFs5ehQLNzHF',
46+
OAUTH_CLIENT_SECRET: '404b80632292e18419dbd2a6ed25976856e95255',
4747
}),
4848

4949
// Extract CSS into a separate file

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
"package.json"
8181
],
8282
"electronLanguages": ["en"],
83+
"protocols": [
84+
{
85+
"name": "Gitify",
86+
"schemes": ["gitify"]
87+
}
88+
],
8389
"mac": {
8490
"category": "public.app-category.developer-tools",
8591
"icon": "assets/images/app-icon.icns",

src/main/main.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const browserWindowOpts = {
1919
minHeight: 400,
2020
resizable: false,
2121
skipTaskbar: true, // Hide the app from the Windows taskbar
22+
// TODO ideally we would disable this as use a preload script with a context bridge
2223
webPreferences: {
23-
enableRemoteModule: true,
2424
nodeIntegration: true,
2525
contextIsolation: false,
2626
},
@@ -37,11 +37,14 @@ const mb = menubar({
3737
const menuBuilder = new MenuBuilder(mb);
3838
const contextMenu = menuBuilder.buildMenu();
3939

40-
/**
41-
* Electron Auto Updater only supports macOS and Windows
42-
* https://github.com/electron/update-electron-app
43-
*/
40+
// Register your app as the handler for a custom protocol
41+
app.setAsDefaultProtocolClient('gitify');
42+
4443
if (isMacOS() || isWindows()) {
44+
/**
45+
* Electron Auto Updater only supports macOS and Windows
46+
* https://github.com/electron/update-electron-app
47+
*/
4548
const updater = new Updater(mb, menuBuilder);
4649
updater.initialize();
4750
}
@@ -54,13 +57,6 @@ app.whenReady().then(async () => {
5457
mb.on('ready', () => {
5558
mb.app.setAppUserModelId(APPLICATION.ID);
5659

57-
/**
58-
* TODO: Remove @electron/remote use - see #650
59-
* GitHub OAuth 2 Login Flows - Enable Remote Browser Window Launch
60-
*/
61-
require('@electron/remote/main').initialize();
62-
require('@electron/remote/main').enable(mb.window.webContents);
63-
6460
// Tray configuration
6561
mb.tray.setToolTip(APPLICATION.NAME);
6662
mb.tray.setIgnoreDoubleClickEvents(true);
@@ -172,3 +168,9 @@ app.whenReady().then(async () => {
172168
app.setLoginItemSettings(settings);
173169
});
174170
});
171+
172+
// Handle gitify:// custom protocol URL events for OAuth 2.0 callback
173+
app.on('open-url', (event, url) => {
174+
event.preventDefault();
175+
mb.window.webContents.send(namespacedEvent('auth-callback'), url);
176+
});

src/renderer/components/settings/AppearanceSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ export const AppearanceSettings: FC = () => {
153153
<Checkbox
154154
name="showAccountHeader"
155155
label="Show account header"
156-
checked={settings.showAccountHeader || hasMultipleAccounts(auth)}
157-
disabled={hasMultipleAccounts(auth)}
156+
checked={settings.showAccountHeader}
157+
visible={!hasMultipleAccounts(auth)}
158158
onChange={(evt) =>
159159
updateSetting('showAccountHeader', evt.target.checked)
160160
}

src/renderer/routes/Accounts.tsx

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const AccountsRoute: FC = () => {
4949
useContext(AppContext);
5050
const navigate = useNavigate();
5151

52+
const [loadingStates, setLoadingStates] = useState<Record<string, boolean>>(
53+
{},
54+
);
55+
5256
const logoutAccount = useCallback(
5357
(account: Account) => {
5458
logoutFromAccount(account);
@@ -65,6 +69,29 @@ export const AccountsRoute: FC = () => {
6569
navigate('/accounts', { replace: true });
6670
}, []);
6771

72+
const handleRefresh = useCallback(async (account: Account) => {
73+
const accountUUID = getAccountUUID(account);
74+
75+
setLoadingStates((prev) => ({
76+
...prev,
77+
[accountUUID]: true,
78+
}));
79+
80+
await refreshAccount(account);
81+
navigate('/accounts', { replace: true });
82+
83+
/**
84+
* Typically the above refresh API call completes very quickly,
85+
* so we add an brief artificial delay to allow the icon to spin a few times
86+
*/
87+
setTimeout(() => {
88+
setLoadingStates((prev) => ({
89+
...prev,
90+
[accountUUID]: false,
91+
}));
92+
}, 500);
93+
}, []);
94+
6895
const loginWithGitHub = useCallback(async () => {
6996
try {
7097
await loginWithGitHubApp();
@@ -89,11 +116,11 @@ export const AccountsRoute: FC = () => {
89116
{auth.accounts.map((account, i) => {
90117
const AuthMethodIcon = getAuthMethodIcon(account.method);
91118
const PlatformIcon = getPlatformIcon(account.platform);
92-
const [isRefreshingAccount, setIsRefreshingAccount] = useState(false);
119+
const accountUUID = getAccountUUID(account);
93120

94121
return (
95122
<Box
96-
key={getAccountUUID(account)}
123+
key={accountUUID}
97124
className="rounded-md p-2 mb-4 bg-gitify-accounts"
98125
>
99126
<Stack
@@ -107,7 +134,6 @@ export const AccountsRoute: FC = () => {
107134
title="Open account profile"
108135
onClick={() => openAccountProfile(account)}
109136
data-testid="account-profile"
110-
className="pb-2"
111137
>
112138
<AvatarWithFallback
113139
src={account.user.avatar}
@@ -130,10 +156,10 @@ export const AccountsRoute: FC = () => {
130156
</Stack>
131157
</Box>
132158

133-
<button
159+
<Box
134160
title="Open host"
135-
type="button"
136161
onClick={() => openHost(account.hostname)}
162+
className="cursor-pointer"
137163
data-testid="account-host"
138164
>
139165
<Stack
@@ -144,12 +170,12 @@ export const AccountsRoute: FC = () => {
144170
<PlatformIcon />
145171
<Text>{account.hostname}</Text>
146172
</Stack>
147-
</button>
173+
</Box>
148174

149-
<button
175+
<Box
150176
title="Open developer settings"
151-
type="button"
152177
onClick={() => openDeveloperSettings(account)}
178+
className="cursor-pointer"
153179
data-testid="account-developer-settings"
154180
>
155181
<Stack
@@ -160,7 +186,7 @@ export const AccountsRoute: FC = () => {
160186
<AuthMethodIcon />
161187
<Text>{account.method}</Text>
162188
</Stack>
163-
</button>
189+
</Box>
164190
</Stack>
165191
</Box>
166192
</Stack>
@@ -192,22 +218,9 @@ export const AccountsRoute: FC = () => {
192218
<IconButton
193219
icon={SyncIcon}
194220
aria-label={`Refresh ${account.user.login}`}
195-
onClick={async () => {
196-
setIsRefreshingAccount(true);
197-
198-
await refreshAccount(account);
199-
navigate('/accounts', { replace: true });
200-
201-
/**
202-
* Typically the above refresh API call completes very quickly,
203-
* so we add an brief artificial delay to allow the icon to spin a few times
204-
*/
205-
setTimeout(() => {
206-
setIsRefreshingAccount(false);
207-
}, 500);
208-
}}
221+
onClick={() => handleRefresh(account)}
209222
size="small"
210-
loading={isRefreshingAccount}
223+
loading={loadingStates[accountUUID] || false}
211224
data-testid="account-refresh"
212225
/>
213226

0 commit comments

Comments
 (0)