Skip to content

Commit

Permalink
linux gets back "close to tray" and "start hidden" defaults = true
Browse files Browse the repository at this point in the history
* @electron recently got back the "GTK / Appindicator"-based tray icons, see #254 for details
* reverts 929122a and 01a9731
  • Loading branch information
vladimiry committed Jun 15, 2020
1 parent 5bcef09 commit eed1810
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 82 deletions.
3 changes: 1 addition & 2 deletions src/electron-main/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IPC_MAIN_API, IPC_MAIN_API_NOTIFICATION_ACTIONS, IpcMainApiEndpoints} fr
import {IPC_MAIN_API_NOTIFICATION$} from "src/electron-main/api/constants";
import {PACKAGE_NAME, PRODUCT_NAME} from "src/shared/constants";
import {attachFullTextIndexWindow, detachFullTextIndexWindow} from "src/electron-main/window/full-text-search";
import {buildSettingsAdapter, linuxLikePlatform} from "src/electron-main/util";
import {buildSettingsAdapter} from "src/electron-main/util";
import {clearIdleTimeLogOut, setupIdleTimeLogOut} from "src/electron-main/power-monitor";
import {curryFunctionMembers} from "src/shared/util";
import {deletePassword, getPassword, setPassword} from "src/electron-main/keytar";
Expand Down Expand Up @@ -53,7 +53,6 @@ export const initApi = async (ctx: Context): Promise<IpcMainApiEndpoints> => {
async staticInit() {
return {
electronLocations: ctx.locations,
linuxLikePlatform: linuxLikePlatform(),
};
},

Expand Down
7 changes: 0 additions & 7 deletions src/electron-main/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {randomBytes} from "crypto";
import {BaseConfig, Config, ENCRYPTION_DERIVATION_PRESETS, KEY_DERIVATION_PRESETS, Settings} from "src/shared/model/options";
import {PACKAGE_NAME} from "src/shared/constants";
import {initialConfig} from "src/shared/util";
import {linuxLikePlatform} from "src/electron-main/util";

export const PLATFORM = platform();

Expand All @@ -25,12 +24,6 @@ export const INITIAL_STORES: Readonly<{
return {
...config,
checkUpdateAndNotify: !SNAP_CONTAINER, // update check is disabled by default for the Snap package type
startHidden: linuxLikePlatform()
? false
: config.startHidden,
hideOnClose: linuxLikePlatform()
? false
: config.hideOnClose,
};
},
settings: () => {
Expand Down
70 changes: 7 additions & 63 deletions src/electron-main/storage-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import _logger from "electron-log";
import compareVersions from "compare-versions";
import path from "path";
import {delay, filter, take} from "rxjs/operators";
import {merge} from "rxjs";

import {AccountConfig} from "src/shared/model/account";
import {BaseConfig, Config, Settings} from "src/shared/model/options";
Expand All @@ -18,15 +16,13 @@ import {IPC_MAIN_API_NOTIFICATION$} from "src/electron-main/api/constants";
import {IPC_MAIN_API_NOTIFICATION_ACTIONS} from "src/shared/api/main";
import {
LAYOUT_MODES,
ONE_SECOND_MS,
PACKAGE_VERSION,
PROTON_API_ENTRY_PRIMARY_VALUE,
PROTON_API_ENTRY_URLS,
PROTON_API_ENTRY_VALUE_PREFIX,
ZOOM_FACTORS,
} from "src/shared/constants";
import {curryFunctionMembers, pickBaseConfigProperties} from "src/shared/util";
import {linuxLikePlatform} from "src/electron-main/util";

const logger = curryFunctionMembers(_logger, "[src/electron-main/storage-upgrade]");

Expand Down Expand Up @@ -238,77 +234,25 @@ const CONFIG_UPGRADES: Record<string, (config: Config) => void> = {
logger.info(loggerPrefix);

function trayIconRelatedUpdate(
{prevKey, key, keyTitle}:
| Readonly<{ prevKey: "startMinimized"; key: keyof Pick<BaseConfig, "startHidden">; keyTitle: string }>
| Readonly<{ prevKey: "closeToTray"; key: keyof Pick<BaseConfig, "hideOnClose">; keyTitle: string }>,
{prevKey, key}:
| Readonly<{ prevKey: "startMinimized"; key: keyof Pick<BaseConfig, "startHidden"> }>
| Readonly<{ prevKey: "closeToTray"; key: keyof Pick<BaseConfig, "hideOnClose"> }>,
): void {
if (typeof config[key] === "boolean") {
return;
}

type PrevConfig = { [k in typeof prevKey]?: boolean };
const {[prevKey]: prevValue} = config as PrevConfig;
delete (config as PrevConfig).startMinimized;
delete (config as PrevConfig)[prevKey];

config[key] = linuxLikePlatform() || typeof prevValue !== "boolean"
// set the default value if any conditions met:
// - Linux system
// - no saved before v4.2.3 value detected
config[key] = typeof prevValue !== "boolean"
? INITIAL_STORES.config()[key]
// otherwise just rename "startMinimized => startHidden"
: prevValue;

setTimeout((): void => {
const showValueResetNotification = (
linuxLikePlatform()
&&
// value existed and has been changed/reset
typeof prevValue === "boolean" && config[key] !== prevValue
);

logger.info(
loggerPrefix,
JSON.stringify({
linuxLikePlatform: linuxLikePlatform(),
prevKey,
key,
prevValue,
value: config[key],
showValueResetNotification
}),
);

if (!showValueResetNotification) {
return;
}

merge(
IPC_MAIN_API_NOTIFICATION$.pipe(filter(IPC_MAIN_API_NOTIFICATION_ACTIONS.is.Bootstrap)),
IPC_MAIN_API_NOTIFICATION$.pipe(filter(IPC_MAIN_API_NOTIFICATION_ACTIONS.is.ActivateBrowserWindow)),
).pipe(
take(1),
delay(ONE_SECOND_MS * 3),
).subscribe((notification) => {
logger.info(
loggerPrefix,
"Showing message",
JSON.stringify({notification}),
);

IPC_MAIN_API_NOTIFICATION$.next(
IPC_MAIN_API_NOTIFICATION_ACTIONS.InfoMessage({
message: [
`The "${keyTitle}" flag has been reset. `,
`See https://github.com/vladimiry/ElectronMail/issues/254 for details.`,
].join(""),
}),
);
});
});
}

trayIconRelatedUpdate({prevKey: "startMinimized", key: "startHidden", keyTitle: "Start minimized to tray"});
trayIconRelatedUpdate({prevKey: "closeToTray", key: "hideOnClose", keyTitle: "Close to tray"});
trayIconRelatedUpdate({prevKey: "startMinimized", key: "startHidden"});
trayIconRelatedUpdate({prevKey: "closeToTray", key: "hideOnClose"});

((): void => {
const key: keyof Pick<Config, "layoutMode"> = "layoutMode";
Expand Down
5 changes: 0 additions & 5 deletions src/electron-main/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import {EncryptionAdapter} from "fs-json-store-encryption-adapter";
import {Model as StoreModel} from "fs-json-store";

import {Context} from "./model";
import {PLATFORM} from "src/electron-main/constants";
import {curryFunctionMembers} from "src/shared/util";

const logger = curryFunctionMembers(_logger, "[src/electron-main/util]");

export function linuxLikePlatform(): boolean {
return PLATFORM !== "win32" && PLATFORM !== "darwin";
}

export function formatFileUrl(pathname: string): string {
return url.format({pathname, protocol: "file:", slashes: true});
}
Expand Down
1 change: 0 additions & 1 deletion src/shared/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export const ENDPOINTS_DEFINITION = {

staticInit: ActionType.Promise<void, DeepReadonly<{
electronLocations: ElectronContextLocations;
linuxLikePlatform: boolean;
}>>(),

init: ActionType.Promise<void, InitResponse>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
>
<label class="custom-control-label" for="hideOnCloseCheckbox">
Close to tray
<a *ngIf="linuxLikePlatform" href="https://github.com/vladimiry/ElectronMail/issues/254">#254</a>
</label>
</div>
<div class="custom-control custom-switch">
Expand All @@ -98,7 +97,6 @@
>
<label class="custom-control-label" for="startHiddenCheckbox">
Start minimized to tray
<a *ngIf="linuxLikePlatform" href="https://github.com/vladimiry/ElectronMail/issues/254">#254</a>
</label>
</div>
<div class="custom-control custom-switch">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {getZoneNameBoundWebLogger} from "src/web/browser-window/util";
preserveWhitespaces: true,
})
export class BaseSettingsComponent implements OnInit, OnDestroy {
readonly linuxLikePlatform = __METADATA__.linuxLikePlatform;

readonly processing$: Observable<boolean> = this.store.pipe(
select(OptionsSelectors.FEATURED.progress),
map((progress) => Boolean(progress.updatingBaseSettings)),
Expand Down

0 comments on commit eed1810

Please sign in to comment.